saker.build Documentation TaskDoc JavaDoc Packages
public class ImmutableUtils
Utility class providing access to various immutability related functionality.

This class provides functions for creating immutable collections. Immutable collections hold their own backing collections, and will create a copy of their argument, so unless otherwise noted in the creating function, modifying the source collection/array will have no effect on the returned collections. All methods that have Immutable in their name will create immutable collections, and create a copy of the objects passed to it unless otherwise noted.

If makeImmutable functions are called with null argument, null will be returned instead of empty immutable collections. (Unless otherwise noted in the documentation of the method.)

The class provides functions for creating unmodifiable view collections. That is, a wrapper collection is returned for an argument that prevents modifications to the underlying collection. Usually, any modifications made to the underlying collection through the passed argument will be visible through the unmodifiable view collection as well. Methods that begin with unmodifiable in their name will create such unmodifiable views.

If unmodifiable methods are called with null argument, null will be returned, unless otherwise noted.

This class provides functions for creating singleton collections. Singleton collections are immutable. Methods that begin with singleton in their name will create such objects.

This class provides functions for creating empty collections. Empty collections are immutable. Methods that begin with empty in their name will create such objects.

Generally, functions that return a specific interface will return an object that only implements that declared interface. E.g. a function that returns SortedSet will not return an object that implements NavigableSet. This is not a strict requirement, and users should not rely on this fact. (List may implement RandomAccess as well.)

All returned stateless objects in this class are Externalizable, unless otherwise noted in the corresponding method documentation.

In general it is useful to use the functions in this class instead of the ones provided by the Java standard library, as the fact that the returned objects are Externalizable, can significantly improve performance in some cases.

Creating immutable collections for sorted collections (sets and maps) can improve performance, as they are usually backed by a random access array that takes up less space than a full TreeMap or such, and can provide more efficient method implementations in some cases.

