Package org.sosy_lab.common.collect
Class Collections3
java.lang.Object
org.sosy_lab.common.collect.Collections3
Utility class similar to
Collections and Collections2.-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanallElementsEqual(Iterable<?> iterable) Check whether all elements contained in the given iterable are equal to each other.static booleanallElementsEqual(Object[] array) Check whether all elements contained in the given array are equal to each other.static booleanallElementsEqual(Stream<?> stream) Check whether all elements contained in the given stream are equal to each other.static <T> ImmutableList<T>elementAndList(T elem, Collection<? extends T> coll) Return a list that contains the given element and the given collection.static <T> ImmutableList<T>elementsAndList(T elem1, T elem2, Collection<? extends T> coll) Return a list that contains the given elements and the given collection.static <T> Stream<T>filterByClass(Iterable<? super T> iterable, Class<T> cls) Provide a stream that results from filtering the given iterable's element by their class.static <T> Stream<T>filterByClass(Collection<? super T> collection, Class<T> cls) Provide a stream that results from filtering the given collection's element by their class.static <T> Stream<T>filterByClass(Stream<? super T> stream, Class<T> cls) Provide a stream that results from filtering the given stream's element by their class.static <T> ImmutableList<T>listAndElement(Collection<? extends T> coll, T elem) Return a list that contains the given collection and the given element.static <T> ImmutableList<T>listAndElements(Collection<? extends T> coll, T elem1, T elem2) Return a list that contains the given collection and the given elements.static <T> ImmutableList<T>listAndSurroundingElements(T elem1, Collection<? extends T> coll, T elem2) Return a list that contains the given collection and the given elements, one before the collection and one after.static <V> NavigableMap<String,V> subMapWithPrefix(NavigableMap<String, V> map, String prefix) Given aNavigableMapwithStrings as key, return a partial map (similar toNavigableMap.subMap(Object, Object)) of all keys that have a given prefix.subMapWithPrefix(SortedMap<String, V> map, String prefix) Given aSortedMapwithStrings as key, return a partial map (similar toSortedMap.subMap(Object, Object)) of all keys that have a given prefix.static NavigableSet<String>subSetWithPrefix(NavigableSet<String> set, String prefix) Given aNavigableSetofString, return a set (similar toNavigableSet.subSet(Object, Object)) of all entries that have a given prefix.subSetWithPrefix(SortedSet<String> set, String prefix) Given aSortedSetofString, return a set (similar toSortedSet.subSet(Object, Object)) of all entries that have a given prefix.static <T1,T2> ImmutableList<T2> transformedImmutableListCopy(Collection<T1> input, Function<? super T1, T2> transformer) Apply a function to all elements in a collection and return anImmutableListwith the results.static <T1,T2> ImmutableList<T2> transformedImmutableListCopy(T1[] input, Function<? super T1, T2> transformer) Apply a function to all elements in an array and return anImmutableListwith the results.static <T1,T2> ImmutableSet<T2> transformedImmutableSetCopy(Collection<T1> input, Function<? super T1, T2> transformer) Apply a function to all elements in a collection and return anImmutableSetwith the results.static <K,V, R> Stream<R> zipMapEntries(Iterable<Map.Entry<K, V>> entries, BiFunction<K, V, R> func) Provide a stream that consists of the result of applying the given function to each of the map entries, similarly toStreams.zip(Stream, Stream, BiFunction).static <K,V, R> Stream<R> zipMapEntries(Map<K, V> map, BiFunction<K, V, R> func) Provide a stream that consists of the result of applying the given function to each of a map's entries, similarly toStreams.zip(Stream, Stream, BiFunction).
-
Method Details
-
allElementsEqual
Check whether all elements contained in the given iterable are equal to each other. For a non-empty iterable, this is the same asImmutableSet.copyOf(iterable).size() == 1, but more efficient.- Throws:
IllegalArgumentException- if the iterable is empty
-
allElementsEqual
Check whether all elements contained in the given array are equal to each other. For a non-empty array, this is the same asImmutableSet.copyOf(array).size() == 1, but more efficient.- Throws:
IllegalArgumentException- if the array is empty
-
allElementsEqual
Check whether all elements contained in the given stream are equal to each other. For a non-empty stream, this is the same asstream.distinct().count() == 1, but more efficient.- Throws:
IllegalArgumentException- if the stream is empty
-
transformedImmutableListCopy
public static <T1,T2> ImmutableList<T2> transformedImmutableListCopy(Collection<T1> input, Function<? super T1, T2> transformer) Apply a function to all elements in a collection and return anImmutableListwith the results. This is an eager version ofLists.transform(List, Function)andCollections2.transform(Collection, Function).This function is more efficient than code doing the same using
StreamorFluentIterable. -
transformedImmutableListCopy
public static <T1,T2> ImmutableList<T2> transformedImmutableListCopy(T1[] input, Function<? super T1, T2> transformer) Apply a function to all elements in an array and return anImmutableListwith the results.This function is more efficient than code doing the same using
StreamorFluentIterable. -
transformedImmutableSetCopy
public static <T1,T2> ImmutableSet<T2> transformedImmutableSetCopy(Collection<T1> input, Function<? super T1, T2> transformer) Apply a function to all elements in a collection and return anImmutableSetwith the results. This is an eager version ofCollections2.transform(Collection, Function). -
zipMapEntries
Provide a stream that consists of the result of applying the given function to each of a map's entries, similarly toStreams.zip(Stream, Stream, BiFunction). -
zipMapEntries
public static <K,V, Stream<R> zipMapEntriesR> (Iterable<Map.Entry<K, V>> entries, BiFunction<K, V, R> func) Provide a stream that consists of the result of applying the given function to each of the map entries, similarly toStreams.zip(Stream, Stream, BiFunction). -
filterByClass
Provide a stream that results from filtering the given stream's element by their class. Additionally, the resulting stream is typed accordingly. This is a stream equivalent ofFluentIterable.filter(Class)andIterables.filter(Iterable, Class). -
filterByClass
Provide a stream that results from filtering the given collection's element by their class. Additionally, the resulting stream is typed accordingly. This is a stream equivalent ofFluentIterable.filter(Class)andIterables.filter(Iterable, Class). -
filterByClass
Provide a stream that results from filtering the given iterable's element by their class. Additionally, the resulting stream is typed accordingly. This is a stream equivalent ofFluentIterable.filter(Class)andIterables.filter(Iterable, Class). -
elementAndList
Return a list that contains the given element and the given collection. -
listAndElement
Return a list that contains the given collection and the given element. -
elementsAndList
Return a list that contains the given elements and the given collection. -
listAndSurroundingElements
public static <T> ImmutableList<T> listAndSurroundingElements(T elem1, Collection<? extends T> coll, T elem2) Return a list that contains the given collection and the given elements, one before the collection and one after. -
listAndElements
Return a list that contains the given collection and the given elements. -
subMapWithPrefix
Given aSortedMapwithStrings as key, return a partial map (similar toSortedMap.subMap(Object, Object)) of all keys that have a given prefix.- Parameters:
map- The map to filter.prefix- The prefix that all keys in the result need to have.- Returns:
- A partial map of the input.
-
subSetWithPrefix
Given aSortedSetofString, return a set (similar toSortedSet.subSet(Object, Object)) of all entries that have a given prefix.- Parameters:
set- The set to filter.prefix- The prefix that all keys in the result need to have.- Returns:
- A subset of the input.
-