summaryrefslogtreecommitdiff
path: root/src/main/java/sevenUnits/utils/ConditionalExistenceCollections.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/sevenUnits/utils/ConditionalExistenceCollections.java')
-rw-r--r--src/main/java/sevenUnits/utils/ConditionalExistenceCollections.java63
1 files changed, 31 insertions, 32 deletions
diff --git a/src/main/java/sevenUnits/utils/ConditionalExistenceCollections.java b/src/main/java/sevenUnits/utils/ConditionalExistenceCollections.java
index dd21a22..6244ee6 100644
--- a/src/main/java/sevenUnits/utils/ConditionalExistenceCollections.java
+++ b/src/main/java/sevenUnits/utils/ConditionalExistenceCollections.java
@@ -49,8 +49,8 @@ import java.util.function.Predicate;
* Other than that, <i>the only difference between the provided collections and
* the returned collections are that elements don't exist if they don't pass the
* provided condition</i>.
- *
- *
+ *
+ *
* @author Adrien Hopkins
* @since 2019-10-17
* @since v0.3.0
@@ -58,7 +58,7 @@ import java.util.function.Predicate;
public final class ConditionalExistenceCollections {
/**
* Elements in this collection only exist if they meet a condition.
- *
+ *
* @author Adrien Hopkins
* @since 2019-10-17
* @since v0.3.0
@@ -71,7 +71,7 @@ public final class ConditionalExistenceCollections {
/**
* Creates the {@code ConditionalExistenceCollection}.
- *
+ *
* @param collection
* @param existenceCondition
* @since 2019-10-17
@@ -103,7 +103,7 @@ public final class ConditionalExistenceCollections {
// instance of E
// therefore this cast will always work
@SuppressWarnings("unchecked")
- final E e = (E) o;
+ final var e = (E) o;
return this.existenceCondition.test(e);
}
@@ -118,7 +118,7 @@ public final class ConditionalExistenceCollections {
public boolean remove(final Object o) {
// remove() must be first in the && statement, otherwise it may not
// execute
- final boolean containedObject = this.contains(o);
+ final var containedObject = this.contains(o);
return this.collection.remove(o) && containedObject;
}
@@ -149,7 +149,7 @@ public final class ConditionalExistenceCollections {
/**
* Elements in this wrapper iterator only exist if they pass a condition.
- *
+ *
* @author Adrien Hopkins
* @since 2019-10-17
* @since v0.3.0
@@ -163,7 +163,7 @@ public final class ConditionalExistenceCollections {
/**
* Creates the {@code ConditionalExistenceIterator}.
- *
+ *
* @param iterator
* @param condition
* @since 2019-10-17
@@ -178,7 +178,7 @@ public final class ConditionalExistenceCollections {
/**
* Gets the next element, and sets nextElement and hasNext accordingly.
- *
+ *
* @since 2019-10-17
* @since v0.3.0
*/
@@ -202,11 +202,11 @@ public final class ConditionalExistenceCollections {
@Override
public E next() {
if (this.hasNext()) {
- final E next = this.nextElement;
+ final var next = this.nextElement;
this.getAndSetNextElement();
return next;
- } else
- throw new NoSuchElementException();
+ }
+ throw new NoSuchElementException();
}
@Override
@@ -217,7 +217,7 @@ public final class ConditionalExistenceCollections {
/**
* Mappings in this map only exist if the entry passes some condition.
- *
+ *
* @author Adrien Hopkins
* @since 2019-10-17
* @since v0.3.0
@@ -230,7 +230,7 @@ public final class ConditionalExistenceCollections {
/**
* Creates the {@code ConditionalExistenceMap}.
- *
+ *
* @param map
* @param entryExistenceCondition
* @since 2019-10-17
@@ -250,10 +250,10 @@ public final class ConditionalExistenceCollections {
// only instances of K have mappings in the backing map
// since we know that key is a valid key, it must be an instance of K
@SuppressWarnings("unchecked")
- final K keyAsK = (K) key;
+ final var keyAsK = (K) key;
// get and test entry
- final V value = this.map.get(key);
+ final var value = this.map.get(key);
final Entry<K, V> entry = new SimpleEntry<>(keyAsK, value);
return this.entryExistenceCondition.test(entry);
}
@@ -269,7 +269,7 @@ public final class ConditionalExistenceCollections {
return this.containsKey(key) ? this.map.get(key) : null;
}
- private final Entry<K, V> getEntry(K key) {
+ private Entry<K, V> getEntry(K key) {
return new Entry<>() {
@Override
public K getKey() {
@@ -296,7 +296,7 @@ public final class ConditionalExistenceCollections {
@Override
public V put(final K key, final V value) {
- final V oldValue = this.map.put(key, value);
+ final var oldValue = this.map.put(key, value);
// get and test entry
final Entry<K, V> entry = new SimpleEntry<>(key, oldValue);
@@ -305,7 +305,7 @@ public final class ConditionalExistenceCollections {
@Override
public V remove(final Object key) {
- final V oldValue = this.map.remove(key);
+ final var oldValue = this.map.remove(key);
return this.containsKey(key) ? oldValue : null;
}
@@ -318,7 +318,7 @@ public final class ConditionalExistenceCollections {
/**
* Elements in this set only exist if a certain condition is true.
- *
+ *
* @author Adrien Hopkins
* @since 2019-10-17
* @since v0.3.0
@@ -330,7 +330,7 @@ public final class ConditionalExistenceCollections {
/**
* Creates the {@code ConditionalNonexistenceSet}.
- *
+ *
* @param set set to use
* @param existenceCondition condition where element exists
* @since 2019-10-17
@@ -368,7 +368,7 @@ public final class ConditionalExistenceCollections {
// of E
// therefore this cast will always work
@SuppressWarnings("unchecked")
- final E e = (E) o;
+ final var e = (E) o;
return this.existenceCondition.test(e);
}
@@ -383,7 +383,7 @@ public final class ConditionalExistenceCollections {
public boolean remove(final Object o) {
// remove() must be first in the && statement, otherwise it may not
// execute
- final boolean containedObject = this.contains(o);
+ final var containedObject = this.contains(o);
return this.set.remove(o) && containedObject;
}
@@ -414,7 +414,7 @@ public final class ConditionalExistenceCollections {
/**
* Elements in the returned wrapper collection are ignored if they don't pass
* a condition.
- *
+ *
* @param <E> type of elements in collection
* @param collection collection to wrap
* @param existenceCondition elements only exist if this returns true
@@ -422,7 +422,7 @@ public final class ConditionalExistenceCollections {
* @since 2019-10-17
* @since v0.3.0
*/
- public static final <E> Collection<E> conditionalExistenceCollection(
+ public static <E> Collection<E> conditionalExistenceCollection(
final Collection<E> collection,
final Predicate<E> existenceCondition) {
return new ConditionalExistenceCollection<>(collection,
@@ -432,7 +432,7 @@ public final class ConditionalExistenceCollections {
/**
* Elements in the returned wrapper iterator are ignored if they don't pass a
* condition.
- *
+ *
* @param <E> type of elements in iterator
* @param iterator iterator to wrap
* @param existenceCondition elements only exist if this returns true
@@ -440,7 +440,7 @@ public final class ConditionalExistenceCollections {
* @since 2019-10-17
* @since v0.3.0
*/
- public static final <E> Iterator<E> conditionalExistenceIterator(
+ public static <E> Iterator<E> conditionalExistenceIterator(
final Iterator<E> iterator, final Predicate<E> existenceCondition) {
return new ConditionalExistenceIterator<>(iterator, existenceCondition);
}
@@ -448,7 +448,7 @@ public final class ConditionalExistenceCollections {
/**
* Mappings in the returned wrapper map are ignored if the corresponding
* entry doesn't pass a condition
- *
+ *
* @param <K> type of key in map
* @param <V> type of value in map
* @param map map to wrap
@@ -457,8 +457,7 @@ public final class ConditionalExistenceCollections {
* @since 2019-10-17
* @since v0.3.0
*/
- public static final <K, V> Map<K, V> conditionalExistenceMap(
- final Map<K, V> map,
+ public static <K, V> Map<K, V> conditionalExistenceMap(final Map<K, V> map,
final Predicate<Entry<K, V>> entryExistenceCondition) {
return new ConditionalExistenceMap<>(map, entryExistenceCondition);
}
@@ -466,7 +465,7 @@ public final class ConditionalExistenceCollections {
/**
* Elements in the returned wrapper set are ignored if they don't pass a
* condition.
- *
+ *
* @param <E> type of elements in set
* @param set set to wrap
* @param existenceCondition elements only exist if this returns true
@@ -474,7 +473,7 @@ public final class ConditionalExistenceCollections {
* @since 2019-10-17
* @since v0.3.0
*/
- public static final <E> Set<E> conditionalExistenceSet(final Set<E> set,
+ public static <E> Set<E> conditionalExistenceSet(final Set<E> set,
final Predicate<E> existenceCondition) {
return new ConditionalExistenceSet<>(set, existenceCondition);
}