Methods
public static <E> List<E>
Creates an unmodifiable list view to the argument array.
public static <K, V> NavigableMap<K, V>
emptyNavigableMap(Comparator<super K> comparator)
Gets an immutable empty navigable map that has the argument comparator.
public static <E> NavigableSet<E>
emptyNavigableSet(Comparator<super E> comparator)
Gets an immutable empty navigable set that has the argument comparator.
public static <K, V> SortedMap<K, V>
emptySortedMap(Comparator<super K> comparator)
Gets an immutable empty sorted map that has the argument comparator.
public static <E> SortedSet<E>
emptySortedSet(Comparator<super E> comparator)
Gets an immutable empty sorted set that has the argument comparator.
public static <K, V> Map<K, V>
makeImmutableHashMap(Map<extends K, ? extends V> map)
Creates a new immutable hash map based on the argument map.
public static <E> Set<E>
makeImmutableHashSet(Iterable<extends E> objects)
Creates an immutable hash set consisting of the argument objects.
public static <E> Set<E>
makeImmutableHashSet(Collection<extends E> objects)
Creates an immutable hash set consisting of the argument objects.
public static <E> Set<E>
Creates an immutable hash set consisting of the argument objects.
public static <K, V> Map<K, V>
makeImmutableIdentityHashMap(Map<extends K, ? extends V> map)
Creates a new immutable identity hash map based on the argument map.
public static <E> Set<E>
makeImmutableIdentityHashSet(Iterable<extends E> objects)
Creates an immutable identity hash set consisting of the argument objects.
public static <E> Set<E>
Creates an immutable identity hash set consisting of the argument objects.
public static <E> Set<E>
Creates an immutable identity hash set consisting of the argument objects.
public static <K, V> Entry<K, V>
Creates a new immutable map entry for the given key-value pair.
public static <K, V> Map<K, V>
makeImmutableLinkedHashMap(Map<extends K, ? extends V> map)
Creates a new immutable linked hash map based on the argument map.
public static <E> Set<E>
makeImmutableLinkedHashSet(Iterable<extends E> objects)
Creates an immutable linked hash set consisting of the argument objects.
public static <E> Set<E>
makeImmutableLinkedHashSet(Collection<extends E> objects)
Creates an immutable linked hash set consisting of the argument objects.
public static <E> Set<E>
Creates an immutable linked hash set consisting of the argument objects.
public static <E> List<E>
makeImmutableList(Iterable<extends E> objects)
Creates an immutable list consisting of the argument objects.
public static <E> List<E>
makeImmutableList(Collection<extends E> objects)
Creates an immutable list consisting of the argument objects.
public static <E> List<E>
makeImmutableList(E[] objects)
Creates an immutable list consisting of the argument objects.
public static <K, V> Entry<K, V>
makeImmutableMapEntry(K key, V value)
Creates a new immutable map entry for the given key-value pair.
public static <K, V> Entry<K, V>
makeImmutableMapEntry(Entry<extends K, ? extends V> entry)
Creates an immutable map entry for the given map entry.
public static <K, V> NavigableMap<K, V>
makeImmutableNavigableMap(List<extends K> keys, List<extends V> values)
Creates a new immutable navigable map based on the argument key-value lists.
public static <K, V> NavigableMap<K, V>
makeImmutableNavigableMap(List<extends K> keys, List<extends V> values, Comparator<super K> comparator)
Creates a new immutable navigable map based on the argument key-value lists and ordered by the specified comparator.
public static <K, V> NavigableMap<K, V>
makeImmutableNavigableMap(Map<extends K, ? extends V> map)
Creates a new immutable navigable map for the argument map.
public static <K, V> NavigableMap<K, V>
makeImmutableNavigableMap(Map<extends K, ? extends V> map, Comparator<super K> comparator)
Creates a new immutable navigable map for the argument map with the specified order.
public static <K, V> NavigableMap<K, V>
Creates a new immutable navigable map for the argument map.
public static <K, V> NavigableMap<K, V>
makeImmutableNavigableMap(SortedMap<K, ? extends V> map)
Creates a new immutable navigable map for the argument map.
public static <K, V> NavigableMap<K, V>
makeImmutableNavigableMap(K[] keys, V[] values)
Creates a new immutable navigable map based on the argument key-value arrays.
public static <K, V> NavigableMap<K, V>
makeImmutableNavigableMap(K[] keys, V[] values, Comparator<super K> comparator)
Creates a new immutable navigable map based on the argument key-value arrays and ordered by the specified comparator.
public static <E> NavigableSet<E>
makeImmutableNavigableSet(Collection<extends E> objects)
Creates a new immutable navigable set for the argument objects.
public static <E> NavigableSet<E>
makeImmutableNavigableSet(Collection<extends E> objects, Comparator<super E> comparator)
Creates a new immutable navigable set for the argument objects and the the given comparator.
public static <E> NavigableSet<E>
Creates a new immutable navigable set for the argument objects.
public static <E> NavigableSet<E>
Creates a new immutable navigable set for the argument objects.
public static <E> NavigableSet<E>
makeImmutableNavigableSet(E[] objects, Comparator<super E> comparator)
Creates a new immutable navigable set for the argument objects and the the given comparator.
public static <E> Enumeration<E>
Creates an enumeration that enumerates only a single object.
public static <K, V> Map<K, V>
singletonIdentityHashMap(K key, V value)
Creates an immutable map with a single entry.
public static <E> Set<E>
Creates an immutable set with a single element.
public static <E> Iterator<E>
Creates an iterator that iterates over a single object.
public static <E> List<E>
singletonList(E element)
Creates an immutable list with a single element.
public static <K, V> Map<K, V>
singletonMap(K key, V value)
Creates an immutable map with a single entry.
public static <K, V> NavigableMap<K, V>
singletonNavigableMap(K key, V value)
Creates an immutable navigable map with a single entry.
public static <K, V> NavigableMap<K, V>
singletonNavigableMap(K key, V value, Comparator<super K> comparator)
Creates an immutable navigable map with a single entry and comparator.
public static <E> NavigableSet<E>
Creates an immutable navigable set with a single element.
public static <E> NavigableSet<E>
singletonNavigableSet(E element, Comparator<super E> comparator)
Creates an immutable navigable set with a single element and comparator.
public static <E> Set<E>
singletonSet(E element)
Creates an immutable set with a single element.
public static <K, V> SortedMap<K, V>
singletonSortedMap(K key, V value)
Creates an immutable sorted map with a single entry.
public static <K, V> SortedMap<K, V>
singletonSortedMap(K key, V value, Comparator<super K> comparator)
Creates an immutable sorted map with a single entry and comparator.
public static <E> SortedSet<E>
Creates an immutable sorted set with a single element.
public static <E> SortedSet<E>
singletonSortedSet(E element, Comparator<super E> comparator)
Creates an immutable sorted set with a single element and comparator.
public static <E> List<E>
Creates an unmodifiable list view to the argument array.
public static <E> List<E>
unmodifiableArrayList(E[] items, int start, int end)
Creates an unmodifiable list view to the argument array in the given range.
public static <E> Collection<E>
unmodifiableCollection(Collection<extends E> collection)
Gets an unmodifiable view to the argument collection.
public static <E> Iterator<E>
unmodifiableIterator(Iterator<extends E> it)
Wraps the argument iterator into an unmodifiable iterator.
public static <E> List<E>
unmodifiableList(List<extends E> list)
Gets an unmodifiable view to the argument list.
public static <E> ListIterator<E>
Wraps the argument list iterator into an unmodifiable list iterator.
public static <K, V> Map<K, V>
unmodifiableMap(Map<extends K, ? extends V> map)
Gets an unmodifiable view to the argument map.
public static <K, V> Entry<K, V>
unmodifiableMapEntry(Entry<extends K, ? extends V> entry)
Gets an unmodifiable view to the argument map entry.
public static <K, V> Iterator<Entry<K, V>>
unmodifiableMapEntryIterator(Iterator<extends Entry<extends K, ? extends V>> it)
Wraps the argument map entry iterator into an unmodifiable iterator.
public static <K, V> NavigableMap<K, V>
unmodifiableNavigableMap(List<K> keys, List<V> values)
Creates a new unmodifiable navigable map that is backed by the argument key and value lists.
public static <K, V> NavigableMap<K, V>
unmodifiableNavigableMap(List<K> keys, List<V> values, Comparator<super K> comparator)
Creates a new unmodifiable navigable map that is backed by the argument key and value lists.
public static <K, V> NavigableMap<K, V>
Gets an unmodifiable view to the argument navigable map.
public static <K, V> NavigableMap<K, V>
unmodifiableNavigableMap(K[] keys, V[] values)
Creates a new unmodifiable navigable map that is backed by the argument key and value arrays.
public static <K, V> NavigableMap<K, V>
unmodifiableNavigableMap(K[] keys, V[] values, Comparator<super K> comparator)
Creates a new unmodifiable navigable map that is backed by the argument key and value arrays.
public static <E> NavigableSet<E>
unmodifiableNavigableSet(List<extends E> elements)
Creates a new navigable set that is backed by the argument list of elements.
public static <E> NavigableSet<E>
unmodifiableNavigableSet(List<extends E> elements, Comparator<super E> comparator)
Creates a new navigable set that is backed by the argument list of elements.
public static <E> NavigableSet<E>
Gets an unmodifiable view to the argument navigable set.
public static <E> NavigableSet<E>
Creates a new navigable set that is backed by the argument array of elements.
public static <E> NavigableSet<E>
unmodifiableNavigableSet(E[] elements, int start, int end)
Creates a new navigable set that is backed by the elements in the argument array region.
public static <E> NavigableSet<E>
unmodifiableNavigableSet(E[] elements, int start, int end, Comparator<super E> comparator)
Creates a new navigable set that is backed by the elements in the argument array region.
public static <E> NavigableSet<E>
unmodifiableNavigableSet(E[] elements, Comparator<super E> comparator)
Creates a new navigable set that is backed by the argument array of elements.
public static List<?>
Creates an unmodifiable array list view to the argument array.
public static List<?>
unmodifiableReflectionArrayList(Object array, int offset, int length)
Creates an unmodifiable array list view to the argument array in the specified range.
public static <E> Set<E>
unmodifiableSet(Set<extends E> set)
Gets an unmodifiable view to the argument set.
public static <K, V> SortedMap<K, V>
unmodifiableSortedMap(SortedMap<K, ? extends V> map)
Gets an unmodifiable view to the argument sorted map.
public static <E> SortedSet<E>
Gets an unmodifiable view to the argument sorted set.
public static <E> List<E> asUnmodifiableArrayList(E... items)
Creates an unmodifiable list view to the argument array.

