Skip to content

Commit

Permalink
feat(maps): Add methods to remove entries
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeV220 committed May 30, 2023
1 parent c85507c commit b8efaa3
Show file tree
Hide file tree
Showing 6 changed files with 489 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,95 @@ public ObjectMap<K, V> appendIfTrue(ObjectMap<K, V> mapIfTrue, Map<K, V> 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<K, V> 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<K, V> removeEntries(Map<K, V> map) {
for (Map.Entry<K, V> 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<K, V> removeEntries(ObjectMap<K, V> map) {
for (ObjectMap.Entry<K, V> 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<K, V> 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<K, V> removeEntriesIfTrue(Map<K, V> map, boolean ifTrue) {
if (ifTrue) {
for (Map.Entry<K, V> 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<K, V> removeEntriesIfTrue(ObjectMap<K, V> map, boolean ifTrue) {
if (ifTrue) {
for (ObjectMap.Entry<K, V> entry : map.entrySet()) {
remove(entry.getKey());
}
}
return this;
}

/**
* Gets the value of the given key as an Integer.
*
Expand Down
89 changes: 89 additions & 0 deletions maps/src/main/java/com/georgev22/library/maps/HashObjectMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,95 @@ public ObjectMap<K, V> appendIfTrue(ObjectMap<K, V> mapIfTrue, Map<K, V> 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<K, V> 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<K, V> removeEntries(Map<K, V> map) {
for (Map.Entry<K, V> 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<K, V> removeEntries(ObjectMap<K, V> map) {
for (ObjectMap.Entry<K, V> 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<K, V> 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<K, V> removeEntriesIfTrue(Map<K, V> map, boolean ifTrue) {
if (ifTrue) {
for (Map.Entry<K, V> 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<K, V> removeEntriesIfTrue(ObjectMap<K, V> map, boolean ifTrue) {
if (ifTrue) {
for (ObjectMap.Entry<K, V> entry : map.entrySet()) {
remove(entry.getKey());
}
}
return this;
}

/**
* Gets the value of the given key as an Integer.
*
Expand Down
89 changes: 89 additions & 0 deletions maps/src/main/java/com/georgev22/library/maps/LinkedObjectMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,95 @@ public ObjectMap<K, V> appendIfTrue(ObjectMap<K, V> mapIfTrue, Map<K, V> 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<K, V> 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<K, V> removeEntries(Map<K, V> map) {
for (Map.Entry<K, V> 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<K, V> removeEntries(ObjectMap<K, V> map) {
for (ObjectMap.Entry<K, V> 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<K, V> 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<K, V> removeEntriesIfTrue(Map<K, V> map, boolean ifTrue) {
if (ifTrue) {
for (Map.Entry<K, V> 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<K, V> removeEntriesIfTrue(ObjectMap<K, V> map, boolean ifTrue) {
if (ifTrue) {
for (ObjectMap.Entry<K, V> entry : map.entrySet()) {
remove(entry.getKey());
}
}
return this;
}

/**
* Gets the value of the given key as an Integer.
*
Expand Down
51 changes: 51 additions & 0 deletions maps/src/main/java/com/georgev22/library/maps/ObjectMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,57 @@ public interface ObjectMap<K, V> extends Map<K, V> {
*/
ObjectMap<K, V> appendIfTrue(final ObjectMap<K, V> mapIfTrue, final Map<K, V> 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<K, V> 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<K, V> removeEntries(final Map<K, V> 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<K, V> removeEntries(final ObjectMap<K, V> 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<K, V> 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<K, V> removeEntriesIfTrue(final Map<K, V> 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<K, V> removeEntriesIfTrue(final ObjectMap<K, V> map, boolean ifTrue);

/**
* Gets the value of the given key as an Integer.
*
Expand Down
Loading

0 comments on commit b8efaa3

Please sign in to comment.