Package net.sf.saxon.ma.arrays
Class ImmutableArrayItem
- java.lang.Object
-
- net.sf.saxon.ma.arrays.ArrayItem
-
- net.sf.saxon.ma.arrays.AbstractArrayItem
-
- net.sf.saxon.ma.arrays.ImmutableArrayItem
-
- All Implemented Interfaces:
Callable
,FunctionItem
,GroundedValue
,Item
,Sequence
public class ImmutableArrayItem extends AbstractArrayItem
Implementation of ArrayItem backed by a persistent immutable array, so that operations that "update" the array do not have to copy the whole array
-
-
Constructor Summary
Constructors Constructor Description ImmutableArrayItem(Iterable<GroundedValue> members)
Create anImmutableArrayItem
, supplying the members of the array as a list (or other iterable) of valuesImmutableArrayItem(SimpleArrayItem other)
Create anImmutableArrayItem
as a copy of a suppliedSimpleArrayItem
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ArrayItem
append(GroundedValue newMember)
Add a member to this arrayint
arrayLength()
Get the number of members in the arrayArrayItem
concat(ArrayItem other)
Concatenate this array with anotherstatic ImmutableArrayItem
from(SequenceIterator iter)
Construct an array whose members are all single items, from the items supplied by aSequenceIterator
GroundedValue
get(int index)
Get a member of the arrayArrayItem
insert(int position, GroundedValue member)
Insert a new member into an arrayboolean
isEmpty()
Ask whether the array is emptyIterable<GroundedValue>
members()
Get the list of all members of the arrayArrayItem
put(int index, GroundedValue newValue)
Replace a member of the arrayArrayItem
remove(int index)
Remove a member from the arrayArrayItem
removeSeveral(IntSet positions)
Remove zero or more members from the arrayArrayItem
subArray(int start, int end)
Get a subarray given a start and end position-
Methods inherited from class net.sf.saxon.ma.arrays.AbstractArrayItem
atomize, call, deepEqual40, deepEquals, effectiveBooleanValue, export, getAnnotations, getArity, getDescription, getFunctionItemType, getFunctionName, getMemberType, getOperandRoles, getUnicodeStringValue, isTrustedResultType, makeNewContext, toString
-
Methods inherited from class net.sf.saxon.ma.arrays.ArrayItem
getGenre, isArray, isMap, parcels, toShortString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface net.sf.saxon.om.FunctionItem
isSequenceVariadic
-
Methods inherited from interface net.sf.saxon.om.GroundedValue
asIterable, concatenate, containsNode, materialize
-
Methods inherited from interface net.sf.saxon.om.Item
getLength, getStringValue, head, isStreamed, itemAt, iterate, reduce, subsequence
-
Methods inherited from interface net.sf.saxon.om.Sequence
makeRepeatable
-
-
-
-
Constructor Detail
-
ImmutableArrayItem
public ImmutableArrayItem(SimpleArrayItem other)
Create anImmutableArrayItem
as a copy of a suppliedSimpleArrayItem
- Parameters:
other
- the suppliedSimpleArrayItem
-
ImmutableArrayItem
public ImmutableArrayItem(Iterable<GroundedValue> members)
Create anImmutableArrayItem
, supplying the members of the array as a list (or other iterable) of values- Parameters:
members
- the supplied collection of members.
-
-
Method Detail
-
from
public static ImmutableArrayItem from(SequenceIterator iter)
Construct an array whose members are all single items, from the items supplied by aSequenceIterator
- Parameters:
iter
- delivers the items to make up the array- Returns:
- an array whose members are single items.
-
get
public GroundedValue get(int index)
Get a member of the array- Specified by:
get
in classArrayItem
- Parameters:
index
- the position of the member to retrieve (zero-based)- Returns:
- the value at the given position.
- Throws:
IndexOutOfBoundsException
- if the index is out of range
-
put
public ArrayItem put(int index, GroundedValue newValue)
Replace a member of the array- Specified by:
put
in classArrayItem
- Parameters:
index
- the position of the member to replace (zero-based)newValue
- the replacement value- Returns:
- the value at the given position.
- Throws:
IndexOutOfBoundsException
- if the index is out of range
-
insert
public ArrayItem insert(int position, GroundedValue member)
Insert a new member into an array- Specified by:
insert
in classArrayItem
- Parameters:
position
- the 0-based position that the new item will assumemember
- the new member to be inserted- Returns:
- a new array item with the new member inserted
- Throws:
IndexOutOfBoundsException
- if position is out of range
-
append
public ArrayItem append(GroundedValue newMember)
Add a member to this array
-
arrayLength
public int arrayLength()
Get the number of members in the arrayNote: the
method always returns 1, because an array is an item
- Specified by:
arrayLength
in classArrayItem
- Returns:
- the number of members in this array.
-
isEmpty
public boolean isEmpty()
Ask whether the array is empty
-
members
public Iterable<GroundedValue> members()
Get the list of all members of the array
-
subArray
public ArrayItem subArray(int start, int end)
Get a subarray given a start and end position- Specified by:
subArray
in classArrayItem
- Parameters:
start
- the start position (zero based)end
- the end position (the position of the first item not to be returned) (zero based)- Returns:
- a new array item containing the sub-array
- Throws:
IndexOutOfBoundsException
- if start, or start+end, is out of range
-
remove
public ArrayItem remove(int index)
Remove a member from the array- Specified by:
remove
in classArrayItem
- Parameters:
index
- the position of the member to be removed (zero-based)- Returns:
- a new array in which the requested member has been removed.
- Throws:
IndexOutOfBoundsException
- if index is out of range
-
removeSeveral
public ArrayItem removeSeveral(IntSet positions)
Remove zero or more members from the array- Specified by:
removeSeveral
in classArrayItem
- Parameters:
positions
- the positions of the members to be removed (zero-based). A value that is out of range is ignored.- Returns:
- a new array in which the requested member has been removed
-
-