Class Generics2


  • public final class Generics2
    extends Object
    helper class to handle creation/transformation/filtering of collections. This class is used to wrap guava. Future releases of bootstrap won't depend on guava anymore.
    Author:
    miha
    • Method Detail

      • newArrayList

        public static <T> ArrayList<T> newArrayList​(T... elements)
        creates a new ArrayList from given array of elements.
        Type Parameters:
        T - the type of all elements inside the list
        Parameters:
        elements - the elements to add to new ArrayList
        Returns:
        new ArrayList that contains all given elements
        Throws:
        IllegalArgumentException - if given array of elements is null
      • newArrayList

        public static <T> ArrayList<T> newArrayList​(Iterator<? extends T> elements)
        Creates a mutable ArrayList instance containing the given elements.
        Parameters:
        elements - the elements that the list should contain, in order
        Returns:
        a new ArrayList containing those elements
      • newArrayList

        public static <T> ArrayList<T> newArrayList​(Iterable<? extends T> elements)
        creates a new ArrayList from given array of elements.
        Type Parameters:
        T - the type of all elements inside the list
        Parameters:
        elements - the elements to add to new ArrayList
        Returns:
        new ArrayList that contains all given elements
        Throws:
        IllegalArgumentException - if given array of elements is null
      • newLinkedHashSet

        public static <T> Set<T> newLinkedHashSet​(Iterable<? extends T> elements)
        creates a new LinkedHashSet from given array of elements.
        Type Parameters:
        T - the type of all elements inside the set
        Parameters:
        elements - the elements to add to new LinkedHashSet
        Returns:
        new LinkedHashSet that contains all given elements
        Throws:
        IllegalArgumentException - if given array of elements is null
      • newHashSet

        public static <T> Set<T> newHashSet​(T... elements)
        creates a new HashSet from given array of elements.
        Type Parameters:
        T - the type of all elements inside the set
        Parameters:
        elements - the elements to add to new HashSet
        Returns:
        new HashSet that contains all given elements
        Throws:
        IllegalArgumentException - if given array of elements is null
      • join

        public static String join​(Iterable<?> elements,
                                  char separator)
        joins all given elements with a special separator
        Parameters:
        elements - elements to join
        separator - separator to use
        Returns:
        elements as string
      • transform

        public static <T> List<T> transform​(T[] elements)
        transform an array of elements into a list of elements
        Type Parameters:
        T - the type of elements
        Parameters:
        elements - the elements to add to list
        Returns:
        new list of elements
      • transform

        public static <P,​R> List<R> transform​(List<P> elements,
                                                    Function<P,​R> transformer)
        Returns a list that applies transformer to each element of elements
      • transform

        public static <P,​R> Set<R> transform​(Set<P> elements,
                                                   Function<P,​R> transformer)
        Returns a list that applies transformer to each element of elements
      • transform

        public static <P,​R> List<R> transform​(P[] elements,
                                                    Function<P,​R> transformer)
        Returns a list that applies transformer to each element of elements
      • filter

        public static <T> List<T> filter​(Iterable<T> unfiltered,
                                         Predicate<T> filter)
        Returns the elements of unfiltered that satisfy given filter. The resulting iterable's iterator does not support remove().
      • split

        public static List<String> split​(CharSequence value,
                                         String separator)
        splits a CharSequence by given separator.
        Parameters:
        value - the value to split
        separator - the separator to use to split value
        Returns:
        list of values