Class SubjectUtils


  • final class SubjectUtils
    extends java.lang.Object
    Utility methods used in Subject implementors.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private SubjectUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) static <T> java.util.List<T> accumulate​(T first, T second, T... rest)  
      private static java.util.List<java.lang.String> addTypeInfoToEveryItem​(java.lang.Iterable<?> items)  
      (package private) static <T> java.lang.Iterable<T> annotateEmptyStrings​(java.lang.Iterable<T> items)
      Returns an iterable with all empty strings replaced by a non-empty human understandable indicator for an empty string.
      (package private) static <E> com.google.common.collect.ImmutableList<E> append​(com.google.common.collect.ImmutableList<? extends E> list, E object)  
      (package private) static <E> com.google.common.collect.ImmutableList<E> append​(E[] array, E object)  
      (package private) static <E> com.google.common.collect.ImmutableList<E> concat​(java.lang.Iterable<? extends E>... inputs)  
      (package private) static java.lang.String countDuplicates​(java.lang.Iterable<?> items)  
      (package private) static java.lang.String countDuplicatesAndAddTypeInfo​(java.lang.Iterable<?> itemsIterable)
      Makes a String representation of items with collapsed duplicates and additional class info.
      (package private) static SubjectUtils.DuplicateGroupedAndTyped countDuplicatesAndMaybeAddTypeInfoReturnObject​(java.lang.Iterable<?> itemsIterable, boolean addTypeInfo)
      Similar to countDuplicatesAndAddTypeInfo(java.lang.Iterable<?>) and countDuplicates(java.lang.Iterable<?>) but (a) only adds type info if requested and (b) returns a richer object containing the data.
      private static <T> SubjectUtils.NonHashingMultiset<T> countDuplicatesToMultiset​(java.lang.Iterable<T> items)  
      (package private) static <T> int countOf​(T t, java.lang.Iterable<T> items)  
      (package private) static java.lang.String entryString​(com.google.common.collect.Multiset.Entry<?> entry)  
      private static com.google.common.base.Optional<java.lang.String> getHomogeneousTypeName​(java.lang.Iterable<?> items)
      Returns the name of the single type of all given items or Optional.absent() if no such type exists.
      (package private) static boolean hasMatchingToStringPair​(java.lang.Iterable<?> items1, java.lang.Iterable<?> items2)
      Returns true if there is a pair of an item from items1 and one in items2 that has the same toString() value without being equal.
      (package private) static <T> java.util.Collection<T> iterableToCollection​(java.lang.Iterable<T> iterable)  
      (package private) static <T> java.util.List<T> iterableToList​(java.lang.Iterable<T> iterable)  
      (package private) static java.lang.String iterableToStringWithTypeInfo​(java.lang.Iterable<?> itemsIterable)
      Makes a String representation of items with additional class info.
      (package private) static java.lang.String objectToTypeName​(java.lang.Object item)  
      (package private) static java.util.List<java.lang.Object> retainMatchingToString​(java.lang.Iterable<?> items, java.lang.Iterable<?> itemsToCheck)
      Returns a new collection containing all elements in items for which there exists at least one element in itemsToCheck that has the same toString() value without being equal.
      (package private) static <E> com.google.common.collect.ImmutableList<E> sandwich​(E first, E[] array, E last)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • HUMAN_UNDERSTANDABLE_EMPTY_STRING

        static final java.lang.String HUMAN_UNDERSTANDABLE_EMPTY_STRING
        See Also:
        Constant Field Values
    • Constructor Detail

      • SubjectUtils

        private SubjectUtils()
    • Method Detail

      • accumulate

        static <T> java.util.List<T> accumulate​(T first,
                                                T second,
                                                T... rest)
      • countOf

        static <T> int countOf​(T t,
                               java.lang.Iterable<T> items)
      • countDuplicates

        static java.lang.String countDuplicates​(java.lang.Iterable<?> items)
      • entryString

        static java.lang.String entryString​(com.google.common.collect.Multiset.Entry<?> entry)
      • countDuplicatesAndAddTypeInfo

        static java.lang.String countDuplicatesAndAddTypeInfo​(java.lang.Iterable<?> itemsIterable)
        Makes a String representation of items with collapsed duplicates and additional class info.

        Example: countDuplicatesAndAddTypeInfo([1, 2, 2, 3]) == "[1, 2 [3 copies]] (java.lang.Integer)" and countDuplicatesAndAddTypeInfo([1, 2L]) == "[1 (java.lang.Integer), 2 (java.lang.Long)]".

      • iterableToStringWithTypeInfo

        static java.lang.String iterableToStringWithTypeInfo​(java.lang.Iterable<?> itemsIterable)
        Makes a String representation of items with additional class info.

        Example: iterableToStringWithTypeInfo([1, 2]) == "[1, 2] (java.lang.Integer)" and iterableToStringWithTypeInfo([1, 2L]) == "[1 (java.lang.Integer), 2 (java.lang.Long)]".

      • retainMatchingToString

        static java.util.List<java.lang.Object> retainMatchingToString​(java.lang.Iterable<?> items,
                                                                       java.lang.Iterable<?> itemsToCheck)
        Returns a new collection containing all elements in items for which there exists at least one element in itemsToCheck that has the same toString() value without being equal.

        Example: retainMatchingToString([1L, 2L, 2L], [2, 3]) == [2L, 2L]

      • hasMatchingToStringPair

        static boolean hasMatchingToStringPair​(java.lang.Iterable<?> items1,
                                               java.lang.Iterable<?> items2)
        Returns true if there is a pair of an item from items1 and one in items2 that has the same toString() value without being equal.

        Example: hasMatchingToStringPair([1L, 2L], [1]) == true

      • objectToTypeName

        static java.lang.String objectToTypeName​(java.lang.Object item)
      • getHomogeneousTypeName

        private static com.google.common.base.Optional<java.lang.String> getHomogeneousTypeName​(java.lang.Iterable<?> items)
        Returns the name of the single type of all given items or Optional.absent() if no such type exists.
      • addTypeInfoToEveryItem

        private static java.util.List<java.lang.String> addTypeInfoToEveryItem​(java.lang.Iterable<?> items)
      • iterableToCollection

        static <T> java.util.Collection<T> iterableToCollection​(java.lang.Iterable<T> iterable)
      • iterableToList

        static <T> java.util.List<T> iterableToList​(java.lang.Iterable<T> iterable)
      • annotateEmptyStrings

        static <T> java.lang.Iterable<T> annotateEmptyStrings​(java.lang.Iterable<T> items)
        Returns an iterable with all empty strings replaced by a non-empty human understandable indicator for an empty string.

        Returns the given iterable if it contains no empty strings.

      • concat

        @SafeVarargs
        static <E> com.google.common.collect.ImmutableList<E> concat​(java.lang.Iterable<? extends E>... inputs)
      • append

        static <E> com.google.common.collect.ImmutableList<E> append​(E[] array,
                                                                     E object)
      • append

        static <E> com.google.common.collect.ImmutableList<E> append​(com.google.common.collect.ImmutableList<? extends E> list,
                                                                     E object)
      • sandwich

        static <E> com.google.common.collect.ImmutableList<E> sandwich​(E first,
                                                                       E[] array,
                                                                       E last)