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.
public static < | asUnmodifiableArrayList( Creates an unmodifiable list view to the argument array. |
public static < | emptyNavigableMap( Gets an immutable empty navigable map that has the argument comparator. |
public static < | emptyNavigableSet( Gets an immutable empty navigable set that has the argument comparator. |
public static < | emptySortedMap( Gets an immutable empty sorted map that has the argument comparator. |
public static < | emptySortedSet( Gets an immutable empty sorted set that has the argument comparator. |
public static < | makeImmutableHashMap( Creates a new immutable hash map based on the argument map. |
public static < | makeImmutableHashSet( Creates an immutable hash set consisting of the argument objects. |
public static < | makeImmutableHashSet( Creates an immutable hash set consisting of the argument objects. |
public static < | makeImmutableHashSet( Creates an immutable hash set consisting of the argument objects. |
public static < | makeImmutableIdentityHashMap( Creates a new immutable identity hash map based on the argument map. |
public static < | makeImmutableIdentityHashSet( Creates an immutable identity hash set consisting of the argument objects. |
public static < | makeImmutableIdentityHashSet( Creates an immutable identity hash set consisting of the argument objects. |
public static < | makeImmutableIdentityHashSet( Creates an immutable identity hash set consisting of the argument objects. |
public static < | makeImmutableIdentityMapEntry( Creates a new immutable map entry for the given key-value pair. |
public static < | makeImmutableLinkedHashMap( Creates a new immutable linked hash map based on the argument map. |
public static < | makeImmutableLinkedHashSet( Creates an immutable linked hash set consisting of the argument objects. |
public static < | makeImmutableLinkedHashSet( Creates an immutable linked hash set consisting of the argument objects. |
public static < | makeImmutableLinkedHashSet( Creates an immutable linked hash set consisting of the argument objects. |
public static < | makeImmutableList( Creates an immutable list consisting of the argument objects. |
public static < | makeImmutableList( Creates an immutable list consisting of the argument objects. |
public static < | makeImmutableList( Creates an immutable list consisting of the argument objects. |
public static < | makeImmutableMapEntry( Creates a new immutable map entry for the given key-value pair. |
public static < | makeImmutableMapEntry( Creates an immutable map entry for the given map entry. |
public static < | makeImmutableNavigableMap( Creates a new immutable navigable map based on the argument key-value lists. |
public static < | makeImmutableNavigableMap( Creates a new immutable navigable map based on the argument key-value lists and ordered by the specified
comparator. |
public static < | makeImmutableNavigableMap( Creates a new immutable navigable map for the argument map. |
public static < | makeImmutableNavigableMap( Creates a new immutable navigable map for the argument map with the specified order. |
public static < | makeImmutableNavigableMap( Creates a new immutable navigable map for the argument map. |
public static < | makeImmutableNavigableMap( Creates a new immutable navigable map for the argument map. |
public static < | makeImmutableNavigableMap( Creates a new immutable navigable map based on the argument key-value arrays. |
public static < | makeImmutableNavigableMap( Creates a new immutable navigable map based on the argument key-value arrays and ordered by the specified
comparator. |
public static < | makeImmutableNavigableSet( Creates a new immutable navigable set for the argument objects. |
public static < | makeImmutableNavigableSet( Creates a new immutable navigable set for the argument objects and the the given comparator. |
public static < | makeImmutableNavigableSet( Creates a new immutable navigable set for the argument objects. |
public static < | makeImmutableNavigableSet( Creates a new immutable navigable set for the argument objects. |
public static < | makeImmutableNavigableSet( Creates a new immutable navigable set for the argument objects and the the given comparator. |
public static < | singletionEnumeration( Creates an enumeration that enumerates only a single object. |
public static < | singletonIdentityHashMap( Creates an immutable map with a single entry. |
public static < | singletonIdentityHashSet( Creates an immutable set with a single element. |
public static < | singletonIterator( Creates an iterator that iterates over a single object. |
public static < | singletonList( Creates an immutable list with a single element. |
public static < | singletonMap( Creates an immutable map with a single entry. |
public static < | singletonNavigableMap( Creates an immutable navigable map with a single entry. |
public static < | singletonNavigableMap( Creates an immutable navigable map with a single entry and comparator. |
public static < | singletonNavigableSet( Creates an immutable navigable set with a single element. |
public static < | singletonNavigableSet( Creates an immutable navigable set with a single element and comparator. |
public static < | singletonSet( Creates an immutable set with a single element. |
public static < | singletonSortedMap( Creates an immutable sorted map with a single entry. |
public static < | singletonSortedMap( Creates an immutable sorted map with a single entry and comparator. |
public static < | singletonSortedSet( Creates an immutable sorted set with a single element. |
public static < | singletonSortedSet( Creates an immutable sorted set with a single element and comparator. |
public static < | unmodifiableArrayList( Creates an unmodifiable list view to the argument array. |
public static < | unmodifiableArrayList( Creates an unmodifiable list view to the argument array in the given range. |
public static < | unmodifiableCollection( Gets an unmodifiable view to the argument collection. |
public static < | unmodifiableIterator( Wraps the argument iterator into an unmodifiable iterator. |
public static < | unmodifiableList( Gets an unmodifiable view to the argument list. |
public static < | unmodifiableListIterator( Wraps the argument list iterator into an unmodifiable list iterator. |
public static < | unmodifiableMap( Gets an unmodifiable view to the argument map. |
public static < | unmodifiableMapEntry( Gets an unmodifiable view to the argument map entry. |
public static < | unmodifiableMapEntryIterator( Wraps the argument map entry iterator into an unmodifiable iterator. |
public static < | unmodifiableNavigableMap( Creates a new unmodifiable navigable map that is backed by the argument key and value lists. |
public static < | unmodifiableNavigableMap( Creates a new unmodifiable navigable map that is backed by the argument key and value lists. |
public static < | unmodifiableNavigableMap( Gets an unmodifiable view to the argument navigable map. |
public static < | unmodifiableNavigableMap( Creates a new unmodifiable navigable map that is backed by the argument key and value arrays. |
public static < | unmodifiableNavigableMap( Creates a new unmodifiable navigable map that is backed by the argument key and value arrays. |
public static < | unmodifiableNavigableSet( Creates a new navigable set that is backed by the argument list of elements. |
public static < | unmodifiableNavigableSet( Creates a new navigable set that is backed by the argument list of elements. |
public static < | unmodifiableNavigableSet( Gets an unmodifiable view to the argument navigable set. |
public static < | unmodifiableNavigableSet( Creates a new navigable set that is backed by the argument array of elements. |
public static < | unmodifiableNavigableSet( Creates a new navigable set that is backed by the elements in the argument array region. |
public static < | unmodifiableNavigableSet( Creates a new navigable set that is backed by the elements in the argument array region. |
public static < | unmodifiableNavigableSet( 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( Creates an unmodifiable array list view to the argument array in the specified range. |
public static < | unmodifiableSet( Gets an unmodifiable view to the argument set. |
public static < | unmodifiableSortedMap( Gets an unmodifiable view to the argument sorted map. |
public static < | unmodifiableSortedSet( Gets an unmodifiable view to the argument sorted set. |
This method works similarly to unmodifiableArrayList(
The method is named with similarity to Arrays.asList(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.
null
if the argument is null
.The SortedMap.comparator() method will return the argument comparator.
The SortedSet.comparator() method will return the argument comparator.
The keys will be compared by equality. (See Objects.equals(
null
if the argument is null
.
The keys will be compared by identity equality. (I.e. The ==
operator.)
null
if the argument is
null
.
The elements will be compared by identity equality. (I.e. The ==
operator.)
null
if the argument is null
.
The elements will be compared by identity equality. (I.e. The ==
operator.)
null
if the argument is null
.
The elements will be compared by identity equality. (I.e. The ==
operator.)
null
if the argument is null
.The entry uses identity comparison semantics similar to IdentityHashMap.
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.
null
if the argument is
null
.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.
null
if the argument is null
.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.
null
if the argument is null
.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.
null
if the argument is null
.null
if the argument is null
.null
if the argument is null
.null
if the argument is null
.null
if the argument is null
.The returned object is not Externalizable.
The returned map has the same semantics as IdentityHashMap.
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.
The returned object is not Externalizable.
The resulting map is ordered by natural order.
The SortedMap.comparator() method will return the argument comparator.
The resulting set is ordered by natural order.
The SortedSet.comparator() method will return the argument comparator.
null
if the argument is null
.null
if the argument is null
.
The Collection, Set, and List classes define different behaviour of their
Object.hashCode() and Object.equals(
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.
null
if the argument is null
.Calling Iterator.remove() on the returned iterator will throw an UnsupportedOperationException.
null
if the argument is null
.null
if the argument is null
.Calling modifying functions on the returned iteratir will throw an UnsupportedOperationException.
null
if the argument is null
.null
if the argument is null
.null
if the argument is null
.Calling Iterator.remove() on the returned iterator will throw an UnsupportedOperationException.
Calling Map.Entry.setValue(
null
if the argument is null
.The argument should have an array type, which may be a primitive array.
null
if the argument is null
.The argument should have an array type, which may be a primitive array.
null
if the argument is null
.null
if the argument is null
.null
if the argument is null
.null
if the argument is null
.