Constructor and Description |
---|
ImmList() |
Modifier and Type | Method and Description |
---|---|
abstract ImmList<E> |
append(E member)
Append an element at the end of the list
|
abstract ImmList<E> |
appendList(ImmList<E> members)
Append multiple elements at the end of the list
|
static <E> ImmList<E> |
empty()
Return an empty list
|
static <E> ImmList<E> |
fromList(java.util.List<E> members)
Construct an immutable list from a Java list of members
|
abstract E |
get(int index)
Get the element at a given index
|
E |
head()
Get the first element in the list
|
abstract ImmList<E> |
insert(int index,
E member)
Insert an element at a given position
|
abstract boolean |
isEmpty()
Ask if the list is empty
|
protected java.lang.IndexOutOfBoundsException |
outOfBounds(int requested,
int actual)
Convenience method for use by subclasses to throw an IndexOutOfBounds exception when needed
|
static <E> ImmList<E> |
pair(E first,
E second)
Return a list of length 2 (two)
|
protected ImmList<E> |
rebalance()
Return a list containing the same elements as this list, but optimized for efficient access
|
abstract ImmList<E> |
remove(int index)
Remove the member at a given position
|
abstract ImmList<E> |
replace(int index,
E member)
Replace the element at a given index
|
static <E> ImmList<E> |
singleton(E member)
Return a singleton list (a list containing one item)
|
abstract int |
size()
Get the size of the list
|
abstract ImmList<E> |
subList(int start,
int end)
Return a sub-sequence with a given start and end position
|
ImmList<E> |
tail()
Get a list containing all elements of the list except the first
|
public static <E> ImmList<E> empty()
E
- the (nominal) type of the list elementpublic static <E> ImmList<E> singleton(E member)
E
- the type of the list membersmember
- the single member of the listpublic static <E> ImmList<E> pair(E first, E second)
E
- the type of the list membersfirst
- the first member of the listsecond
- the second member of the listpublic static <E> ImmList<E> fromList(java.util.List<E> members)
E
- the type of the list membersmembers
- the members to be added to the listpublic abstract E get(int index)
index
- the required index (zero-based)java.lang.IndexOutOfBoundsException
- if the index is out of rangepublic E head()
java.lang.IndexOutOfBoundsException
- if the list is emptypublic abstract int size()
public abstract boolean isEmpty()
public abstract ImmList<E> replace(int index, E member)
index
- the index (zero-based) of the element to be replacedmember
- the replacement member to be included in the new listjava.lang.IndexOutOfBoundsException
- if the index is out of rangepublic abstract ImmList<E> insert(int index, E member)
index
- the position (zero-based) for the insertion. The new element will
be inserted before the existing element at this position. If the index
is equal to the list size, the new element is inserted at the end.member
- the new member to be included in the new listjava.lang.IndexOutOfBoundsException
- if the index is out of rangepublic abstract ImmList<E> append(E member)
member
- the new member to be included in the new listpublic abstract ImmList<E> appendList(ImmList<E> members)
members
- the new members to be included in the new listpublic abstract ImmList<E> remove(int index)
index
- the zero-based index position of the member to be removedjava.lang.IndexOutOfBoundsException
- if the index is out of rangepublic abstract ImmList<E> subList(int start, int end)
start
- the zero-based index position of the first member to be extractedend
- the zero-based index position of the first member after the sub-sequence
to be extractedjava.lang.IndexOutOfBoundsException
- if either index is out of range or if end precedes startpublic ImmList<E> tail()
subList(1, size())
, or equivalently remove(0)
java.lang.IndexOutOfBoundsException
- if the list is emptyprotected ImmList<E> rebalance()
protected java.lang.IndexOutOfBoundsException outOfBounds(int requested, int actual)
requested
- the index value that was requested by the calleractual
- the actual size of the listIndexOutOfBoundsException
with suitable message textCopyright (c) 2004-2020 Saxonica Limited. All rights reserved.