Package net.sf.saxon.ma.trie
Class ImmutableList<T>
- java.lang.Object
-
- net.sf.saxon.ma.trie.ImmutableList<T>
-
- Type Parameters:
T
- the type of the elements in the list
- All Implemented Interfaces:
java.lang.Iterable<T>
public abstract class ImmutableList<T> extends java.lang.Object implements java.lang.Iterable<T>
An immutable list implementation that only supports sequential traversal using an iterator, prepending an item to the start, and extraction of the head()/tail() of the list. This is optimized for sequential access rather than direct access.
-
-
Constructor Summary
Constructors Constructor Description ImmutableList()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static <T> ImmutableList<T>
empty()
Return an empty listboolean
equals(java.lang.Object o)
Test whether two lists are equalabstract T
head()
Get the first item in the listabstract boolean
isEmpty()
Ask whether the list is emptyjava.util.Iterator<T>
iterator()
Get an iterator over the elements of the listImmutableList<T>
prepend(T element)
Return a list with a new item added at the startImmutableList<T>
reverse()
Return a list with the contents of this list in reverse orderint
size()
Get the size of the list (the number of items).abstract ImmutableList<T>
tail()
Get all items in the list other than the firstjava.lang.String
toString()
Return a string representation of the list contents
-
-
-
Method Detail
-
empty
public static <T> ImmutableList<T> empty()
Return an empty list- Type Parameters:
T
- the nominal item type of the list elements- Returns:
- an empty list
-
head
public abstract T head()
Get the first item in the list- Returns:
- the first item in the list
-
tail
public abstract ImmutableList<T> tail()
Get all items in the list other than the first- Returns:
- a list containing all items except the first
-
isEmpty
public abstract boolean isEmpty()
Ask whether the list is empty- Returns:
- true if and only if the list contains no items
-
size
public final int size()
Get the size of the list (the number of items). Note that this is an O(n) operation.- Returns:
- the size of the list.
-
prepend
public ImmutableList<T> prepend(T element)
Return a list with a new item added at the start- Parameters:
element
- the item to be added at the start- Returns:
- a new list
-
equals
public boolean equals(java.lang.Object o)
Test whether two lists are equal- Overrides:
equals
in classjava.lang.Object
- Parameters:
o
- the other list- Returns:
- true if the other object is an instance of this ImmutableList class, and the elements of the two lists are pairwise equal.
-
iterator
public java.util.Iterator<T> iterator()
Get an iterator over the elements of the list- Specified by:
iterator
in interfacejava.lang.Iterable<T>
- Returns:
- an iterator over the list
-
toString
public java.lang.String toString()
Return a string representation of the list contents- Overrides:
toString
in classjava.lang.Object
- Returns:
- a string in the form "[item1, item2, ...]"
-
reverse
public ImmutableList<T> reverse()
Return a list with the contents of this list in reverse order- Returns:
- the reversed list
-
-