Class UnmodifiableCollectionUtil

java.lang.Object
com.puppycrawl.tools.checkstyle.utils.UnmodifiableCollectionUtil

public final class UnmodifiableCollectionUtil extends Object
Note: it simply wraps the existing JDK methods to provide a workaround for Pitest survival on mutation for removal of immutable wrapping, see #13127 for more details.
  • Constructor Details

  • Method Details

    • unmodifiableList

      public static <T> List<T> unmodifiableList(List<T> collection)
      Creates an unmodifiable list based on the provided collection.
      Type Parameters:
      T - the type of elements in the set
      Parameters:
      collection - the collection to create an unmodifiable list from
      Returns:
      an unmodifiable list containing the elements from the provided collection
    • unmodifiableList

      public static <S, T> List<T> unmodifiableList(Collection<S> items, Class<T> elementType)
      Returns an unmodifiable view of a List containing elements of a specific type.
      Type Parameters:
      S - The generic type of elements in the input Collection.
      T - The type of elements in the resulting unmodifiable List.
      Parameters:
      items - The List of items to make unmodifiable.
      elementType - The Class object representing the type of elements in the list.
      Returns:
      An unmodifiable List containing elements of the specified type.
    • copyOfArray

      public static <T> T[] copyOfArray(T[] array, int length)
      Creates a copy of array.
      Type Parameters:
      T - The type of array
      Parameters:
      array - Array to create a copy of
      length - length of array
      Returns:
      copy of array
    • copyOfMap

      public static <K, V> Map<K,V> copyOfMap(Map<? extends K,? extends V> map)
      Creates a copy of Map.
      Type Parameters:
      K - the type of keys in the map
      V - the type of values in the map
      Parameters:
      map - map to create a copy of
      Returns:
      an immutable copy of the input map
    • singleton

      public static <T> Set<T> singleton(T obj)
      Returns an immutable set containing only the specified object.
      Type Parameters:
      T - the type of object
      Parameters:
      obj - the type of object in the set
      Returns:
      immutable set