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 or Set 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...
Still there are a number of similarities, though these were not always explicitly stated as features in Guava:
  • The list sets and maps still require all values to be non-null.
  • The UnmodifiableSet and UnmodifiableMap 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.
The classes implemented here have been made to be compact and fast, not to be functional utilities. Still there are some utility methods added, one to make all collections into lists, and one to make maps explicitly ordered. See UnmodifiableCollection.asList() and UnmodifiableMapBase.orderedBy(java.util.Comparator).