Class CollectionUtil
java.lang.Object
org.eclipse.net4j.util.collection.CollectionUtil
Various static helper methods.
- Since:
- 3.5
- Author:
- Eike Stepper
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> booleanaddNotNull(Collection<? super T> c, T e) static voidstatic <K,V> V compute(Map<K, V> map, K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) static <T> Stream<T> concat(Collection<Stream<T>> streams) Returns a stream that concatenates the given streams.static <T> Stream<T> Returns a stream that concatenates the given streams.static <T> Iterator<T> static <T> Tfirst(Collection<? extends T> c) static <K,V> List <K> removeAll(Map<K, V> map, BiPredicate<K, V> predicate) static <T> Set<T> setOf(Collection<? extends T> c) static <T> Stream<T> Returns a stream over the elements of the given iterator.subclasses(Class<TYPE> clazz) Returns a function that returns a stream containing the given object if it is an instance of the given class; otherwise an empty stream.static <NODE> List<NODE> topologicalSort(Collection<NODE> nodes, Function<NODE, Collection<NODE>> edgeProvider) static <NODE> List<NODE> topologicalSort(Collection<NODE> nodes, Function<NODE, Collection<NODE>> edgeProvider, boolean reverse)
-
Method Details
-
close
- Since:
- 3.29
-
dump
-
topologicalSort
public static <NODE> List<NODE> topologicalSort(Collection<NODE> nodes, Function<NODE, Collection<NODE>> edgeProvider) - Since:
- 3.25
-
topologicalSort
public static <NODE> List<NODE> topologicalSort(Collection<NODE> nodes, Function<NODE, Collection<NODE>> edgeProvider, boolean reverse) - Since:
- 3.25
-
addNotNull
- Since:
- 3.16
-
setOf
- Since:
- 3.16
-
first
- Since:
- 3.16
-
removeAll
- Since:
- 3.16
-
compute
public static <K,V> V compute(Map<K, V> map, K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) - Since:
- 3.16
-
subclasses
public static <SUBTYPE,TYPE extends SUBTYPE> Function<? super SUBTYPE,? extends Stream<? extends TYPE>> subclasses(Class<TYPE> clazz) Returns a function that returns a stream containing the given object if it is an instance of the given class; otherwise an empty stream.Example usage:
Stream<Animal> animals = Stream.of(new Dog(), new Cat(), new Bird()); Stream<Dog> dogs = animals.flatMap(CollectionUtil.subclasses(Dog.class));
This example creates a stream of animals and then uses the
subclassesfunction to filter and cast the stream to only include instances ofDog. This is a little easier to read and remember than usingfilterandmapseparately, as the following equivalent code shows:Stream<Dog> dogs = animals .filter(Dog.class::isInstance) .map(Dog.class::cast);- Since:
- 3.29
-
stream
Returns a stream over the elements of the given iterator.- Since:
- 3.29
-
concat
Returns a stream that concatenates the given streams.- Since:
- 3.26
-
concat
Returns a stream that concatenates the given streams.- Since:
- 3.26
-