Package net.morimekta.util.collect
This package contains a number of unmodifiable collection classes
largely inspired of the immutable collections in
guava. Note that there
are some important differences:
- All classes are made as simple as possible, only one implementation per type (e.g. no special 1-entry set implementation).
-
Builder classes for map and set accepts duplicate values / duplicate
keys, and will handle them as a normal
Map
orSet
would. - The unmodifiable collections are not serializable, and if forcefully serialized will always end up empty, and as new instances. PS: The whole concept of serializable should be ditched in my opinion.
- Note that since the classes were more or less written from scratch, I have taken the liberty of taking the general copyright of the implementations, though lots of kudos to the Guava team for making them in the first place, and more or less standardizing the interface for immutable collections. Even Java uses these now...
- The list sets and maps still require all values to be non-null.
-
The
UnmodifiableSet
andUnmodifiableMap
classes will always preserve input order. - Constructors will try to reuse the same instance and backing instances as much as possible, with the limitations of local knowledge.
UnmodifiableCollection.asList()
and
UnmodifiableMapBase.orderedBy(java.util.Comparator)
.-
Interface Summary Interface Description UnmodifiableCollectionBuilder<E,C extends UnmodifiableCollection<E>,B extends UnmodifiableCollectionBuilder<E,C,B>> Base interface for unmodifiable collections. -
Class Summary Class Description SetOperations Utility class containing set-math operations.UnmodifiableCollection<E> Simple unmodifiable collection base class.UnmodifiableList<E> Simple unmodifiable list implementation backed by an object array.UnmodifiableList.Builder<E> UnmodifiableMap<K,V> Simple unmodifiable map that preserves entry order when iterating.UnmodifiableMap.Builder<K,V> UnmodifiableMapBuilder<K,V,M extends net.morimekta.util.collect.UnmodifiableMapBase<K,V>,B extends UnmodifiableMapBuilder<K,V,M,B>> Unmodifiables UnmodifiableSet<E> Simple immutable set.UnmodifiableSet.Builder<E> UnmodifiableSortedMap<K,V> UnmodifiableSortedMap.Builder<K,V> UnmodifiableSortedSet<E> UnmodifiableSortedSet.Builder<E>