|
51 | 51 |
|
52 | 52 | import java.util.ArrayList; |
53 | 53 | import java.util.HashMap; |
| 54 | +import java.util.HashSet; |
54 | 55 | import java.util.List; |
55 | 56 |
|
56 | 57 | abstract class BaseVoiceCommandManager extends BaseSubManager { |
@@ -136,6 +137,11 @@ public void setVoiceCommands(List<VoiceCommand> voiceCommands) { |
136 | 137 | return; |
137 | 138 | } |
138 | 139 |
|
| 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 | + |
139 | 145 | updateIdsOnVoiceCommands(voiceCommands); |
140 | 146 | this.voiceCommands = new ArrayList<>(voiceCommands); |
141 | 147 |
|
@@ -225,4 +231,21 @@ public void onNotified(RPCNotification notification) { |
225 | 231 | }; |
226 | 232 | internalInterface.addOnRPCNotificationListener(FunctionID.ON_COMMAND, commandListener); |
227 | 233 | } |
| 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 | + } |
228 | 251 | } |
0 commit comments