Package org.sosy_lab.common.collect
Class Collections3
- java.lang.Object
-
- org.sosy_lab.common.collect.Collections3
-
public final class Collections3 extends Object
Utility class similar toCollections
andCollections2
.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
allElementsEqual(Iterable<?> iterable)
Check whether all elements contained in the given iterable are equal to each other.static boolean
allElementsEqual(Object[] array)
Check whether all elements contained in the given array are equal to each other.static boolean
allElementsEqual(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 aNavigableMap
withString
s as key, return a partial map (similar toNavigableMap.subMap(Object, Object)
) of all keys that have a given prefix.static <V> SortedMap<String,V>
subMapWithPrefix(SortedMap<String,V> map, String prefix)
Given aSortedMap
withString
s 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 aNavigableSet
ofString
, return a set (similar toNavigableSet.subSet(Object, Object)
) of all entries that have a given prefix.static SortedSet<String>
subSetWithPrefix(SortedSet<String> set, String prefix)
Given aSortedSet
ofString
, 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 anImmutableList
with 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 anImmutableList
with 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 anImmutableSet
with 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 Detail
-
allElementsEqual
public static boolean allElementsEqual(Iterable<?> iterable)
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
public static boolean allElementsEqual(Object[] array)
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
public static boolean allElementsEqual(Stream<?> stream)
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 anImmutableList
with 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
Stream
orFluentIterable
.
-
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 anImmutableList
with the results.This function is more efficient than code doing the same using
Stream
orFluentIterable
.
-
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 anImmutableSet
with the results. This is an eager version ofCollections2.transform(Collection, Function)
.
-
zipMapEntries
public 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)
.
-
zipMapEntries
public 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)
.
-
filterByClass
public 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. Additionally, the resulting stream is typed accordingly. This is a stream equivalent ofFluentIterable.filter(Class)
andIterables.filter(Iterable, Class)
.
-
filterByClass
public 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. Additionally, the resulting stream is typed accordingly. This is a stream equivalent ofFluentIterable.filter(Class)
andIterables.filter(Iterable, Class)
.
-
filterByClass
public 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. Additionally, the resulting stream is typed accordingly. This is a stream equivalent ofFluentIterable.filter(Class)
andIterables.filter(Iterable, Class)
.
-
elementAndList
public static <T> ImmutableList<T> elementAndList(T elem, Collection<? extends T> coll)
Return a list that contains the given element and the given collection.
-
listAndElement
public static <T> ImmutableList<T> listAndElement(Collection<? extends T> coll, T elem)
Return a list that contains the given collection and the given element.
-
elementsAndList
public 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.
-
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
public 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.
-
subMapWithPrefix
public static <V> NavigableMap<String,V> subMapWithPrefix(NavigableMap<String,V> map, String prefix)
Given aNavigableMap
withString
s as key, return a partial map (similar toNavigableMap.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.
-
subMapWithPrefix
public static <V> SortedMap<String,V> subMapWithPrefix(SortedMap<String,V> map, String prefix)
Given aSortedMap
withString
s 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
public static NavigableSet<String> subSetWithPrefix(NavigableSet<String> set, String prefix)
Given aNavigableSet
ofString
, return a set (similar toNavigableSet.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.
-
subSetWithPrefix
public static SortedSet<String> subSetWithPrefix(SortedSet<String> set, String prefix)
Given aSortedSet
ofString
, 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.
-
-