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>
public class SubclassFilteredCollection<S,T extends S> extends 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 Collection<? extends S>
collection
private Predicate<? super S>
predicate
private int
size
-
Constructor Summary
Constructors Constructor Description SubclassFilteredCollection(Collection<? extends S> collection, 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(Collection<? extends T> collection, Predicate<T> predicate)
Create a new filtered collection without any constraints on the predicate type.boolean
isEmpty()
Iterator<T>
iterator()
int
size()
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
-
Methods inherited from interface java.util.Collection
equals, hashCode, parallelStream, removeIf, stream, toArray
-
-
-
-
Field Detail
-
collection
private final Collection<? extends S> collection
-
size
private int size
-
-
Constructor Detail
-
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:
for an alternative way to construct this.
-
-
Method Detail
-
iterator
public Iterator<T> iterator()
- Specified by:
iterator
in interfaceCollection<S>
- Specified by:
iterator
in interfaceIterable<S>
- Specified by:
iterator
in classAbstractCollection<T extends S>
-
spliterator
public Spliterator<T> spliterator()
-
size
public int size()
- Specified by:
size
in interfaceCollection<S>
- Specified by:
size
in classAbstractCollection<T extends S>
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmpty
in interfaceCollection<S>
- Overrides:
isEmpty
in 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>
.
-
-