Package com.github.andrewoma.dexx.collection


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:

Dexx collections overview

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 the Sets class.

  • Many of the collections have the same name as their mutable java.util counterparts, 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.util counterpart by using as...() methods. e.g. Set.asSet(). Such views are immutable.

  • Collections can be constructed from java.util collections by using the copyOf(...) 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 Set that does not exist may return the same collection as no modifications were required.

See the project site for further examples and information.

  • Class
    Description
    ArrayList is an IndexedList implementation backed by an array.
    ArrayLists is the preferred method of constructing instances of ArrayList.
    Builder<E,R>
    Builders provide efficient implementations for incrementally building persistent collections.
    BuilderFactory defines a factory interface for creating Builder instances.
    Cons<E>
    Cons constructs a new list by prepending a new element to an existing list
    ConsList is a functional LinkedList implementation that constructs a list by prepending an element to another list.
     
    DerivedKeyHashMap is a HashMap variant where the key for the Map is derived from the value stored.
    A generic function interface that takes a single parameter.
    HashMap<K,V>
    HashMap is an implementation of Map based on a hash trie.
     
    HashSet is an implementation of Set backed by a HashMap.
    IdentityKeyFunction is a KeyFunction where the value can be used as a key.
    IndexedList implementations guarantee fast random access to elements via List.get(int).
    IndexedLists is the preferred method of constructing instances of IndexedList.
    Iterable defines collections that can be accessed via an Iterator.
    KeyFunction defines the interface for extracting a key from a value.
    LinkedList implementations guarantee fast access to the head via List.first() and tail via LinkedList.tail().
    LinkedLists is the preferred method of constructing instances of LinkedList.
    List<E>
    List defines an sequence of elements where the order is preserved.
    Map<K,V>
    Map defines the interface for maps that associate keys with values.
    Maps is the preferred method of constructing instances of Map.
    Nil<E>
    Nil is the empty list
    Pair<C1,C2>
    Pair is a generic container for two components of specified types.
    Set<E>
    Set defines the interface for a unique set of values as defined by Object.equals(Object).
    Sets is the preferred method of constructing instances of Set.
    SortedMap defines the interface for maps that are sorted by their key.
    SortedMaps is the preferred method of constructing instances of SortedMap.
    SortedSet defines the interface for sets that are sorted.
    SortedSets is the preferred method of constructing instances of SortedSet.
    Traversable is the root of the collection hierarchy.
    TreeMap<K,V>
    TreeMap is an implementation of SortedMap based on a red-black tree.
    TreeSet is an implementation of SortedSet backed by a TreeMap.
    Vector is a general-purpose, immutable data structure.