Package org.infinispan.commons.util
Class Immutables
- java.lang.Object
-
- org.infinispan.commons.util.Immutables
-
- Direct Known Subclasses:
CoreImmutables
public class Immutables extends java.lang.ObjectFactory for generating immutable type wrappers.- Since:
- 4.0
- Author:
- Jason T. Greene, Galder ZamarreƱo, Tristan Tarrant
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceImmutables.Immutablestatic classImmutables.ImmutableIteratorWrapper<E>static classImmutables.ImmutableMapWrapperExternalizerstatic classImmutables.ImmutableSetWrapperExternalizer
-
Constructor Summary
Constructors Constructor Description Immutables()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> java.util.Collection<T>immutableCollectionCopy(java.util.Collection<T> collection)Creates a new immutable copy of the specified Collection.static <T> java.util.Collection<T>immutableCollectionWrap(java.util.Collection<? extends T> collection)Wraps a collection with an immutable collection.static <K,V>
java.util.Map.Entry<K,V>immutableEntry(java.util.Map.Entry<K,V> entry)Wraps aMap.Entry} with an immutableMap.Entry}.static <K,V>
java.util.Map.Entry<K,V>immutableEntry(K key, V value)Wraps a key and value with an immutableMap.Entry}.static <T> ImmutableListCopy<T>immutableListAdd(java.util.List<T> list, int position, T element)static <T> java.util.List<T>immutableListConvert(java.util.Collection<? extends T> source)Converts a Collection to an immutable List by copying it.static <T> java.util.List<T>immutableListCopy(java.util.List<T> list)Creates an immutable copy of the list.static <T> java.util.List<T>immutableListMerge(java.util.List<? extends T> list1, java.util.List<? extends T> list2)Creates a new immutable list containing the union (combined entries) of both lists.static <T> java.util.List<T>immutableListRemove(java.util.List<T> list, int position)static <T> ImmutableListCopy<T>immutableListReplace(java.util.List<T> list, int position, T element)static <T> java.util.List<T>immutableListWrap(T... array)Wraps an array with an immutable list.static <K,V>
java.util.Map<K,V>immutableMapCopy(java.util.Map<K,V> map)Creates an immutable copy of the specified map.static <K,V>
java.util.Map<K,V>immutableMapWrap(java.util.Map<? extends K,? extends V> map)Wraps a map with an immutable map.static <T> java.util.Set<T>immutableSetConvert(java.util.Collection<? extends T> collection)Converts a Collections into an immutable Set by copying it.static <T> java.util.Set<T>immutableSetCopy(java.util.Set<T> set)Creates an immutable copy of the specified set.static <T> java.util.Set<T>immutableSetWrap(java.util.Set<? extends T> set)Wraps a set with an immutable set.static TypedPropertiesimmutableTypedProperties(TypedProperties properties)Creates an immutable copy of the properties.static booleanisImmutable(java.lang.Object o)Whether or not this collection type is immutable
-
-
-
Method Detail
-
isImmutable
public static boolean isImmutable(java.lang.Object o)
Whether or not this collection type is immutable- Parameters:
o- a Collection, Set, List, or Map- Returns:
- true if immutable, false if not
-
immutableListConvert
public static <T> java.util.List<T> immutableListConvert(java.util.Collection<? extends T> source)
Converts a Collection to an immutable List by copying it.- Parameters:
source- the collection to convert- Returns:
- a copied/converted immutable list
-
immutableListCopy
public static <T> java.util.List<T> immutableListCopy(java.util.List<T> list)
Creates an immutable copy of the list.- Parameters:
list- the list to copy- Returns:
- the immutable copy
-
immutableTypedProperties
public static TypedProperties immutableTypedProperties(TypedProperties properties)
Creates an immutable copy of the properties.- Parameters:
properties- the TypedProperties to copy- Returns:
- the immutable copy
-
immutableListWrap
public static <T> java.util.List<T> immutableListWrap(T... array)
Wraps an array with an immutable list. There is no copying involved.- Type Parameters:
T-- Parameters:
array- the array to wrap- Returns:
- a list containing the array
-
immutableListMerge
public static <T> java.util.List<T> immutableListMerge(java.util.List<? extends T> list1, java.util.List<? extends T> list2)Creates a new immutable list containing the union (combined entries) of both lists.- Parameters:
list1- contains the first elements of the new listlist2- contains the successor elements of the new list- Returns:
- a new immutable merged copy of list1 and list2
-
immutableListAdd
public static <T> ImmutableListCopy<T> immutableListAdd(java.util.List<T> list, int position, T element)
-
immutableListReplace
public static <T> ImmutableListCopy<T> immutableListReplace(java.util.List<T> list, int position, T element)
-
immutableListRemove
public static <T> java.util.List<T> immutableListRemove(java.util.List<T> list, int position)
-
immutableSetConvert
public static <T> java.util.Set<T> immutableSetConvert(java.util.Collection<? extends T> collection)
Converts a Collections into an immutable Set by copying it.- Parameters:
collection- the collection to convert/copy- Returns:
- a new immutable set containing the elements in collection
-
immutableSetWrap
public static <T> java.util.Set<T> immutableSetWrap(java.util.Set<? extends T> set)
Wraps a set with an immutable set. There is no copying involved.- Parameters:
set- the set to wrap- Returns:
- an immutable set wrapper that delegates to the original set
-
immutableSetCopy
public static <T> java.util.Set<T> immutableSetCopy(java.util.Set<T> set)
Creates an immutable copy of the specified set.- Parameters:
set- the set to copy from- Returns:
- an immutable set copy
-
immutableMapWrap
public static <K,V> java.util.Map<K,V> immutableMapWrap(java.util.Map<? extends K,? extends V> map)
Wraps a map with an immutable map. There is no copying involved.- Parameters:
map- the map to wrap- Returns:
- an immutable map wrapper that delegates to the original map
-
immutableMapCopy
public static <K,V> java.util.Map<K,V> immutableMapCopy(java.util.Map<K,V> map)
Creates an immutable copy of the specified map.- Parameters:
map- the map to copy from- Returns:
- an immutable map copy
-
immutableCollectionCopy
public static <T> java.util.Collection<T> immutableCollectionCopy(java.util.Collection<T> collection)
Creates a new immutable copy of the specified Collection.- Parameters:
collection- the collection to copy- Returns:
- an immutable copy
-
immutableCollectionWrap
public static <T> java.util.Collection<T> immutableCollectionWrap(java.util.Collection<? extends T> collection)
Wraps a collection with an immutable collection. There is no copying involved.- Parameters:
collection- the collection to wrap- Returns:
- an immutable collection wrapper that delegates to the original collection
-
immutableEntry
public static <K,V> java.util.Map.Entry<K,V> immutableEntry(java.util.Map.Entry<K,V> entry)
Wraps aMap.Entry} with an immutableMap.Entry}. There is no copying involved.- Parameters:
entry- the mapping to wrap.- Returns:
- an immutable
Map.Entry} wrapper that delegates to the original mapping.
-
immutableEntry
public static <K,V> java.util.Map.Entry<K,V> immutableEntry(K key, V value)Wraps a key and value with an immutableMap.Entry}. There is no copying involved.- Parameters:
key- the key to wrap.value- the value to wrap.- Returns:
- an immutable
Map.Entry} wrapper that delegates to the original mapping.
-
-