From a6ec9122ea48e574729013150ba15ddafe092818 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Thu, 14 Sep 2023 10:01:58 +0300 Subject: [PATCH] BAEL-6811 move string article to make space for a new one using the same library; delete extra file --- .../core-java-string-algorithms-3/README.md | 1 + .../repetition/SubstringRepetition.java | 0 .../SubstringRepetitionUnitTest.java | 0 .../core-java-string-algorithms/README.md | 1 - .../MultiValueHashMapTest.java | 79 ------------------- 5 files changed, 1 insertion(+), 80 deletions(-) rename core-java-modules/{core-java-string-algorithms => core-java-string-algorithms-3}/src/main/java/com/baeldung/repetition/SubstringRepetition.java (100%) rename core-java-modules/{core-java-string-algorithms => core-java-string-algorithms-3}/src/test/java/com/baeldung/repetition/SubstringRepetitionUnitTest.java (100%) delete mode 100644 core-java-modules/core-java-string-conversions-3/src/java.com.baeldung.multivluehashmap/MultiValueHashMapTest.java diff --git a/core-java-modules/core-java-string-algorithms-3/README.md b/core-java-modules/core-java-string-algorithms-3/README.md index 6af818b52d..2bb70f5c97 100644 --- a/core-java-modules/core-java-string-algorithms-3/README.md +++ b/core-java-modules/core-java-string-algorithms-3/README.md @@ -11,3 +11,4 @@ This module contains articles about string-related algorithms. - [Find the First Non Repeating Character in a String in Java](https://www.baeldung.com/java-find-the-first-non-repeating-character) - [Find the First Embedded Occurrence of an Integer in a Java String](https://www.baeldung.com/java-string-find-embedded-integer) - [Find the Most Frequent Characters in a String](https://www.baeldung.com/java-string-find-most-frequent-characters) +- [Checking If a String Is a Repeated Substring](https://www.baeldung.com/java-repeated-substring) \ No newline at end of file diff --git a/core-java-modules/core-java-string-algorithms/src/main/java/com/baeldung/repetition/SubstringRepetition.java b/core-java-modules/core-java-string-algorithms-3/src/main/java/com/baeldung/repetition/SubstringRepetition.java similarity index 100% rename from core-java-modules/core-java-string-algorithms/src/main/java/com/baeldung/repetition/SubstringRepetition.java rename to core-java-modules/core-java-string-algorithms-3/src/main/java/com/baeldung/repetition/SubstringRepetition.java diff --git a/core-java-modules/core-java-string-algorithms/src/test/java/com/baeldung/repetition/SubstringRepetitionUnitTest.java b/core-java-modules/core-java-string-algorithms-3/src/test/java/com/baeldung/repetition/SubstringRepetitionUnitTest.java similarity index 100% rename from core-java-modules/core-java-string-algorithms/src/test/java/com/baeldung/repetition/SubstringRepetitionUnitTest.java rename to core-java-modules/core-java-string-algorithms-3/src/test/java/com/baeldung/repetition/SubstringRepetitionUnitTest.java diff --git a/core-java-modules/core-java-string-algorithms/README.md b/core-java-modules/core-java-string-algorithms/README.md index 5a7abf074a..e2f909ed38 100644 --- a/core-java-modules/core-java-string-algorithms/README.md +++ b/core-java-modules/core-java-string-algorithms/README.md @@ -11,6 +11,5 @@ This module contains articles about string-related algorithms. - [How to Reverse a String in Java](https://www.baeldung.com/java-reverse-string) - [Check if a String Is a Pangram in Java](https://www.baeldung.com/java-string-pangram) - [Check If a String Contains Multiple Keywords in Java](https://www.baeldung.com/string-contains-multiple-words) -- [Checking If a String Is a Repeated Substring](https://www.baeldung.com/java-repeated-substring) - [Remove Emojis from a Java String](https://www.baeldung.com/java-string-remove-emojis) - More articles: [[next -->]](../core-java-string-algorithms-2) diff --git a/core-java-modules/core-java-string-conversions-3/src/java.com.baeldung.multivluehashmap/MultiValueHashMapTest.java b/core-java-modules/core-java-string-conversions-3/src/java.com.baeldung.multivluehashmap/MultiValueHashMapTest.java deleted file mode 100644 index a3d0bc35de..0000000000 --- a/core-java-modules/core-java-string-conversions-3/src/java.com.baeldung.multivluehashmap/MultiValueHashMapTest.java +++ /dev/null @@ -1,79 +0,0 @@ -import org.junit.jupiter.api.Test; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - -import static org.junit.jupiter.api.Assertions.*; - -public class MultiValueHashMapTest { - @Test - public void given_MultiValueHashMap_whenPuttingAndGettingSingleValue_thenValueIsRetrieved() { - MultiValueHashMap map = new MultiValueHashMap<>(); - map.put("key1", 10); - assertEquals(List.of(10), map.get("key1")); - } - - @Test - public void given_MultiValueHashMap_whenPuttingAndGettingMultipleValues_thenAllValuesAreRetrieved() { - MultiValueHashMap map = new MultiValueHashMap<>(); - map.put("key2", "value1"); - map.put("key2", "value2"); - map.put("key2", "value3"); - - assertEquals(List.of("value1", "value2", "value3"), map.get("key2")); - } - - @Test - public void given_MultiValueHashMap_whenGettingNonExistentKey_thenEmptyListIsReturned() { - MultiValueHashMap map = new MultiValueHashMap<>(); - assertTrue(map.get("nonexistent").isEmpty()); - } - - @Test - public void given_MultiValueHashMap_whenRemovingValue_thenValueIsSuccessfullyRemoved() { - MultiValueHashMap map = new MultiValueHashMap<>(); - map.put(1, "one"); - map.put(1, "uno"); - map.put(1, "eins"); - - map.remove(1, "uno"); - assertEquals(List.of("one", "eins"), map.get(1)); - } - - @Test - public void testRemoveNonExistentValue() { - MultiValueHashMap map = new MultiValueHashMap<>(); - map.put(1, "one"); - map.remove(1, "nonexistent"); - assertEquals(List.of("one"), map.get(1)); - } - - public class MultiValueHashMap { - private HashMap> map; - - // Constructor - public MultiValueHashMap() { - map = new HashMap<>(); - } - - public void put(K key, V value) { - if (!map.containsKey(key)) { - map.put(key, new ArrayList<>()); - } - map.get(key).add(value); - } - - public List get(K key) { - return map.getOrDefault(key, new ArrayList<>()); - } - - public void remove(K key, V value) { - if (map.containsKey(key)) { - map.get(key).remove(value); - } - } - - - } -}