Class UnmodifiableCollectionUtil
- java.lang.Object
-
- com.puppycrawl.tools.checkstyle.utils.UnmodifiableCollectionUtil
-
public final class UnmodifiableCollectionUtil extends java.lang.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>
java.util.Map<K,V>copyOfMap(java.util.Map<? extends K,? extends V> map)
Creates a copy of Map.static <T> java.util.Set<T>
singleton(T obj)
Returns an immutable set containing only the specified object.static <S,T>
java.util.List<T>unmodifiableList(java.util.Collection<S> items, java.lang.Class<T> elementType)
Returns an unmodifiable view of a List containing elements of a specific type.static <T> java.util.List<T>
unmodifiableList(java.util.List<T> collection)
Creates an unmodifiable list based on the provided collection.static <T> java.util.Set<T>
unmodifiableSet(java.util.Set<T> collection)
Creates an unmodifiable set based on the provided collection.
-
-
-
Constructor Detail
-
UnmodifiableCollectionUtil
private UnmodifiableCollectionUtil()
Private constructor for UnmodifiableCollectionUtil.
-
-
Method Detail
-
unmodifiableSet
public static <T> java.util.Set<T> unmodifiableSet(java.util.Set<T> collection)
Creates an unmodifiable set based on the provided collection.- Type Parameters:
T
- the type of elements in the set- Parameters:
collection
- the collection to create an unmodifiable set from- Returns:
- an unmodifiable set containing the elements from the provided collection
-
unmodifiableList
public static <T> java.util.List<T> unmodifiableList(java.util.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> java.util.List<T> unmodifiableList(java.util.Collection<S> items, java.lang.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> java.util.Map<K,V> copyOfMap(java.util.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
-
singleton
public static <T> java.util.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
-
-