T - the type the returned collection will holdpublic class ImmutableCollections<T> extends Object
This class is used to achieve deep immutability for value classes by ensuring collections in those classes contain immutable elements in addition to being immutable themselves.
| Modifier and Type | Method and Description |
|---|---|
List<T> |
newList(Collection<T> toCopy)
Create a new unmodifiable List containing immutable copies of the given elements.
|
static <T> List<T> |
newListOfImmutableType(Collection<T> toCopy)
Creates an unmodifiable copy of a Collection that already contains immutable types.
|
static <T,S> Map<T,S> |
newMapOfImmutableTypes(Map<T,S> toCopy) |
static <T,S> Map<T,S> |
newMapOfImmutableTypes(Map<T,S> toCopy,
java.util.function.Supplier<Map<T,S>> mapSupplier)
Creates an unmodifiable copy of a Map that already contains immutable types.
|
static <T> ImmutableCollections<T> |
with(java.util.function.Function<T,T> immutableInstanceFactory)
Creates an instance that maps elements to an immutable form using the given mapping function.
|
public static <T> ImmutableCollections<T> with(java.util.function.Function<T,T> immutableInstanceFactory)
The mapping function may return the element unmapped if it is already considered immutable.
immutableInstanceFactory - a function for mapping an element to an immutable copy of that elementpublic List<T> newList(Collection<T> toCopy)
toCopy - the Collection containing the elements to be copiedpublic static <T> List<T> newListOfImmutableType(Collection<T> toCopy)
toCopy - the Collection to copypublic static <T,S> Map<T,S> newMapOfImmutableTypes(Map<T,S> toCopy, java.util.function.Supplier<Map<T,S>> mapSupplier)
toCopy - the collection to copymapSupplier - a supplier that supplies the desired type of MapCopyright © 2022. All rights reserved.