This method works similarly to unmodifiableArrayList(E[]), but is vararg and differently named for convenience.

The method is named with similarity to Arrays.asList(T...), in order to explicitly differentiate this method from the other unmodifiable methods, as this uses a vararg parameter. Otherwise it could easily cause confusion when mistakenly invoked with various types of parameters, and result in some unexpected compilation errors which are avoidable this way.

EThe element type.
itemsThe array of elements.
The unmodifiable view, or null if the argument is null.
public static <K, V> NavigableMap<K, V> emptyNavigableMap(Comparator<super K> comparator)
Gets an immutable empty navigable map that has the argument comparator.

The SortedMap.comparator() method will return the argument comparator.

KThe key type.
VThe value type.
comparatorThe comparator.
The empty navigable map.
public static <E> NavigableSet<E> emptyNavigableSet(Comparator<super E> comparator)
Gets an immutable empty navigable set that has the argument comparator.

The SortedSet.comparator() method will return the argument comparator.

EThe element type.
comparatorThe comparator.
The empty navigable set.
public static <K, V> SortedMap<K, V> emptySortedMap(Comparator<super K> comparator)
Gets an immutable empty sorted map that has the argument comparator.

The SortedMap.comparator() method will return the argument comparator.

KThe key type.
VThe value type.
comparatorThe comparator.
The empty sorted map.
public static <E> SortedSet<E> emptySortedSet(Comparator<super E> comparator)
Gets an immutable empty sorted set that has the argument comparator.

The SortedSet.comparator() method will return the argument comparator.

EThe element type.
comparatorThe comparator.
The empty sorted set.
public static <K, V> Map<K, V> makeImmutableHashMap(Map<extends K, ? extends V> map)
Creates a new immutable hash map based on the argument map.

The keys will be compared by equality. (See Objects.equals(Object, Object) )

KThe key type.
VThe value type.
mapThe map.
An immutable hash map based on the entries, or null if the argument is null.
public static <E> Set<E> makeImmutableHashSet(Iterable<extends E> objects)
Creates an immutable hash set consisting of the argument objects.

The elements will be compared by equality.

EThe element type.
objectsThe element objects.
An immutable hash set or null if the argument is null.
public static <E> Set<E> makeImmutableHashSet(Collection<extends E> objects)
Creates an immutable hash set consisting of the argument objects.

The elements will be compared by equality.

EThe element type.
objectsThe element objects.
An immutable hash set or null if the argument is null.
public static <E> Set<E> makeImmutableHashSet(E[] objects)
Creates an immutable hash set consisting of the argument objects.

The elements will be compared by equality.

EThe element type.
objectsThe element objects.
An immutable hash set or null if the argument is null.
public static <K, V> Map<K, V> makeImmutableIdentityHashMap(Map<extends K, ? extends V> map)
Creates a new immutable identity hash map based on the argument map.

The keys will be compared by identity equality. (I.e. The == operator.)

KThe key type.
VThe value type.
mapThe map.
An immutable identity hash map based on the entries, or null if the argument is null.
public static <E> Set<E> makeImmutableIdentityHashSet(Iterable<extends E> objects)
Creates an immutable identity hash set consisting of the argument objects.

The elements will be compared by identity equality. (I.e. The == operator.)

EThe element type.
objectsThe element objects.
An immutable identity hash set or null if the argument is null.
public static <E> Set<E> makeImmutableIdentityHashSet(Collection<extends E> objects)
Creates an immutable identity hash set consisting of the argument objects.

The elements will be compared by identity equality. (I.e. The == operator.)

EThe element type.
objectsThe element objects.
An immutable identity hash set or null if the argument is null.
public static <E> Set<E> makeImmutableIdentityHashSet(E[] objects)
Creates an immutable identity hash set consisting of the argument objects.

The elements will be compared by identity equality. (I.e. The == operator.)

EThe element type.
objectsThe element objects.
An immutable identity hash set or null if the argument is null.
public static <K, V> Entry<K, V> makeImmutableIdentityMapEntry(K key, V value)
Creates a new immutable map entry for the given key-value pair.

