Package com.github.andrewoma.dexx.collection
Dexx collections are a port of Scala's immutable, persistent collection classes to pure Java.
Persistent in the context of functional data structures means the data structure preserves the previous version of itself when modified. This means any reference to a collection is effectively immutable. However, modifications can be made by returning a new version of the data structure, leaving the original structure unchanged.
The following diagram shows the key interfaces (blue) and classes (green) in this package:
Usage Notes:
- Each of the collection types has an associated companion class (plural form) that is the
preferred method of construction. e.g. To create a
Set, use theSetsclass. - Many of the collections have the same name as their mutable
java.utilcounterparts, however they are not directly related. This is due to the interfaces being fundamentally incompatible as operations the "modify" collections must return a new instance for persistent collections. - Collections can be viewed as their
java.utilcounterpart by usingas...()methods. e.g.Set.asSet(). Such views are immutable. - Collections can be constructed from
java.utilcollections by using thecopyOf(...)methods in the companion classes. e.g.Sets.copyOf(java.lang.Iterable). - While operations on collections often return a new instance that reflects the modifications,
this is not a guarantee. e.g. Attempting to remove an element from a
Setthat does not exist may return the same collection as no modifications were required.
See the project site for further examples and information.
-
Interface Summary Interface Description Builder<E,R> Buildersprovide efficient implementations for incrementally building persistent collections.BuilderFactory<E,R> BuilderFactorydefines a factory interface for creatingBuilderinstances.Function<P,R> A generic function interface that takes a single parameter.IndexedList<E> IndexedListimplementations guarantee fast random access to elements viaList.get(int).Iterable<E> Iterabledefines collections that can be accessed via anIterator.KeyFunction<K,V> KeyFunctiondefines the interface for extracting a key from a value.LinkedList<E> LinkedListimplementations guarantee fast access to the head viaList.first()and tail viaLinkedList.tail().List<E> Listdefines an sequence of elements where the order is preserved.Map<K,V> Mapdefines the interface for maps that associate keys with values.Set<E> Set defines the interface for a unique set of values as defined byObject.equals(Object).SortedMap<K,V> SortedMap defines the interface for maps that are sorted by their key.SortedSet<E> SortedSetdefines the interface for sets that are sorted.Traversable<E> Traversableis the root of the collection hierarchy. -
Class Summary Class Description ArrayList<E> ArrayListis anIndexedListimplementation backed by an array.ArrayLists ArrayListsis the preferred method of constructing instances ofArrayList.Cons<E> Cons constructs a new list by prepending a new element to an existing listConsList<E> ConsListis a functionalLinkedListimplementation that constructs a list by prepending an element to another list.ConsListIterator<E> DerivedKeyHashMap<K,V> DerivedKeyHashMapis aHashMapvariant where the key for theMapis derived from the value stored.HashMap<K,V> HashMapis an implementation ofMapbased on a hash trie.HashMap.Itr<K,V> HashSet<E> HashSetis an implementation ofSetbacked by aHashMap.IdentityKeyFunction<E> IdentityKeyFunctionis aKeyFunctionwhere the value can be used as a key.IndexedLists IndexedListsis the preferred method of constructing instances ofIndexedList.LinkedLists LinkedListsis the preferred method of constructing instances ofLinkedList.Maps Mapsis the preferred method of constructing instances ofMap.Nil<E> Nil is the empty listPair<C1,C2> Pairis a generic container for two components of specified types.Sets Setsis the preferred method of constructing instances ofSet.SortedMaps SortedMapsis the preferred method of constructing instances ofSortedMap.SortedSets SortedSetsis the preferred method of constructing instances ofSortedSet.TreeMap<K,V> TreeSet<E> TreeSetis an implementation ofSortedSetbacked by aTreeMap.Vector<E> Vector is a general-purpose, immutable data structure.VectorBuilder<E> VectorIterator<E> VectorPointer<E>