public final class ConditionalExistenceCollections
extends java.lang.Object
All of the collections in this class are "views" of the provided collections. They are mutable if the provided collections are mutable, they allow null if the provided collections allow null, they will reflect changes in the provided collection, etc.
The modification operations will always run the corresponding operations, even if the conditional existence collection doesn't change. For example, if you have a set that ignores even numbers, add(2) will still add a 2 to the backing set (but the conditional existence set will say it doesn't exist).
The returned collections do not pass the hashCode and equals operations through to the backing collections,
but rely on Object
's equals
and hashCode
methods. This is necessary to preserve the contracts
of these operations in the case that the backing collections are sets or lists.
Other than that, 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.
Constructor and Description |
---|
ConditionalExistenceCollections() |
Modifier and Type | Method and Description |
---|---|
static <E> java.util.Collection<E> |
conditionalExistenceCollection(java.util.Collection<E> collection,
java.util.function.Predicate<E> existenceCondition)
Elements in the returned wrapper collection are ignored if they don't pass a condition.
|
static <E> java.util.Iterator<E> |
conditionalExistenceIterator(java.util.Iterator<E> iterator,
java.util.function.Predicate<E> existenceCondition)
Elements in the returned wrapper iterator are ignored if they don't pass a condition.
|
static <K,V> java.util.Map<K,V> |
conditionalExistenceMap(java.util.Map<K,V> map,
java.util.function.Predicate<java.util.Map.Entry<K,V>> entryExistenceCondition)
Mappings in the returned wrapper map are ignored if the corresponding entry doesn't pass a condition
|
static <E> java.util.Set<E> |
conditionalExistenceSet(java.util.Set<E> set,
java.util.function.Predicate<E> existenceCondition)
Elements in the returned wrapper set are ignored if they don't pass a condition.
|
public static final <E> java.util.Collection<E> conditionalExistenceCollection(java.util.Collection<E> collection, java.util.function.Predicate<E> existenceCondition)
E
- type of elements in collectioncollection
- collection to wrapexistenceCondition
- elements only exist if this returns truepublic static final <E> java.util.Iterator<E> conditionalExistenceIterator(java.util.Iterator<E> iterator, java.util.function.Predicate<E> existenceCondition)
E
- type of elements in iteratoriterator
- iterator to wrapexistenceCondition
- elements only exist if this returns truepublic static final <K,V> java.util.Map<K,V> conditionalExistenceMap(java.util.Map<K,V> map, java.util.function.Predicate<java.util.Map.Entry<K,V>> entryExistenceCondition)
K
- type of key in mapV
- type of value in mapmap
- map to wrapentryExistenceCondition
- mappings only exist if this returns truepublic static final <E> java.util.Set<E> conditionalExistenceSet(java.util.Set<E> set, java.util.function.Predicate<E> existenceCondition)
E
- type of elements in setset
- set to wrapexistenceCondition
- elements only exist if this returns true