The entry uses identity comparison semantics similar to IdentityHashMap.

KThe key type.
VThe value type.
keyThe key.
valueThe value.
An immutable map entry containing the arguments.
public static <K, V> Map<K, V> makeImmutableLinkedHashMap(Map<extends K, ? extends V> map)
Creates a new immutable linked hash map based on the argument map.

The linked hash map differs from the plain hash map that it has a predictable iteration order. This iteration order is the same as the argument map. The iteration order stays the same between serialization and deserialization.

The resulting map implementation may not contain an actual linked data structure, but the same name is kept to keep the established semantic association with the preexisting class.

The keys will be compared by equality.

KThe key type.
VThe value type.
mapThe map.
An immutable linked hash map based on the entries, or null if the argument is null.
public static <E> Set<E> makeImmutableLinkedHashSet(Iterable<extends E> objects)
Creates an immutable linked hash set consisting of the argument objects.

The linked hash set differs from the plain hash set that it has a predictable iteration order. This iteration order is the same as the argument objects. The iteration order stays the same between serialization and deserialization.

The resulting set implementation may not contain an actual linked data structure, but the same name is kept to keep the established semantic association with the preexisting class.

The elements will be compared by equality.

EThe element type.
objectsThe element objects.
An immutable linked hash set or null if the argument is null.
public static <E> Set<E> makeImmutableLinkedHashSet(Collection<extends E> objects)
Creates an immutable linked hash set consisting of the argument objects.

The linked hash set differs from the plain hash set that it has a predictable iteration order. This iteration order is the same as the argument objects. The iteration order stays the same between serialization and deserialization.

The resulting set implementation may not contain an actual linked data structure, but the same name is kept to keep the established semantic association with the preexisting class.

The elements will be compared by equality.

EThe element type.
objectsThe element objects.
An immutable linked hash set or null if the argument is null.
public static <E> Set<E> makeImmutableLinkedHashSet(E[] objects)
Creates an immutable linked hash set consisting of the argument objects.

The linked hash set differs from the plain hash set that it has a predictable iteration order. This iteration order is the same as the argument objects. The iteration order stays the same between serialization and deserialization.

The resulting set implementation may not contain an actual linked data structure, but the same name is kept to keep the established semantic association with the preexisting class.

The elements will be compared by equality.

EThe element type.
objectsThe element objects.
An immutable linked hash set or null if the argument is null.
public static <E> List<E> makeImmutableList(Iterable<extends E> objects)
Creates an immutable list consisting of the argument objects.
EThe element type.
objectsThe element objects.
An immutable list or null if the argument is null.
public static <E> List<E> makeImmutableList(Collection<extends E> objects)
Creates an immutable list consisting of the argument objects.
EThe element type.
objectsThe element objects.
An immutable list or null if the argument is null.
public static <E> List<E> makeImmutableList(E[] objects)
Creates an immutable list consisting of the argument objects.
EThe element type.
objectsThe element objects.
An immutable list or null if the argument is null.
public static <K, V> Entry<K, V> makeImmutableMapEntry(K key, V value)
Creates a new immutable map entry for the given key-value pair.
KThe key type.
VThe value type.
keyThe key.
valueThe value.
An immutable map entry containing the arguments.
public static <K, V> Entry<K, V> makeImmutableMapEntry(Entry<extends K, ? extends V> entry)
Creates an immutable map entry for the given map entry.
KThe key type.
VThe value type.
entryThe map entry to create an immutable instance based on.
The created map entry, or null if the argument is null.
public static <K, V> NavigableMap<K, V> makeImmutableNavigableMap(List<extends K> keys, List<extends V> values) throws IllegalArgumentException, NullPointerException
Creates a new immutable navigable map based on the argument key-value lists.

The lists must have same length. Each key at a given index will be mapped to the value in the value array at the same index.

The lists doesn't need to be RandomAccess, they are accessed by this method using an iterator, and the key-value pairs are matched accordingly.

KThe key type.
VThe value type.
keysThe list of keys.
valuesThe list of values.
An immutable navigable map with entries constructed from the argument lists.
IllegalArgumentExceptionIf the lists have different lengths.
NullPointerExceptionIf any of the lists are null.
public static <K, V> NavigableMap<K, V> makeImmutableNavigableMap(List<extends K> keys, List<extends V> values, Comparator<super K> comparator) throws IllegalArgumentException, NullPointerException
Creates a new immutable navigable map based on the argument key-value lists and ordered by the specified comparator.

The lists must have same length. Each key at a given index will be mapped to the value in the value array at the same index.

The lists doesn't need to be RandomAccess, they are accessed by this method using an iterator, and the key-value pairs are matched accordingly.

KThe key type.
VThe value type.
keysThe list of keys.
valuesThe list of values.
comparatorThe comparator to order the created navigable map.
An immutable navigable map with entries constructed from the argument lists and comparator.
IllegalArgumentExceptionIf the lists have different lengths.
NullPointerExceptionIf any of the lists are null.
public static <K, V> NavigableMap<K, V> makeImmutableNavigableMap(Map<extends K, ? extends V> map)
Creates a new immutable navigable map for the argument map.

The returned map uses the natural order. If the argument contains duplicate keys, only one of them will be present in the resulting set.

KThe key type.
VThe value type.
mapThe map create the navigable map of.
An immutable navigable map based on the entries, or null if the argument is null.
public static <K, V> NavigableMap<K, V> makeImmutableNavigableMap(Map<extends K, ? extends V> map, Comparator<super K> comparator)
Creates a new immutable navigable map for the argument map with the specified order.

