Class UnmodifiableCollections


  • public final class UnmodifiableCollections
    extends java.lang.Object
    Provides a set of methods that produce unmodifiable copies of collections.
    Since:
    4.0.0
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <K,​V>
      java.util.Map<K,​V>
      buildMap​(java.util.function.Consumer<java.util.Map<K,​V>> handler)
      Build an unmodifiable map.
      static <E> java.util.List<E> copyOf​(java.util.List<E> original)
      Creates an unmodifiable copy of the given List instance.
      static <K,​V>
      java.util.Map<K,​V>
      copyOf​(java.util.Map<K,​V> original)
      Creates an unmodifiable copy of the given Map instance.
      static <E> java.util.Set<E> copyOf​(java.util.Set<E> original)
      Creates an unmodifiable copy of the given Set instance.
      static <K,​V>
      java.util.Map.Entry<K,​V>
      immutableMapEntry​(K key, V value)
      Creates an immutable instance of Map.Entry.
      static <E> java.util.List<E> toList​(E... original)
      Creates an unmodifiable copy of the given array as a list, preserving order.
      static <E> java.util.Set<E> toSet​(E... original)
      Creates an unmodifiable copy of the given array as a set.
      • Methods inherited from class java.lang.Object

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

      • copyOf

        public static <E> java.util.List<E> copyOf​(java.util.List<E> original)
        Creates an unmodifiable copy of the given List instance.
        Type Parameters:
        E - the type of every item in the entry
        Parameters:
        original - the list to be copied
        Returns:
        a unmodifiable copy of the given List instance
        Since:
        4.0.0
      • copyOf

        public static <E> java.util.Set<E> copyOf​(java.util.Set<E> original)
        Creates an unmodifiable copy of the given Set instance.
        Type Parameters:
        E - the type of every item in the entry
        Parameters:
        original - the set to be copied
        Returns:
        a unmodifiable copy of the given Set instance
        Since:
        4.0.0
      • copyOf

        public static <K,​V> java.util.Map<K,​V> copyOf​(java.util.Map<K,​V> original)
        Creates an unmodifiable copy of the given Map instance.
        Type Parameters:
        K - key type of the map
        V - value type of the map
        Parameters:
        original - the map to be copied
        Returns:
        an unmodifiable copy of the given Map instance.
        Since:
        4.1.0
      • toList

        @SafeVarargs
        public static <E> java.util.List<E> toList​(E... original)
        Creates an unmodifiable copy of the given array as a list, preserving order.
        Type Parameters:
        E - the type of every item in the entry
        Parameters:
        original - the array to be copied into a list
        Returns:
        a unmodifiable copy of the given array as a List instance
        Since:
        4.0.0
      • toSet

        @SafeVarargs
        public static <E> java.util.Set<E> toSet​(E... original)
        Creates an unmodifiable copy of the given array as a set.
        Type Parameters:
        E - the type of every item in the entry
        Parameters:
        original - the array to be copied into a set
        Returns:
        a unmodifiable copy of the given array as a Set instance
        Since:
        4.0.0
      • buildMap

        public static <K,​V> java.util.Map<K,​V> buildMap​(java.util.function.Consumer<java.util.Map<K,​V>> handler)
        Build an unmodifiable map.
        Type Parameters:
        K - key type
        V - value type
        Parameters:
        handler - consumer that will populate the map wih keys
        Returns:
        a new unmodifiable map
        Since:
        4.0.0
      • immutableMapEntry

        public static <K,​V> java.util.Map.Entry<K,​V> immutableMapEntry​(K key,
                                                                                   V value)
        Creates an immutable instance of Map.Entry.
        Type Parameters:
        K - the key's type
        V - the value's type
        Parameters:
        key - the key in the entry
        value - the value in the entry
        Returns:
        the new map entry
        Since:
        4.0.0