Class CollectionsHelper


  • public abstract class CollectionsHelper
    extends Object
    A set of static methods similar to Java9's List.of(), Set.of() and Map.of().
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> List<T> listOf()
      Returns an immutable list containing zero elements.
      static <T> List<T> listOf​(T... elts)
      Returns an unmodifiable list containing the given elements.
      static <K,​V>
      Map.Entry<K,​V>
      mapEntry​(K k, V v)
      Returns an Map.Entry containing the given key and value.
      static <K,​V>
      Map<K,​V>
      mapOf()
      Returns an immutable map containing zero mappings.
      static <K,​V>
      Map<K,​V>
      mapOf​(K k1, V v1)
      Create an unmodifiable map containing a single mappings.
      static <K,​V>
      Map<K,​V>
      mapOf​(K k1, V v1, K k2, V v2)
      Create an unmodifiable map containing 2 mappings.
      static <K,​V>
      Map<K,​V>
      mapOf​(K k1, V v1, K k2, V v2, K k3, V v3)
      Create an unmodifiable map containing 3 mappings.
      static <K,​V>
      Map<K,​V>
      mapOf​(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4)
      Create an unmodifiable map containing 4 mappings.
      static <K,​V>
      Map<K,​V>
      mapOf​(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5)
      Create an unmodifiable map containing 5 mappings.
      static <K,​V>
      Map<K,​V>
      mapOf​(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6)
      Create an unmodifiable map containing 5 mappings.
      static <K,​V>
      Map<K,​V>
      mapOf​(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7)
      Create an unmodifiable map containing 5 mappings.
      static <T> Set<T> setOf()
      Returns an immutable set containing zero elements.
      static <T> Set<T> setOf​(T... elts)
      Create an unmodifiable set containing the given elements.
    • Method Detail

      • listOf

        public static <T> List<T> listOf()
        Returns an immutable list containing zero elements.
        Type Parameters:
        T - the List's element type
        Returns:
        an empty List
      • listOf

        @SafeVarargs
        public static <T> List<T> listOf​(T... elts)
        Returns an unmodifiable list containing the given elements.
        Type Parameters:
        T - the List's element type
        Parameters:
        elts - the elements
        Returns:
        a List containing the specified elements
      • setOf

        public static <T> Set<T> setOf()
        Returns an immutable set containing zero elements.
        Type Parameters:
        T - the Set's element type
        Returns:
        an empty Set
      • setOf

        @SafeVarargs
        public static <T> Set<T> setOf​(T... elts)
        Create an unmodifiable set containing the given elements.
        Type Parameters:
        T - the Set's element type
        Parameters:
        elts - elements to add
        Returns:
        a Set containing the specified elements
      • mapEntry

        public static <K,​V> Map.Entry<K,​V> mapEntry​(K k,
                                                                V v)
        Returns an Map.Entry containing the given key and value.
        Type Parameters:
        K - the key's type
        V - the value's type
        Parameters:
        k - key
        v - value
        Returns:
        an Entry containing the specified key and value
      • mapOf

        public static <K,​V> Map<K,​V> mapOf()
        Returns an immutable map containing zero mappings.
        Type Parameters:
        K - the Map's key type
        V - the Map's value type
        Returns:
        an empty Map
      • mapOf

        public static <K,​V> Map<K,​V> mapOf​(K k1,
                                                       V v1)
        Create an unmodifiable map containing a single mappings.
        Type Parameters:
        K - the Map's key type
        V - the Map's value type
        Parameters:
        k1 - key
        v1 - value
        Returns:
        a Map containing the specified mappings
      • mapOf

        public static <K,​V> Map<K,​V> mapOf​(K k1,
                                                       V v1,
                                                       K k2,
                                                       V v2)
        Create an unmodifiable map containing 2 mappings.
        Type Parameters:
        K - the Map's key type
        V - the Map's value type
        Parameters:
        k1 - first key
        v1 - first value
        k2 - second key
        v2 - second value
        Returns:
        a Map containing the specified mappings
      • mapOf

        public static <K,​V> Map<K,​V> mapOf​(K k1,
                                                       V v1,
                                                       K k2,
                                                       V v2,
                                                       K k3,
                                                       V v3)
        Create an unmodifiable map containing 3 mappings.
        Type Parameters:
        K - the Map's key type
        V - the Map's value type
        Parameters:
        k1 - first key
        v1 - first value
        k2 - second key
        v2 - second value
        k3 - third key
        v3 - third value
        Returns:
        a Map containing the specified mappings
      • mapOf

        public static <K,​V> Map<K,​V> mapOf​(K k1,
                                                       V v1,
                                                       K k2,
                                                       V v2,
                                                       K k3,
                                                       V v3,
                                                       K k4,
                                                       V v4)
        Create an unmodifiable map containing 4 mappings.
        Type Parameters:
        K - the Map's key type
        V - the Map's value type
        Parameters:
        k1 - first key
        v1 - first value
        k2 - second key
        v2 - second value
        k3 - third key
        v3 - third value
        k4 - fourth key
        v4 - fourth value
        Returns:
        a Map containing the specified mappings
      • mapOf

        public static <K,​V> Map<K,​V> mapOf​(K k1,
                                                       V v1,
                                                       K k2,
                                                       V v2,
                                                       K k3,
                                                       V v3,
                                                       K k4,
                                                       V v4,
                                                       K k5,
                                                       V v5)
        Create an unmodifiable map containing 5 mappings.
        Type Parameters:
        K - the Map's key type
        V - the Map's value type
        Parameters:
        k1 - first key
        v1 - first value
        k2 - second key
        v2 - second value
        k3 - third key
        v3 - third value
        k4 - fourth key
        v4 - fourth value
        k5 - fifth key
        v5 - fifth value
        Returns:
        a Map containing the specified mappings
      • mapOf

        public static <K,​V> Map<K,​V> mapOf​(K k1,
                                                       V v1,
                                                       K k2,
                                                       V v2,
                                                       K k3,
                                                       V v3,
                                                       K k4,
                                                       V v4,
                                                       K k5,
                                                       V v5,
                                                       K k6,
                                                       V v6)
        Create an unmodifiable map containing 5 mappings.
        Type Parameters:
        K - the Map's key type
        V - the Map's value type
        Parameters:
        k1 - first key
        v1 - first value
        k2 - second key
        v2 - second value
        k3 - third key
        v3 - third value
        k4 - fourth key
        v4 - fourth value
        k5 - fifth key
        v5 - fifth value
        k6 - sixth key
        v6 - sixth value
        Returns:
        a Map containing the specified mappings
      • mapOf

        public static <K,​V> Map<K,​V> mapOf​(K k1,
                                                       V v1,
                                                       K k2,
                                                       V v2,
                                                       K k3,
                                                       V v3,
                                                       K k4,
                                                       V v4,
                                                       K k5,
                                                       V v5,
                                                       K k6,
                                                       V v6,
                                                       K k7,
                                                       V v7)
        Create an unmodifiable map containing 5 mappings.
        Type Parameters:
        K - the Map's key type
        V - the Map's value type
        Parameters:
        k1 - first key
        v1 - first value
        k2 - second key
        v2 - second value
        k3 - third key
        v3 - third value
        k4 - fourth key
        v4 - fourth value
        k5 - fifth key
        v5 - fifth value
        k6 - sixth key
        v6 - sixth value
        k7 - seventh key
        v7 - seventh value
        Returns:
        a Map containing the specified mappings