Class Collections3

java.lang.Object
org.sosy_lab.common.collect.Collections3

public final class Collections3 extends Object
Utility class similar to Collections and Collections2.
  • Method Details

    • 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 as ImmutableSet.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 as ImmutableSet.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 as stream.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 an ImmutableList with the results. This is an eager version of Lists.transform(List, Function) and Collections2.transform(Collection, Function).

      This function is more efficient than code doing the same using Stream or FluentIterable.

    • 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 an ImmutableList with the results.

      This function is more efficient than code doing the same using Stream or FluentIterable.

    • 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 an ImmutableSet with the results. This is an eager version of Collections2.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 to Streams.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 to Streams.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 of FluentIterable.filter(Class) and Iterables.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 of FluentIterable.filter(Class) and Iterables.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 of FluentIterable.filter(Class) and Iterables.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 a NavigableMap with Strings as key, return a partial map (similar to NavigableMap.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 a SortedMap with Strings as key, return a partial map (similar to SortedMap.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 a NavigableSet of String, return a set (similar to NavigableSet.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 a SortedSet of String, return a set (similar to SortedSet.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.