Package org.openstreetmap.josm.tools
Class SubclassFilteredCollection<S,T extends S>
java.lang.Object
java.util.AbstractCollection<T>
org.openstreetmap.josm.tools.SubclassFilteredCollection<S,T>
- Type Parameters:
S- element type of the underlying collectionT- element type of filtered collection (and subclass of S). The predicate must accept only objects of type T.
- All Implemented Interfaces:
Iterable<T>,Collection<T>
Filtered view of a collection.
(read-only collection, but elements can be changed, of course)
Lets you iterate through those elements of a given collection that satisfy a
certain condition (imposed by a predicate).
The behaviour of this class is undefined if the underlying collection is changed.
- Since:
- 3147
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionSubclassFilteredCollection(Collection<? extends S> collection, Predicate<? super S> predicate) Constructs a newSubclassFilteredCollection. -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> SubclassFilteredCollection<T,T> filter(Collection<? extends T> collection, Predicate<T> predicate) Create a new filtered collection without any constraints on the predicate type.booleanisEmpty()iterator()intsize()Methods inherited from class java.util.AbstractCollection
add, addAll, clear, contains, containsAll, remove, removeAll, retainAll, toArray, toArray, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
equals, hashCode, parallelStream, removeIf, stream, toArray
-
Field Details
-
collection
-
predicate
-
size
-
-
Constructor Details
-
SubclassFilteredCollection
public SubclassFilteredCollection(Collection<? extends S> collection, Predicate<? super S> predicate) Constructs a newSubclassFilteredCollection.- Parameters:
collection- The base collection to filterpredicate- The predicate to use as filter- See Also:
-
-
Method Details
-
iterator
- Specified by:
iteratorin interfaceCollection<S>- Specified by:
iteratorin interfaceIterable<S>- Specified by:
iteratorin classAbstractCollection<T extends S>
-
spliterator
-
size
- Specified by:
sizein interfaceCollection<S>- Specified by:
sizein classAbstractCollection<T extends S>
-
isEmpty
- Specified by:
isEmptyin interfaceCollection<S>- Overrides:
isEmptyin classAbstractCollection<T extends S>
-
filter
public static <T> SubclassFilteredCollection<T,T> filter(Collection<? extends T> collection, Predicate<T> predicate) Create a new filtered collection without any constraints on the predicate type.- Type Parameters:
T- The collection type.- Parameters:
collection- The collection to filter.predicate- The predicate to filter for.- Returns:
- The filtered collection. It is a
Collection<T>.
-