The returned map has the ordering specified by the argument comparator. If the argument contains duplicate keys, only one of them will be present in the resulting set.

KThe key type.
VThe value type.
mapThe map create the navigable map of.
comparatorThe comparator that specifies the returned map ordering. Passing null means the natural order.
An immutable navigable map based on the entries, or null if the argument is null.
public static <K, V> NavigableMap<K, V> makeImmutableNavigableMap(NavigableMap<K, ? extends V> map)
Creates a new immutable navigable map for the argument map.

The returned map has the same ordering as the argument.

KThe key type.
VThe value type.
mapThe map create the navigable map of.
An immutable navigable map based on the entries, or null if the argument is null.
public static <K, V> NavigableMap<K, V> makeImmutableNavigableMap(SortedMap<K, ? extends V> map)
Creates a new immutable navigable map for the argument map.

The returned map has the same ordering as the argument.

KThe key type.
VThe value type.
mapThe map create the navigable map of.
An immutable navigable map based on the entries, or null if the argument is null.
public static <K, V> NavigableMap<K, V> makeImmutableNavigableMap(K[] keys, V[] values) throws IllegalArgumentException, NullPointerException
Creates a new immutable navigable map based on the argument key-value arrays.

The arrays must have same length. Each key at a given will be mapped to the value in the value array at the same index.

KThe key type.
VThe value type.
keysThe array of keys.
valuesThe array of values.
An immutable navigable map with entries constructed from the argument arrays.
IllegalArgumentExceptionIf the arrays have different lengths.
NullPointerExceptionIf any of the arrays are null.
public static <K, V> NavigableMap<K, V> makeImmutableNavigableMap(K[] keys, V[] values, Comparator<super K> comparator) throws IllegalArgumentException, NullPointerException
Creates a new immutable navigable map based on the argument key-value arrays and ordered by the specified comparator.

The arrays must have same length. Each key at a given will be mapped to the value in the value array at the same index.

KThe key type.
VThe value type.
keysThe array of keys.
valuesThe array of values.
comparatorThe comparator to order the created navigable map.
An immutable navigable map with entries constructed from the argument arrays and comparator.
IllegalArgumentExceptionIf the arrays have different lengths.
NullPointerExceptionIf any of the arrays are null.
public static <E> NavigableSet<E> makeImmutableNavigableSet(Collection<extends E> objects)
Creates a new immutable navigable set for the argument objects.

The returned set uses the natural order. If the argument contains duplicate elements, only one of them will be present in the resulting set.

EThe element type.
objectsThe elements to construct a set of.
An immutable navigable set based on the elements, or null if the argument is null.
public static <E> NavigableSet<E> makeImmutableNavigableSet(Collection<extends E> objects, Comparator<super E> comparator)
Creates a new immutable navigable set for the argument objects and the the given comparator.

The returned set uses the given comparator for ordering. If the argument contains duplicate elements, only one of them will be present in the resulting set.

EThe element type.
objectsThe elements to construct a set of.
comparatorThe comparator to order the created navigable set.
An immutable navigable set based on the elements, or null if the argument is null.
public static <E> NavigableSet<E> makeImmutableNavigableSet(SortedSet<E> objects)
Creates a new immutable navigable set for the argument objects.

The returned set has the same ordering as the argument.

EThe element type.
objectsThe elements to construct a set of.
An immutable navigable set based on the elements, or null if the argument is null.
public static <E> NavigableSet<E> makeImmutableNavigableSet(E[] objects)
Creates a new immutable navigable set for the argument objects.

The returned set uses the natural order. If the argument contains duplicate elements, only one of them will be present in the resulting set.

EThe element type.
objectsThe elements to construct a set of.
An immutable navigable set based on the elements, or null if the argument is null.
public static <E> NavigableSet<E> makeImmutableNavigableSet(E[] objects, Comparator<super E> comparator)
Creates a new immutable navigable set for the argument objects and the the given comparator.

The returned set uses the given comparator for ordering. If the argument contains duplicate elements, only one of them will be present in the resulting set.

EThe element type.
objectsThe elements to construct a set of.
comparatorThe comparator to order the created navigable set.
An immutable navigable set based on the elements, or null if the argument is null.
public static <E> Enumeration<E> singletionEnumeration(E value)
Creates an enumeration that enumerates only a single object.

The returned object is not Externalizable.

EThe element type.
valueThe object to enumerate.
The created singleton enumeration.
public static <K, V> Map<K, V> singletonIdentityHashMap(K key, V value)
Creates an immutable map with a single entry.

The returned map has the same semantics as IdentityHashMap.

KThe key type.
VThe value type.
keyThe key for the entry.
valueThe value mapped to the key.
The created map.
public static <E> Set<E> singletonIdentityHashSet(E element)
Creates an immutable set with a single element.

The set has the same element semantics as a Set made from IdentityHashMap. The elements are compared by identity (==) and the identity hash code is used.

EThe element type.
elementThe element.
The created set.
public static <E> Iterator<E> singletonIterator(E obj)
Creates an iterator that iterates over a single object.

The returned object is not Externalizable.

EThe element type.
objThe object to iterate over.
The created singleton iterator.
public static <E> List<E> singletonList(E element)
Creates an immutable list with a single element.
EThe element type.
elementThe element.
The created list.
public static <K, V> Map<K, V> singletonMap(K key, V value)
Creates an immutable map with a single entry.
KThe key type.
VThe value type.
keyThe key for the entry.
valueThe value mapped to the key.
The created map.
public static <K, V> NavigableMap<K, V> singletonNavigableMap(K key, V value)
Creates an immutable navigable map with a single entry.

