Skip to content

Commit a7eba52

Browse files
author
Julian Kast
committed
Add method to BaseVoiceCommandManager to check for uniqueness
1 parent 2b18229 commit a7eba52

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151

5252
import java.util.ArrayList;
5353
import java.util.HashMap;
54+
import java.util.HashSet;
5455
import java.util.List;
5556

5657
abstract class BaseVoiceCommandManager extends BaseSubManager {
@@ -136,6 +137,11 @@ public void setVoiceCommands(List<VoiceCommand> voiceCommands) {
136137
return;
137138
}
138139

140+
if (!isVoiceCommandsUnique(voiceCommands)) {
141+
DebugTool.logError(TAG, "Not all voice command strings are unique across all voice commands. Voice commands will not be set.");
142+
return;
143+
}
144+
139145
updateIdsOnVoiceCommands(voiceCommands);
140146
this.voiceCommands = new ArrayList<>(voiceCommands);
141147

@@ -225,4 +231,21 @@ public void onNotified(RPCNotification notification) {
225231
};
226232
internalInterface.addOnRPCNotificationListener(FunctionID.ON_COMMAND, commandListener);
227233
}
234+
235+
/**
236+
* Boolean method that checks to see if all VoiceCommands in a given list are unique
237+
*
238+
* @param voiceCommands - list of VoiceCommands
239+
* @return - true if VoiceCommands are unique, false if not
240+
*/
241+
private boolean isVoiceCommandsUnique(List<VoiceCommand> voiceCommands) {
242+
HashSet<String> voiceCommandHashSet = new HashSet<>();
243+
int voiceCommandCount = 0;
244+
245+
for (VoiceCommand voiceCommand : voiceCommands) {
246+
voiceCommandHashSet.addAll(voiceCommand.getVoiceCommands());
247+
voiceCommandCount += voiceCommand.getVoiceCommands().size();
248+
}
249+
return (voiceCommandHashSet.size() == voiceCommandCount);
250+
}
228251
}

0 commit comments

Comments
 (0)