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:
Iterable<T>
public abstract class ImmutableList<T> extends Object implements 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. Unlikenet.sf.saxon.ma.parray.ImmList
, it 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(Object o)
Test whether two lists are equalabstract T
head()
Get the first item in the listabstract boolean
isEmpty()
Ask whether the list is emptyIterator<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 firstString
toString()
Return a string representation of the list contents-
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
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(Object o)
Test whether two lists are equal
-
toString
public String toString()
Return a string representation of the list contents
-
reverse
public ImmutableList<T> reverse()
Return a list with the contents of this list in reverse order- Returns:
- the reversed list
-
-