The resulting map is ordered by natural order.

KThe key type.
VThe value type.
keyThe key for the entry.
valueThe value mapped to the key.
The created navigable map.
public static <K, V> NavigableMap<K, V> singletonNavigableMap(K key, V value, Comparator<super K> comparator)
Creates an immutable navigable map with a single entry and comparator.

The SortedMap.comparator() method will return the argument comparator.

KThe key type.
VThe value type.
keyThe key for the entry.
valueThe value mapped to the key.
comparatorThe comparator for the created navigable map.
The created navigable map.
public static <E> NavigableSet<E> singletonNavigableSet(E element)
Creates an immutable navigable set with a single element.

The resulting set is ordered by natural order.

EThe element type.
elementThe element.
The created navigable set.
public static <E> NavigableSet<E> singletonNavigableSet(E element, Comparator<super E> comparator)
Creates an immutable navigable set with a single element and comparator.

The SortedSet.comparator() method will return the argument comparator.

EThe element type.
elementThe element.
comparatorThe comparator for the created navigable set.
The created navigable set.
public static <E> Set<E> singletonSet(E element)
Creates an immutable set with a single element.
EThe element type.
elementThe element.
The created set.
public static <K, V> SortedMap<K, V> singletonSortedMap(K key, V value)
Creates an immutable sorted map with a single entry.

The resulting map is ordered by natural order.

KThe key type.
VThe value type.
keyThe key for the entry.
valueThe value mapped to the key.
The created sorted map.
public static <K, V> SortedMap<K, V> singletonSortedMap(K key, V value, Comparator<super K> comparator)
Creates an immutable sorted map with a single entry and comparator.

The SortedMap.comparator() method will return the argument comparator.

KThe key type.
VThe value type.
keyThe key for the entry.
valueThe value mapped to the key.
comparatorThe comparator for the created sorted map.
The created sorted map.
public static <E> SortedSet<E> singletonSortedSet(E element)
Creates an immutable sorted set with a single element.

The resulting set is ordered by natural order.

EThe element type.
elementThe element.
The created sorted set.
public static <E> SortedSet<E> singletonSortedSet(E element, Comparator<super E> comparator)
Creates an immutable sorted set with a single element and comparator.

The SortedSet.comparator() method will return the argument comparator.

EThe element type.
elementThe element.
comparatorThe comparator for the created sorted set.
The created sorted set.
public static <E> List<E> unmodifiableArrayList(E[] items)
Creates an unmodifiable list view to the argument array.
EThe element type.
itemsThe array of elements.
The unmodifiable view, or null if the argument is null.
public static <E> List<E> unmodifiableArrayList(E[] items, int start, int end) throws IndexOutOfBoundsException
Creates an unmodifiable list view to the argument array in the given range.
EThe element type.
itemsThe array of elements.
startThe starting index of the range in the array. (inclusive)
endThe end index for the range in the array. (exclusive)
The unmodifiable view, or null if the argument is null.
IndexOutOfBoundsExceptionIf the specified range is out of the arrays bounds.
public static <E> Collection<E> unmodifiableCollection(Collection<extends E> collection)
Gets an unmodifiable view to the argument collection.

The Collection, Set, and List classes define different behaviour of their Object.hashCode() and Object.equals(Object) methods. In order to preserve their behaviour, this method checks the implemented interfaces of the argument object.

If the argument collection implements Set, and unmodifiable set will be returned.

If the argument collection implements List, and unmodifiable list will be returned.

In any other cases and unmodifiable collection will be returned that doesn't implement any subinterfaces of Collection. This means that comparing the resulting collection by hash code or equality may end in unexpected results. In this case some of the requirements mandatad by the hash code and equals functions are violated.

collectionThe collection.
The unmodifiable view, or null if the argument is null.
public static <E> Iterator<E> unmodifiableIterator(Iterator<extends E> it)
Wraps the argument iterator into an unmodifiable iterator.

Calling Iterator.remove() on the returned iterator will throw an UnsupportedOperationException.

EThe element type.
itThe iterator.
The unmodifiable iterator, or null if the argument is null.
public static <E> List<E> unmodifiableList(List<extends E> list)
Gets an unmodifiable view to the argument list.
EThe element type.
listThe list.
The unmodifiable view, or null if the argument is null.
public static <E> ListIterator<E> unmodifiableListIterator(ListIterator<extends E> it)
Wraps the argument list iterator into an unmodifiable list iterator.

Calling modifying functions on the returned iteratir will throw an UnsupportedOperationException.

EThe element type.
itThe iterator.
The unmodifiable list iterator, or null if the argument is null.
public static <K, V> Map<K, V> unmodifiableMap(Map<extends K, ? extends V> map)
Gets an unmodifiable view to the argument map.
KThe key type.
VThe value type.
mapThe map.
The unmodifiable view, or null if the argument is null.
public static <K, V> Entry<K, V> unmodifiableMapEntry(Entry<extends K, ? extends V> entry)
Gets an unmodifiable view to the argument map entry.
KThe key type.
VThe value type.
entryThe map entry.
The unmodifiable view, or null if the argument is null.
public static <K, V> Iterator<Entry<K, V>> unmodifiableMapEntryIterator(Iterator<extends Entry<extends K, ? extends V>> it)
Wraps the argument map entry iterator into an unmodifiable iterator.

Calling Iterator.remove() on the returned iterator will throw an UnsupportedOperationException.

Calling Map.Entry.setValue(V) on the entries returned by the iterator will also throw an UnsupportedOperationException.

