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:
java.lang.Iterable<T>
,java.util.Collection<T>
public class SubclassFilteredCollection<S,T extends S> extends java.util.AbstractCollection<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 Modifier and Type Class Description private class
SubclassFilteredCollection.FilterIterator
-
Field Summary
Fields Modifier and Type Field Description private java.util.Collection<? extends S>
collection
private java.util.function.Predicate<? super S>
predicate
private int
size
-
Constructor Summary
Constructors Constructor Description SubclassFilteredCollection(java.util.Collection<? extends S> collection, java.util.function.Predicate<? super S> predicate)
Constructs a newSubclassFilteredCollection
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <T> SubclassFilteredCollection<T,T>
filter(java.util.Collection<? extends T> collection, java.util.function.Predicate<T> predicate)
Create a new filtered collection without any constraints on the predicate type.boolean
isEmpty()
java.util.Iterator<T>
iterator()
int
size()
java.util.Spliterator<T>
spliterator()
-
Methods inherited from class java.util.AbstractCollection
add, addAll, clear, contains, containsAll, remove, removeAll, retainAll, toArray, toArray, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
-
-
-
Field Detail
-
collection
private final java.util.Collection<? extends S> collection
-
size
private int size
-
-
Constructor Detail
-
SubclassFilteredCollection
public SubclassFilteredCollection(java.util.Collection<? extends S> collection, java.util.function.Predicate<? super S> predicate)
Constructs a newSubclassFilteredCollection
.- Parameters:
collection
- The base collection to filterpredicate
- The predicate to use as filter- See Also:
for an alternative way to construct this.
-
-
Method Detail
-
spliterator
public java.util.Spliterator<T> spliterator()
-
size
public int size()
-
isEmpty
public boolean isEmpty()
-
filter
public static <T> SubclassFilteredCollection<T,T> filter(java.util.Collection<? extends T> collection, java.util.function.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>
.
-
-