From 4f24eb635eb5b24f0ca960e8531cfa7989ad4193 Mon Sep 17 00:00:00 2001 From: parthiv39731 <70740707+parthiv39731@users.noreply.github.com> Date: Sun, 23 Jul 2023 23:20:50 +0530 Subject: [PATCH] BAEL-6710 (#14454) Changed method names --- .../uniquecharcheck/UniqueCharChecker.java | 10 ++-- .../UniqueCharCheckerUnitTest.java | 50 +++++++++---------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/core-java-modules/core-java-string-operations-6/src/main/java/com/baeldung/uniquecharcheck/UniqueCharChecker.java b/core-java-modules/core-java-string-operations-6/src/main/java/com/baeldung/uniquecharcheck/UniqueCharChecker.java index 365307708c..fefacb92d0 100644 --- a/core-java-modules/core-java-string-operations-6/src/main/java/com/baeldung/uniquecharcheck/UniqueCharChecker.java +++ b/core-java-modules/core-java-string-operations-6/src/main/java/com/baeldung/uniquecharcheck/UniqueCharChecker.java @@ -7,7 +7,7 @@ import java.util.stream.Collectors; public class UniqueCharChecker { - public static boolean checkV1(String str) { + public static boolean bruteForceCheck(String str) { char[] chars = str.toUpperCase().toCharArray(); for (int i = 0; i < chars.length; i++) { for (int j = i + 1; j < chars.length; j++) { @@ -19,7 +19,7 @@ public class UniqueCharChecker { return true; } - public static boolean checkV2(String str) { + public static boolean sortAndThenCheck(String str) { char[] chars = str.toUpperCase().toCharArray(); Arrays.sort(chars); for (int i = 0; i < chars.length - 1; i++) { @@ -30,7 +30,7 @@ public class UniqueCharChecker { return true; } - public static boolean checkV3(String str) { + public static boolean useSetCheck(String str) { char[] chars = str.toUpperCase().toCharArray(); Set set = new HashSet <>(); for (char c: chars) { @@ -39,7 +39,7 @@ public class UniqueCharChecker { return set.size() == str.length(); } - public static boolean checkV4(String str) { + public static boolean useStreamCheck(String str) { boolean isUnique = str.toUpperCase().chars() .mapToObj(c -> (char)c) .collect(Collectors.toSet()) @@ -47,7 +47,7 @@ public class UniqueCharChecker { return isUnique; } - public static boolean checkV5(String str) { + public static boolean useStringUtilscheck(String str) { for (int i = 0; i < str.length(); i++) { String curChar = String.valueOf(str.charAt(i)); String remainingStr = str.substring(i+1); diff --git a/core-java-modules/core-java-string-operations-6/src/test/java/com/baeldung/uniquecharcheck/UniqueCharCheckerUnitTest.java b/core-java-modules/core-java-string-operations-6/src/test/java/com/baeldung/uniquecharcheck/UniqueCharCheckerUnitTest.java index 938787662f..98473c6630 100644 --- a/core-java-modules/core-java-string-operations-6/src/test/java/com/baeldung/uniquecharcheck/UniqueCharCheckerUnitTest.java +++ b/core-java-modules/core-java-string-operations-6/src/test/java/com/baeldung/uniquecharcheck/UniqueCharCheckerUnitTest.java @@ -11,82 +11,82 @@ import static org.junit.Assert.assertTrue; public class UniqueCharCheckerUnitTest { @Test - public void givenMethCheck1_whenUnique_returnTrue() { + public void givenUnique_whenBruteForceCheck_thenReturnTrue() { String[] sampleStrings = new String[]{"Justfewdi123", "$%&Hibusc", "Hibusc%$#", "მშვნიერ"}; final String MSG = "Duplicate found"; Arrays.stream(sampleStrings) - .forEach(sampleStr -> assertTrue(MSG + " in " + sampleStr, UniqueCharChecker.checkV1(sampleStr))); + .forEach(sampleStr -> assertTrue(MSG + " in " + sampleStr, UniqueCharChecker.bruteForceCheck(sampleStr))); } @Test - public void givenMethCheck2_whenUnique_returnTrue() { + public void givenUnique_whenSortAndThenCheck_thenReturnTrue() { String[] sampleStrings = new String[]{"Justfewdi123", "$%&Hibusc", "Hibusc%$#", "მშვნიერ"}; final String MSG = "Duplicate found"; Arrays.stream(sampleStrings) - .forEach(sampleStr -> assertTrue(MSG + " in " + sampleStr, UniqueCharChecker.checkV2(sampleStr))); + .forEach(sampleStr -> assertTrue(MSG + " in " + sampleStr, UniqueCharChecker.sortAndThenCheck(sampleStr))); } @Test - public void givenMethCheck3_whenUnique_returnTrue() { + public void givenUnique_whenUseSetCheck_thenReturnTrue() { String[] sampleStrings = new String[]{"Justfewdi123", "$%&Hibusc", "Hibusc%$#", "მშვნიერ"}; final String MSG = "Duplicate found"; Arrays.stream(sampleStrings) - .forEach(sampleStr -> assertTrue(MSG + " in " + sampleStr, UniqueCharChecker.checkV3(sampleStr))); + .forEach(sampleStr -> assertTrue(MSG + " in " + sampleStr, UniqueCharChecker.useSetCheck(sampleStr))); } @Test - public void givenMethCheck4_whenUnique_returnTrue() { + public void givenUnique_whenUseStreamCheck_thenReturnTrue() { String[] sampleStrings = new String[]{"Justfewdi123", "$%&Hibusc", "Hibusc%$#", "მშვნიერ"}; final String MSG = "Duplicate found"; Arrays.stream(sampleStrings) - .forEach(sampleStr -> assertTrue(MSG + " in " + sampleStr, UniqueCharChecker.checkV1(sampleStr))); + .forEach(sampleStr -> assertTrue(MSG + " in " + sampleStr, UniqueCharChecker.useStreamCheck(sampleStr))); } @Test - public void givenMethCheck5_whenUnique_returnTrue() { + public void givenUnique_whenUseStringUtilscheck_thenReturnTrue() { String[] sampleStrings = new String[]{"Justfewdi123", "$%&Hibusc", "Hibusc%$#", "მშვნიერ"}; final String MSG = "Duplicate found"; Arrays.stream(sampleStrings) - .forEach(sampleStr -> assertTrue(MSG + " in " + sampleStr, UniqueCharChecker.checkV5(sampleStr))); + .forEach(sampleStr -> assertTrue(MSG + " in " + sampleStr, UniqueCharChecker.useStringUtilscheck(sampleStr))); } @Test - public void givenMethCheck1_whenNotUnique_returnFalse() { + public void givenNotUnique_whenBruteForceCheck_thenReturnFalse() { String[] sampleStrings = new String[]{"Justfewdif123", "$%&Hibushc", "Hibusuc%$#", "Hi%busc%$#", "მშვენიერი"}; final String MSG = "Duplicate not found"; Arrays.stream(sampleStrings) - .forEach(sampleStr -> assertFalse(MSG + " in " + sampleStr, UniqueCharChecker.checkV1(sampleStr))); + .forEach(sampleStr -> assertFalse(MSG + " in " + sampleStr, UniqueCharChecker.bruteForceCheck(sampleStr))); } @Test - public void givenMethCheck2_whenNotUnique_returnFalse() { + public void givenNotUnique_whenSortAndThenCheck_thenReturnFalse() { String[] sampleStrings = new String[]{"Justfewdif123", "$%&Hibushc", "Hibusuc%$#", "Hi%busc%$#", "მშვენიერი"}; final String MSG = "Duplicate not found"; Arrays.stream(sampleStrings) - .forEach(sampleStr -> assertFalse(MSG + " in " + sampleStr, UniqueCharChecker.checkV2(sampleStr))); + .forEach(sampleStr -> assertFalse(MSG + " in " + sampleStr, UniqueCharChecker.sortAndThenCheck(sampleStr))); } @Test - public void givenMethCheck3_whenNotUnique_returnFalse() { + public void givenNotUnique_whenUseSetCheck_thenReturnFalse() { String[] sampleStrings = new String[]{"Justfewdif123", "$%&Hibushc", "Hibusuc%$#", "Hi%busc%$#", "მშვენიერი"}; final String MSG = "Duplicate not found"; Arrays.stream(sampleStrings) - .forEach(sampleStr -> assertFalse(MSG + " in " + sampleStr, UniqueCharChecker.checkV3(sampleStr))); + .forEach(sampleStr -> assertFalse(MSG + " in " + sampleStr, UniqueCharChecker.useSetCheck(sampleStr))); } @Test - public void givenMethCheck4_whenNotUnique_returnFalse() { + public void givenNotUnique_whenUseStreamCheck_thenReturnFalse() { String[] sampleStrings = new String[]{"Justfewdif123", "$%&Hibushc", "Hibusuc%$#", "Hi%busc%$#", "მშვენიერი"}; final String MSG = "Duplicate not found"; Arrays.stream(sampleStrings) - .forEach(sampleStr -> assertFalse(MSG + " in " + sampleStr, UniqueCharChecker.checkV4(sampleStr))); + .forEach(sampleStr -> assertFalse(MSG + " in " + sampleStr, UniqueCharChecker.useStreamCheck(sampleStr))); } -@Test -public void givenMethCheck5_whenNotUnique_returnFalse() { - String[] sampleStrings = new String[]{"Justfewdif123", "$%&Hibushc", "Hibusuc%$#", "Hi%busc%$#", "მშვენიერი"}; - final String MSG = "Duplicate not found"; - Arrays.stream(sampleStrings) - .forEach(sampleStr -> assertFalse(MSG + " in " + sampleStr, UniqueCharChecker.checkV5(sampleStr))); -} + @Test + public void givenNotUnique_whenUseStringUtilscheck_thenReturnFalse() { + String[] sampleStrings = new String[]{"Justfewdif123", "$%&Hibushc", "Hibusuc%$#", "Hi%busc%$#", "მშვენიერი"}; + final String MSG = "Duplicate not found"; + Arrays.stream(sampleStrings) + .forEach(sampleStr -> assertFalse(MSG + " in " + sampleStr, UniqueCharChecker.useStringUtilscheck(sampleStr))); + } }