Class Collections3

    • 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 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​(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.

      • 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.