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 Summary
Constructors Modifier Constructor Description private
UnmodifiableCollectionUtil()
Private constructor for UnmodifiableCollectionUtil.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> T[]
copyOfArray(T[] array, int length)
Creates a copy of array.static <K,V>
Map<K,V>copyOfMap(Map<? extends K,? extends V> map)
Creates a copy of Map.static <T> Set<T>
singleton(T obj)
Returns an immutable set containing only the specified object.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.static <T> List<T>
unmodifiableList(List<T> collection)
Creates an unmodifiable list based on the provided collection.
-
-
-
Constructor Detail
-
UnmodifiableCollectionUtil
private UnmodifiableCollectionUtil()
Private constructor for UnmodifiableCollectionUtil.
-
-
Method Detail
-
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 oflength
- 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 mapV
- the type of values in the map- Parameters:
map
- map to create a copy of- Returns:
- an immutable copy of the input map
-
-