diff --git a/maps/src/main/java/com/georgev22/library/maps/ConcurrentObjectMap.java b/maps/src/main/java/com/georgev22/library/maps/ConcurrentObjectMap.java index 2040818..c28d29c 100644 --- a/maps/src/main/java/com/georgev22/library/maps/ConcurrentObjectMap.java +++ b/maps/src/main/java/com/georgev22/library/maps/ConcurrentObjectMap.java @@ -186,6 +186,95 @@ public ObjectMap appendIfTrue(ObjectMap mapIfTrue, Map mapIfFa return this; } + /** + * Removes the entry with the specified key from the ObjectMap. + * + * @param key the key of the entry to be removed + * @return the modified ObjectMap with the specified entry removed, or the original ObjectMap if the key was not found + */ + @Override + public ObjectMap removeEntry(K key) { + remove(key); + return this; + } + + /** + * Removes all entries with keys present in the specified map from the ObjectMap. + * + * @param map the map containing the keys to be removed + * @return the modified ObjectMap with the entries corresponding to the specified keys removed + */ + @Override + public ObjectMap removeEntries(Map map) { + for (Map.Entry entry : map.entrySet()) { + remove(entry.getKey()); + } + return this; + } + + /** + * Removes all entries with keys present in the specified ObjectMap from the ObjectMap. + * + * @param map the ObjectMap containing the keys to be removed + * @return the modified ObjectMap with the entries corresponding to the keys in the specified ObjectMap removed + */ + @Override + public ObjectMap removeEntries(ObjectMap map) { + for (ObjectMap.Entry entry : map.entrySet()) { + remove(entry.getKey()); + } + return this; + } + + /** + * Removes the entry with the specified key from the ObjectMap if the condition is true. + * + * @param key the key of the entry to be removed + * @param ifTrue the condition to check before removing the entry + * @return the modified ObjectMap with the specified entry removed if the condition is true, or the original ObjectMap otherwise + */ + @Override + public ObjectMap removeEntryIfTrue(K key, boolean ifTrue) { + if (ifTrue) { + remove(key); + } + return this; + } + + /** + * Removes all entries with keys present in the specified map from the ObjectMap if the condition is true. + * + * @param map the map containing the keys to be removed + * @param ifTrue the condition to check before removing the entries + * @return the modified ObjectMap with the entries corresponding to the keys in the specified map removed if the condition is true, or the original ObjectMap otherwise + */ + @Override + public ObjectMap removeEntriesIfTrue(Map map, boolean ifTrue) { + if (ifTrue) { + for (Map.Entry entry : map.entrySet()) { + remove(entry.getKey()); + } + } + return this; + } + + /** + * Removes all entries with keys present in the specified ObjectMap from the ObjectMap if the condition is true. + * + * @param map the ObjectMap containing the keys to be removed + * @param ifTrue the condition to check before removing the entries + * @return the modified ObjectMap with the entries corresponding to the keys in the specified ObjectMap removed if the condition is true, or the original ObjectMap otherwise + */ + @Override + public ObjectMap removeEntriesIfTrue(ObjectMap map, boolean ifTrue) { + if (ifTrue) { + for (ObjectMap.Entry entry : map.entrySet()) { + remove(entry.getKey()); + } + } + return this; + } + /** * Gets the value of the given key as an Integer. * diff --git a/maps/src/main/java/com/georgev22/library/maps/HashObjectMap.java b/maps/src/main/java/com/georgev22/library/maps/HashObjectMap.java index 1d263ec..e03db56 100644 --- a/maps/src/main/java/com/georgev22/library/maps/HashObjectMap.java +++ b/maps/src/main/java/com/georgev22/library/maps/HashObjectMap.java @@ -187,6 +187,95 @@ public ObjectMap appendIfTrue(ObjectMap mapIfTrue, Map mapIfFa return this; } + /** + * Removes the entry with the specified key from the ObjectMap. + * + * @param key the key of the entry to be removed + * @return the modified ObjectMap with the specified entry removed, or the original ObjectMap if the key was not found + */ + @Override + public ObjectMap removeEntry(K key) { + remove(key); + return this; + } + + /** + * Removes all entries with keys present in the specified map from the ObjectMap. + * + * @param map the map containing the keys to be removed + * @return the modified ObjectMap with the entries corresponding to the specified keys removed + */ + @Override + public ObjectMap removeEntries(Map map) { + for (Map.Entry entry : map.entrySet()) { + remove(entry.getKey()); + } + return this; + } + + /** + * Removes all entries with keys present in the specified ObjectMap from the ObjectMap. + * + * @param map the ObjectMap containing the keys to be removed + * @return the modified ObjectMap with the entries corresponding to the keys in the specified ObjectMap removed + */ + @Override + public ObjectMap removeEntries(ObjectMap map) { + for (ObjectMap.Entry entry : map.entrySet()) { + remove(entry.getKey()); + } + return this; + } + + /** + * Removes the entry with the specified key from the ObjectMap if the condition is true. + * + * @param key the key of the entry to be removed + * @param ifTrue the condition to check before removing the entry + * @return the modified ObjectMap with the specified entry removed if the condition is true, or the original ObjectMap otherwise + */ + @Override + public ObjectMap removeEntryIfTrue(K key, boolean ifTrue) { + if (ifTrue) { + remove(key); + } + return this; + } + + /** + * Removes all entries with keys present in the specified map from the ObjectMap if the condition is true. + * + * @param map the map containing the keys to be removed + * @param ifTrue the condition to check before removing the entries + * @return the modified ObjectMap with the entries corresponding to the keys in the specified map removed if the condition is true, or the original ObjectMap otherwise + */ + @Override + public ObjectMap removeEntriesIfTrue(Map map, boolean ifTrue) { + if (ifTrue) { + for (Map.Entry entry : map.entrySet()) { + remove(entry.getKey()); + } + } + return this; + } + + /** + * Removes all entries with keys present in the specified ObjectMap from the ObjectMap if the condition is true. + * + * @param map the ObjectMap containing the keys to be removed + * @param ifTrue the condition to check before removing the entries + * @return the modified ObjectMap with the entries corresponding to the keys in the specified ObjectMap removed if the condition is true, or the original ObjectMap otherwise + */ + @Override + public ObjectMap removeEntriesIfTrue(ObjectMap map, boolean ifTrue) { + if (ifTrue) { + for (ObjectMap.Entry entry : map.entrySet()) { + remove(entry.getKey()); + } + } + return this; + } + /** * Gets the value of the given key as an Integer. * diff --git a/maps/src/main/java/com/georgev22/library/maps/LinkedObjectMap.java b/maps/src/main/java/com/georgev22/library/maps/LinkedObjectMap.java index 5d48c7f..72fbb1c 100644 --- a/maps/src/main/java/com/georgev22/library/maps/LinkedObjectMap.java +++ b/maps/src/main/java/com/georgev22/library/maps/LinkedObjectMap.java @@ -187,6 +187,95 @@ public ObjectMap appendIfTrue(ObjectMap mapIfTrue, Map mapIfFa return this; } + /** + * Removes the entry with the specified key from the ObjectMap. + * + * @param key the key of the entry to be removed + * @return the modified ObjectMap with the specified entry removed, or the original ObjectMap if the key was not found + */ + @Override + public ObjectMap removeEntry(K key) { + remove(key); + return this; + } + + /** + * Removes all entries with keys present in the specified map from the ObjectMap. + * + * @param map the map containing the keys to be removed + * @return the modified ObjectMap with the entries corresponding to the specified keys removed + */ + @Override + public ObjectMap removeEntries(Map map) { + for (Map.Entry entry : map.entrySet()) { + remove(entry.getKey()); + } + return this; + } + + /** + * Removes all entries with keys present in the specified ObjectMap from the ObjectMap. + * + * @param map the ObjectMap containing the keys to be removed + * @return the modified ObjectMap with the entries corresponding to the keys in the specified ObjectMap removed + */ + @Override + public ObjectMap removeEntries(ObjectMap map) { + for (ObjectMap.Entry entry : map.entrySet()) { + remove(entry.getKey()); + } + return this; + } + + /** + * Removes the entry with the specified key from the ObjectMap if the condition is true. + * + * @param key the key of the entry to be removed + * @param ifTrue the condition to check before removing the entry + * @return the modified ObjectMap with the specified entry removed if the condition is true, or the original ObjectMap otherwise + */ + @Override + public ObjectMap removeEntryIfTrue(K key, boolean ifTrue) { + if (ifTrue) { + remove(key); + } + return this; + } + + /** + * Removes all entries with keys present in the specified map from the ObjectMap if the condition is true. + * + * @param map the map containing the keys to be removed + * @param ifTrue the condition to check before removing the entries + * @return the modified ObjectMap with the entries corresponding to the keys in the specified map removed if the condition is true, or the original ObjectMap otherwise + */ + @Override + public ObjectMap removeEntriesIfTrue(Map map, boolean ifTrue) { + if (ifTrue) { + for (Map.Entry entry : map.entrySet()) { + remove(entry.getKey()); + } + } + return this; + } + + /** + * Removes all entries with keys present in the specified ObjectMap from the ObjectMap if the condition is true. + * + * @param map the ObjectMap containing the keys to be removed + * @param ifTrue the condition to check before removing the entries + * @return the modified ObjectMap with the entries corresponding to the keys in the specified ObjectMap removed if the condition is true, or the original ObjectMap otherwise + */ + @Override + public ObjectMap removeEntriesIfTrue(ObjectMap map, boolean ifTrue) { + if (ifTrue) { + for (ObjectMap.Entry entry : map.entrySet()) { + remove(entry.getKey()); + } + } + return this; + } + /** * Gets the value of the given key as an Integer. * diff --git a/maps/src/main/java/com/georgev22/library/maps/ObjectMap.java b/maps/src/main/java/com/georgev22/library/maps/ObjectMap.java index 449f3dc..79f5c87 100644 --- a/maps/src/main/java/com/georgev22/library/maps/ObjectMap.java +++ b/maps/src/main/java/com/georgev22/library/maps/ObjectMap.java @@ -253,6 +253,57 @@ public interface ObjectMap extends Map { */ ObjectMap appendIfTrue(final ObjectMap mapIfTrue, final Map mapIfFalse, boolean ifTrue); + /** + * Removes the entry with the specified key from the ObjectMap. + * + * @param key the key of the entry to be removed + * @return the modified ObjectMap with the specified entry removed, or the original ObjectMap if the key was not found + */ + ObjectMap removeEntry(final K key); + + /** + * Removes all entries with keys present in the specified map from the ObjectMap. + * + * @param map the map containing the keys to be removed + * @return the modified ObjectMap with the entries corresponding to the specified keys removed + */ + ObjectMap removeEntries(final Map map); + + /** + * Removes all entries with keys present in the specified ObjectMap from the ObjectMap. + * + * @param map the ObjectMap containing the keys to be removed + * @return the modified ObjectMap with the entries corresponding to the keys in the specified ObjectMap removed + */ + ObjectMap removeEntries(final ObjectMap map); + + /** + * Removes the entry with the specified key from the ObjectMap if the condition is true. + * + * @param key the key of the entry to be removed + * @param ifTrue the condition to check before removing the entry + * @return the modified ObjectMap with the specified entry removed if the condition is true, or the original ObjectMap otherwise + */ + ObjectMap removeEntryIfTrue(final K key, boolean ifTrue); + + /** + * Removes all entries with keys present in the specified map from the ObjectMap if the condition is true. + * + * @param map the map containing the keys to be removed + * @param ifTrue the condition to check before removing the entries + * @return the modified ObjectMap with the entries corresponding to the keys in the specified map removed if the condition is true, or the original ObjectMap otherwise + */ + ObjectMap removeEntriesIfTrue(final Map map, boolean ifTrue); + + /** + * Removes all entries with keys present in the specified ObjectMap from the ObjectMap if the condition is true. + * + * @param map the ObjectMap containing the keys to be removed + * @param ifTrue the condition to check before removing the entries + * @return the modified ObjectMap with the entries corresponding to the keys in the specified ObjectMap removed if the condition is true, or the original ObjectMap otherwise + */ + ObjectMap removeEntriesIfTrue(final ObjectMap map, boolean ifTrue); + /** * Gets the value of the given key as an Integer. * diff --git a/maps/src/main/java/com/georgev22/library/maps/TreeObjectMap.java b/maps/src/main/java/com/georgev22/library/maps/TreeObjectMap.java index 29e501f..119364c 100644 --- a/maps/src/main/java/com/georgev22/library/maps/TreeObjectMap.java +++ b/maps/src/main/java/com/georgev22/library/maps/TreeObjectMap.java @@ -187,6 +187,95 @@ public ObjectMap appendIfTrue(ObjectMap mapIfTrue, Map mapIfFa return this; } + /** + * Removes the entry with the specified key from the ObjectMap. + * + * @param key the key of the entry to be removed + * @return the modified ObjectMap with the specified entry removed, or the original ObjectMap if the key was not found + */ + @Override + public ObjectMap removeEntry(K key) { + remove(key); + return this; + } + + /** + * Removes all entries with keys present in the specified map from the ObjectMap. + * + * @param map the map containing the keys to be removed + * @return the modified ObjectMap with the entries corresponding to the specified keys removed + */ + @Override + public ObjectMap removeEntries(Map map) { + for (Map.Entry entry : map.entrySet()) { + remove(entry.getKey()); + } + return this; + } + + /** + * Removes all entries with keys present in the specified ObjectMap from the ObjectMap. + * + * @param map the ObjectMap containing the keys to be removed + * @return the modified ObjectMap with the entries corresponding to the keys in the specified ObjectMap removed + */ + @Override + public ObjectMap removeEntries(ObjectMap map) { + for (ObjectMap.Entry entry : map.entrySet()) { + remove(entry.getKey()); + } + return this; + } + + /** + * Removes the entry with the specified key from the ObjectMap if the condition is true. + * + * @param key the key of the entry to be removed + * @param ifTrue the condition to check before removing the entry + * @return the modified ObjectMap with the specified entry removed if the condition is true, or the original ObjectMap otherwise + */ + @Override + public ObjectMap removeEntryIfTrue(K key, boolean ifTrue) { + if (ifTrue) { + remove(key); + } + return this; + } + + /** + * Removes all entries with keys present in the specified map from the ObjectMap if the condition is true. + * + * @param map the map containing the keys to be removed + * @param ifTrue the condition to check before removing the entries + * @return the modified ObjectMap with the entries corresponding to the keys in the specified map removed if the condition is true, or the original ObjectMap otherwise + */ + @Override + public ObjectMap removeEntriesIfTrue(Map map, boolean ifTrue) { + if (ifTrue) { + for (Map.Entry entry : map.entrySet()) { + remove(entry.getKey()); + } + } + return this; + } + + /** + * Removes all entries with keys present in the specified ObjectMap from the ObjectMap if the condition is true. + * + * @param map the ObjectMap containing the keys to be removed + * @param ifTrue the condition to check before removing the entries + * @return the modified ObjectMap with the entries corresponding to the keys in the specified ObjectMap removed if the condition is true, or the original ObjectMap otherwise + */ + @Override + public ObjectMap removeEntriesIfTrue(ObjectMap map, boolean ifTrue) { + if (ifTrue) { + for (ObjectMap.Entry entry : map.entrySet()) { + remove(entry.getKey()); + } + } + return this; + } + /** * Gets the value of the given key as an Integer. * diff --git a/maps/src/main/java/com/georgev22/library/maps/UnmodifiableObjectMap.java b/maps/src/main/java/com/georgev22/library/maps/UnmodifiableObjectMap.java index 79d2447..8c70b10 100644 --- a/maps/src/main/java/com/georgev22/library/maps/UnmodifiableObjectMap.java +++ b/maps/src/main/java/com/georgev22/library/maps/UnmodifiableObjectMap.java @@ -37,7 +37,7 @@ public UnmodifiableObjectMap(Map map) { */ @Override public ObjectMap append(K key, V value) { - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException("UnmodifiableObjectMap"); } /** @@ -51,7 +51,7 @@ public ObjectMap append(K key, V value) { */ @Override public ObjectMap append(Map map) { - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException("UnmodifiableObjectMap"); } /** @@ -65,7 +65,7 @@ public ObjectMap append(Map map) { */ @Override public ObjectMap append(ObjectMap map) { - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException("UnmodifiableObjectMap"); } /** @@ -81,7 +81,7 @@ public ObjectMap append(ObjectMap map) { */ @Override public ObjectMap appendIfTrue(K key, V value, boolean ifTrue) { - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException("UnmodifiableObjectMap"); } /** @@ -98,7 +98,7 @@ public ObjectMap appendIfTrue(K key, V value, boolean ifTrue) { */ @Override public ObjectMap appendIfTrue(K key, V valueIfTrue, V valueIfFalse, boolean ifTrue) { - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException("UnmodifiableObjectMap"); } /** @@ -113,7 +113,7 @@ public ObjectMap appendIfTrue(K key, V valueIfTrue, V valueIfFalse, boolea */ @Override public ObjectMap appendIfTrue(Map map, boolean ifTrue) { - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException("UnmodifiableObjectMap"); } /** @@ -129,7 +129,7 @@ public ObjectMap appendIfTrue(Map map, boolean ifTrue) { */ @Override public ObjectMap appendIfTrue(Map mapIfTrue, Map mapIfFalse, boolean ifTrue) { - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException("UnmodifiableObjectMap"); } /** @@ -144,7 +144,7 @@ public ObjectMap appendIfTrue(Map mapIfTrue, Map mapIfFalse, b */ @Override public ObjectMap appendIfTrue(ObjectMap map, boolean ifTrue) { - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException("UnmodifiableObjectMap"); } /** @@ -160,7 +160,76 @@ public ObjectMap appendIfTrue(ObjectMap map, boolean ifTrue) { */ @Override public ObjectMap appendIfTrue(ObjectMap mapIfTrue, Map mapIfFalse, boolean ifTrue) { - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException("UnmodifiableObjectMap"); + } + + /** + * Removes the entry with the specified key from the ObjectMap. + * + * @param key the key of the entry to be removed + * @return the modified ObjectMap with the specified entry removed, or the original ObjectMap if the key was not found + */ + @Override + public ObjectMap removeEntry(K key) { + throw new UnsupportedOperationException("UnmodifiableObjectMap"); + } + + /** + * Removes all entries with keys present in the specified map from the ObjectMap. + * + * @param map the map containing the keys to be removed + * @return the modified ObjectMap with the entries corresponding to the specified keys removed + */ + @Override + public ObjectMap removeEntries(Map map) { + throw new UnsupportedOperationException("UnmodifiableObjectMap"); + } + + /** + * Removes all entries with keys present in the specified ObjectMap from the ObjectMap. + * + * @param map the ObjectMap containing the keys to be removed + * @return the modified ObjectMap with the entries corresponding to the keys in the specified ObjectMap removed + */ + @Override + public ObjectMap removeEntries(ObjectMap map) { + throw new UnsupportedOperationException("UnmodifiableObjectMap"); + } + + /** + * Removes the entry with the specified key from the ObjectMap if the condition is true. + * + * @param key the key of the entry to be removed + * @param ifTrue the condition to check before removing the entry + * @return the modified ObjectMap with the specified entry removed if the condition is true, or the original ObjectMap otherwise + */ + @Override + public ObjectMap removeEntryIfTrue(K key, boolean ifTrue) { + throw new UnsupportedOperationException("UnmodifiableObjectMap"); + } + + /** + * Removes all entries with keys present in the specified map from the ObjectMap if the condition is true. + * + * @param map the map containing the keys to be removed + * @param ifTrue the condition to check before removing the entries + * @return the modified ObjectMap with the entries corresponding to the keys in the specified map removed if the condition is true, or the original ObjectMap otherwise + */ + @Override + public ObjectMap removeEntriesIfTrue(Map map, boolean ifTrue) { + throw new UnsupportedOperationException("UnmodifiableObjectMap"); + } + + /** + * Removes all entries with keys present in the specified ObjectMap from the ObjectMap if the condition is true. + * + * @param map the ObjectMap containing the keys to be removed + * @param ifTrue the condition to check before removing the entries + * @return the modified ObjectMap with the entries corresponding to the keys in the specified ObjectMap removed if the condition is true, or the original ObjectMap otherwise + */ + @Override + public ObjectMap removeEntriesIfTrue(ObjectMap map, boolean ifTrue) { + throw new UnsupportedOperationException("UnmodifiableObjectMap"); } /** @@ -496,7 +565,7 @@ public V get(Object key) { @Nullable @Override public V put(K key, V value) { - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException("UnmodifiableObjectMap"); } /** @@ -531,7 +600,7 @@ public V put(K key, V value) { */ @Override public V remove(Object key) { - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException("UnmodifiableObjectMap"); } /** @@ -555,7 +624,7 @@ public V remove(Object key) { */ @Override public void putAll(@NotNull Map m) { - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException("UnmodifiableObjectMap"); } /** @@ -567,7 +636,7 @@ public void putAll(@NotNull Map m) { */ @Override public void clear() { - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException("UnmodifiableObjectMap"); } /**