KThe key type.
VThe value type.
itThe iterator.
The unmodifiable iterator, or null if the argument is null.
public static <K, V> NavigableMap<K, V> unmodifiableNavigableMap(List<K> keys, List<V> values) throws IllegalArgumentException, NullPointerException
Creates a new unmodifiable navigable map that is backed by the argument key and value lists.

The keys should be stricly ordered by the natural order.

The lists must have same length. Each key at a given will be mapped to the value in the value list at the same index.

Callers should not modify the contents of the argument lists after the result map has been constructed.

If the above requirements are violated, the code that uses the returned map may experience unexpected results. If the elements are not stricly sorted, the lookup methods may not work properly in the returned map.

If you might possibly modify the argument lists after this method returns, consider using makeImmutableNavigableMap(List<extends K>, List<extends V>) instead, which creates its own copy of elements.

KThe key type.
VThe value type
keysThe list of keys.
valuesThe list of values.
The unmodifiable navigable map view to the argument lists ordered by natural order.
IllegalArgumentExceptionIf the lists have different lengths.
NullPointerExceptionIf any of the arguments are null.
public static <K, V> NavigableMap<K, V> unmodifiableNavigableMap(List<K> keys, List<V> values, Comparator<super K> comparator) throws IllegalArgumentException, NullPointerException
Creates a new unmodifiable navigable map that is backed by the argument key and value lists.

The keys should be stricly ordered by the argument comparator.

The lists must have same length. Each key at a given will be mapped to the value in the value list at the same index.

Callers should not modify the contents of the argument lists after the result map has been constructed.

If the above requirements are violated, the code that uses the returned map may experience unexpected results. If the elements are not stricly sorted, the lookup methods may not work properly in the returned map.

If you might possibly modify the argument lists after this method returns, consider using makeImmutableNavigableMap(List<extends K>, List<extends V>, Comparator<super K>) instead, which creates its own copy of elements.

The argument lists should support random access indexing for better performance.

KThe key type.
VThe value type
keysThe list of keys.
valuesThe list of values.
comparatorThe comparator that specifies the order of the elements.
The unmodifiable navigable map view to the argument lists ordered by the argument comparator.
IllegalArgumentExceptionIf the lists have different lengths.
NullPointerExceptionIf any of the arguments are null.
public static <K, V> NavigableMap<K, V> unmodifiableNavigableMap(NavigableMap<K, ? extends V> map)
Gets an unmodifiable view to the argument navigable map.
KThe key type.
VThe value type.
mapThe map.
The unmodifiable view, or null if the argument is null.
public static <K, V> NavigableMap<K, V> unmodifiableNavigableMap(K[] keys, V[] values) throws IllegalArgumentException, NullPointerException
Creates a new unmodifiable navigable map that is backed by the argument key and value arrays.

The keys should be stricly ordered by the natural order.

The arrays must have same length. Each key at a given will be mapped to the value in the value array at the same index.

Callers should not modify the contents of the argument arrays after the result map has been constructed.

If the above requirements are violated, the code that uses the returned map may experience unexpected results. If the elements are not stricly sorted, the lookup methods may not work properly in the returned map.

If you might possibly modify the argument arrays after this method returns, consider using makeImmutableNavigableMap(K[], V[]) instead, which creates its own copy of elements.

KThe key type.
VThe value type
keysThe array of keys.
valuesThe array of values.
The unmodifiable navigable map view to the argument arrays ordered by natural order.
IllegalArgumentExceptionIf the arrays have different lengths.
NullPointerExceptionIf any of the arguments are null.
public static <K, V> NavigableMap<K, V> unmodifiableNavigableMap(K[] keys, V[] values, Comparator<super K> comparator) throws IllegalArgumentException, NullPointerException
Creates a new unmodifiable navigable map that is backed by the argument key and value arrays.

The keys should be stricly ordered by the argument comparator.

The arrays must have same length. Each key at a given will be mapped to the value in the value array at the same index.

Callers should not modify the contents of the argument arrays after the result map has been constructed.

If the above requirements are violated, the code that uses the returned map may experience unexpected results. If the elements are not stricly sorted, the lookup methods may not work properly in the returned map.

If you might possibly modify the argument arrays after this method returns, consider using makeImmutableNavigableMap(K[], V[], Comparator<super K>) instead, which creates its own copy of elements.

KThe key type.
VThe value type
keysThe array of keys.
valuesThe array of values.
comparatorThe comparator that specifies the order of the elements.
The unmodifiable navigable map view to the argument arrays ordered by the argument comparator.
IllegalArgumentExceptionIf the arrays have different lengths.
NullPointerExceptionIf any of the arguments are null.
public static <E> NavigableSet<E> unmodifiableNavigableSet(List<extends E> elements)
Creates a new navigable set that is backed by the argument list of elements.

The elements must be stricly ordered by the natural order.

Callers should not modify the contents of the argument list after the result set has been constructed.

If the above requirements are violated, the code that uses the returned set may experience unexpected results. If the elements are not stricly sorted, the lookup methods may not work properly in the returned set.

If you might possibly modify the argument array after this method returns, consider using makeImmutableNavigableSet(Collection<extends E>) instead, which creates its own copy of elements.

The argument list should support random access indexing for better performance.

elementsThe backing elements for the created navigable set.
An unmodifiable navigable set backed by the argument list, ordered by natural order.
public static <E> NavigableSet<E> unmodifiableNavigableSet(List<extends E> elements, Comparator<super E> comparator)
Creates a new navigable set that is backed by the argument list of elements.

The elements must be stricly ordered by the argument comparator.

