diff options
author | Henigan <rheniga1@MGC12Z921DLVCG.fbpld77.ford.com> | 2021-04-21 13:36:20 -0400 |
---|---|---|
committer | Henigan <rheniga1@MGC12Z921DLVCG.fbpld77.ford.com> | 2021-04-21 13:36:20 -0400 |
commit | fc8896d3851915140d58ae6e3db1738f35288d60 (patch) | |
tree | 81ac3d7bc582f72de3166f4a19b05e3aa0f7c678 | |
parent | e1f9c020b19a656b20103b3accb7ef04dc53a5b4 (diff) | |
download | sdl_android-bugfix/issue_1664.tar.gz |
add removceDuplicate helper method to VoiceCommandbugfix/issue_1664
2 files changed, 31 insertions, 1 deletions
diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/VoiceCommandTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/VoiceCommandTests.java index 0a7673c0c..6acdbeae0 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/VoiceCommandTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/VoiceCommandTests.java @@ -39,6 +39,9 @@ import com.smartdevicelink.test.TestValues; import org.junit.Test; import org.junit.runner.RunWith; +import java.util.ArrayList; +import java.util.List; + import static junit.framework.TestCase.assertEquals; @RunWith(AndroidJUnit4.class) @@ -59,4 +62,25 @@ public class VoiceCommandTests { assertEquals(voiceCommand.getVoiceCommandSelectionListener(), voiceCommandSelectionListener); } + @Test + public void testDuplicateStrings() { + List<String> voiceCommandsList = new ArrayList<>(); + voiceCommandsList.add("Test1"); + voiceCommandsList.add("Test1"); + voiceCommandsList.add("Test1"); + VoiceCommand voiceCommand = new VoiceCommand(voiceCommandsList, voiceCommandSelectionListener); + + assertEquals(1, voiceCommand.getVoiceCommands().size()); + assertEquals("Test1", voiceCommand.getVoiceCommands().get(0)); + + voiceCommandsList = new ArrayList<>(); + voiceCommandsList.add("Test1"); + voiceCommandsList.add("Test2"); + voiceCommandsList.add("Test1"); + VoiceCommand voiceCommand2 = new VoiceCommand(voiceCommandsList, voiceCommandSelectionListener); + + assertEquals(2, voiceCommand2.getVoiceCommands().size()); + assertEquals("Test1", voiceCommand2.getVoiceCommands().get(0)); + assertEquals("Test2", voiceCommand2.getVoiceCommands().get(1)); + } } diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/VoiceCommand.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/VoiceCommand.java index 15d66b09e..798bf93ef 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/VoiceCommand.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/VoiceCommand.java @@ -36,6 +36,8 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import java.util.ArrayList; +import java.util.HashSet; import java.util.List; public class VoiceCommand { @@ -77,7 +79,7 @@ public class VoiceCommand { * @param voiceCommands - the list of commands to send to the head unit */ public void setVoiceCommands(@NonNull List<String> voiceCommands) { - this.voiceCommands = voiceCommands; + this.voiceCommands = new ArrayList<>(removeDuplicateStrings(voiceCommands)); } /** @@ -126,6 +128,10 @@ public class VoiceCommand { return commandId; } + private HashSet<String> removeDuplicateStrings(List<String> voiceCommands) { + return new HashSet<>(voiceCommands); + } + /** * Used to compile hashcode for VoiceCommand for use to compare in equals method * |