File tree Expand file tree Collapse file tree
base/src/main/java/com/smartdevicelink/managers/screen/menu Expand file tree Collapse file tree Original file line number Diff line number Diff line change 5151
5252import java .util .ArrayList ;
5353import java .util .HashMap ;
54+ import java .util .HashSet ;
5455import java .util .List ;
5556
5657abstract 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}
You can’t perform that action at this time.
0 commit comments