Callers should not modify the contents of the argument list after the result set has been constructed.

If the above requirements are violated, the code that uses the returned set may experience unexpected results. If the elements are not stricly sorted, the lookup methods may not work properly in the returned set.

If you might possibly modify the argument list after this method returns, consider using makeImmutableNavigableSet(Collection<extends E>, Comparator<super E>) instead, which creates its own copy of elements.

The argument list should support random access indexing for better performance.

elementsThe backing elements for the created navigable set.
comparatorThe comparator for the ordering of the set.
An unmodifiable navigable set backed by the argument list, ordered by the argument comparator.
Gets an unmodifiable view to the argument navigable set.
EThe element type.
setThe set.
The unmodifiable view, or null if the argument is null.
public static <E> NavigableSet<E> unmodifiableNavigableSet(E[] elements)
Creates a new navigable set that is backed by the argument array of elements.

The elements must be stricly ordered by the natural order.

Callers should not modify the contents of the argument array after the result set has been constructed.

If the above requirements are violated, the code that uses the returned set may experience unexpected results. If the elements are not stricly sorted, the lookup methods may not work properly in the returned set.

If you might possibly modify the argument array after this method returns, consider using makeImmutableNavigableSet(E[]) instead, which creates its own copy of elements.

EThe element type.
elementsThe backing elements for the created navigable set.
An unmodifiable navigable set backed by the argument array, ordered by natural order.
public static <E> NavigableSet<E> unmodifiableNavigableSet(E[] elements, int start, int end) throws IndexOutOfBoundsException
Creates a new navigable set that is backed by the elements in the argument array region.

The elements must be stricly ordered by the natural order.

Callers should not modify the contents of the argument array after the result set has been constructed.

If the above requirements are violated, the code that uses the returned set may experience unexpected results. If the elements are not stricly sorted, the lookup methods may not work properly in the returned set.

If you might possibly modify the argument array range after this method returns, consider using unmodifiableNavigableSet(Arrays.copyOfRange(elements, start, end)) instead, by manually creating an owned copy of the range.

EThe element type.
elementsThe backing elements for the created navigable set.
startThe start index of the specified range. (inclusive)
endThe end index of the specified range. (exclusive)
An unmodifiable navigable set backed by the argument array range, ordered by natural order.
IndexOutOfBoundsExceptionIf the specified range is out of bounds.
public static <E> NavigableSet<E> unmodifiableNavigableSet(E[] elements, int start, int end, Comparator<super E> comparator) throws IndexOutOfBoundsException
Creates a new navigable set that is backed by the elements in the argument array region.

The elements must be stricly ordered by the argument comparator.

Callers should not modify the contents of the argument array after the result set has been constructed.

If the above requirements are violated, the code that uses the returned set may experience unexpected results. If the elements are not stricly sorted, the lookup methods may not work properly in the returned set.

If you might possibly modify the argument array range after this method returns, consider using unmodifiableNavigableSet(Arrays.copyOfRange(elements, start, end), comparator) instead, by manually creating an owned copy of the range.

EThe element type.
elementsThe backing elements for the created navigable set.
startThe start index of the specified range. (inclusive)
endThe end index of the specified range. (exclusive)
comparatorThe comparator for the ordering of the set.
An unmodifiable navigable set backed by the argument array range, ordered by natural order.
IndexOutOfBoundsExceptionIf the specified range is out of bounds.
public static <E> NavigableSet<E> unmodifiableNavigableSet(E[] elements, Comparator<super E> comparator)
Creates a new navigable set that is backed by the argument array of elements.

The elements must be stricly ordered by the argument comparator.

Callers should not modify the contents of the argument array after the result set has been constructed.

If the above requirements are violated, the code that uses the returned set may experience unexpected results. If the elements are not stricly sorted, the lookup methods may not work properly in the returned set.

If you might possibly modify the argument array after this method returns, consider using makeImmutableNavigableSet(E[], Comparator<super E>) instead, which creates its own copy of elements.

elementsThe backing elements for the created navigable set.
comparatorThe comparator for the ordering of the set.
An unmodifiable navigable set backed by the argument array, ordered by the argument comparator.
Creates an unmodifiable array list view to the argument array.

The argument should have an array type, which may be a primitive array.

arrayThe array of elements.
The unmodifiable view, or null if the argument is null.
IllegalArgumentExceptionIf the argument is not an array.
public static List<?> unmodifiableReflectionArrayList(Object array, int offset, int length) throws IllegalArgumentException, IndexOutOfBoundsException
Creates an unmodifiable array list view to the argument array in the specified range.

The argument should have an array type, which may be a primitive array.

arrayThe array of elements.
offsetThe offset where the returned view should start.
lengthThe number of elements in the array view.
The unmodifiable view, or null if the argument is null.
IllegalArgumentExceptionIf the argument is not an array.
IndexOutOfBoundsExceptionIf the specified range is out of bounds.
public static <E> Set<E> unmodifiableSet(Set<extends E> set)
Gets an unmodifiable view to the argument set.
EThe element type.
setThe set.
The unmodifiable view, or null if the argument is null.
public static <K, V> SortedMap<K, V> unmodifiableSortedMap(SortedMap<K, ? extends V> map)
Gets an unmodifiable view to the argument sorted map.
KThe key type.
VThe value type.
mapThe map.
The unmodifiable view, or null if the argument is null.
public static <E> SortedSet<E> unmodifiableSortedSet(SortedSet<E> set)
Gets an unmodifiable view to the argument sorted set.
EThe element type.
setThe set.
The unmodifiable view, or null if the argument is null.