Package net.sf.saxon.ma.parray
Class ImmList<E>
java.lang.Object
net.sf.saxon.ma.parray.ImmList<E>
- Type Parameters:
E
- the type of the elements in the list
- All Implemented Interfaces:
Iterable<E>
An immutable list of elements
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAppend an element at the end of the listappendList
(ImmList<E> members) Append multiple elements at the end of the liststatic <E> ImmList<E>
empty()
Return an empty liststatic <E> ImmList<E>
Construct an immutable list from a Java list of membersabstract E
get
(int index) Get the element at a given indexhead()
Get the first element in the listInsert an element at a given positionabstract boolean
isEmpty()
Ask if the list is emptyprotected IndexOutOfBoundsException
outOfBounds
(int requested, int actual) Convenience method for use by subclasses to throw an IndexOutOfBounds exception when neededstatic <E> ImmList<E>
pair
(E first, E second) Return a list of length 2 (two)Return a list containing the same elements as this list, but optimized for efficient accessremove
(int index) Remove the member at a given positionReplace the element at a given indexstatic <E> ImmList<E>
singleton
(E member) Return a singleton list (a list containing one item)abstract int
size()
Get the size of the listsubList
(int start, int end) Return a sub-sequence with a given start and end positiontail()
Get a list containing all elements of the list except the firstMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, iterator, spliterator
-
Constructor Details
-
ImmList
public ImmList()
-
-
Method Details
-
empty
Return an empty list- Type Parameters:
E
- the (nominal) type of the list element- Returns:
- an empty immutable list
-
singleton
Return a singleton list (a list containing one item)- Type Parameters:
E
- the type of the list members- Parameters:
member
- the single member of the list- Returns:
- the singleton list
-
pair
Return a list of length 2 (two)- Type Parameters:
E
- the type of the list members- Parameters:
first
- the first member of the listsecond
- the second member of the list- Returns:
- the two-member list
-
fromList
Construct an immutable list from a Java list of members- Type Parameters:
E
- the type of the list members- Parameters:
members
- the members to be added to the list- Returns:
- the immutable list
-
get
Get the element at a given index- Parameters:
index
- the required index (zero-based)- Returns:
- the element at the given index
- Throws:
IndexOutOfBoundsException
- if the index is out of range
-
head
Get the first element in the list- Returns:
- the result of get(0)
- Throws:
IndexOutOfBoundsException
- if the list is empty
-
size
public abstract int size()Get the size of the list- Returns:
- the number of members in the list
-
isEmpty
public abstract boolean isEmpty()Ask if the list is empty- Returns:
- true if the list contains no elements, otherwise false
-
replace
Replace the element at a given index- Parameters:
index
- the index (zero-based) of the element to be replacedmember
- the replacement member to be included in the new list- Returns:
- a new list, identical to the old except for the replacement of one member
- Throws:
IndexOutOfBoundsException
- if the index is out of range
-
insert
Insert an element at a given position- Parameters:
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 list- Returns:
- a new list, identical to the old except for the addition of one member
- Throws:
IndexOutOfBoundsException
- if the index is out of range
-
append
Append an element at the end of the list- Parameters:
member
- the new member to be included in the new list- Returns:
- a new list, identical to the old except for the addition of one member
-
appendList
Append multiple elements at the end of the list- Parameters:
members
- the new members to be included in the new list- Returns:
- a new list, identical to the old except for the addition of new members
-
remove
Remove the member at a given position- Parameters:
index
- the zero-based index position of the member to be removed- Returns:
- a new list, identical to the old except for the removal of one member
- Throws:
IndexOutOfBoundsException
- if the index is out of range
-
subList
Return a sub-sequence with a given start and end position- Parameters:
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 extracted- Returns:
- a new list containing the elements from the specified range of positions
- Throws:
IndexOutOfBoundsException
- if either index is out of range or if end precedes start
-
tail
Get a list containing all elements of the list except the first- Returns:
- the result of
subList(1, size())
, or equivalentlyremove(0)
- Throws:
IndexOutOfBoundsException
- if the list is empty
-
rebalance
Return a list containing the same elements as this list, but optimized for efficient access- Returns:
- either this list, or a copy containing the same elements in the same order
-
outOfBounds
Convenience method for use by subclasses to throw an IndexOutOfBounds exception when needed- Parameters:
requested
- the index value that was requested by the calleractual
- the actual size of the list- Returns:
- an
IndexOutOfBoundsException
with suitable message text
-