Package net.sf.saxon.ma.arrays
Class SimpleArrayItem
- java.lang.Object
-
- net.sf.saxon.ma.arrays.AbstractArrayItem
-
- net.sf.saxon.ma.arrays.SimpleArrayItem
-
public class SimpleArrayItem extends AbstractArrayItem implements ArrayItem
A simple implementation of XDM array items, in which the array is backed by a Java List.
-
-
Field Summary
Fields Modifier and Type Field Description static SimpleArrayItemEMPTY_ARRAYStatic constant value representing an empty array-
Fields inherited from interface net.sf.saxon.ma.arrays.ArrayItem
SINGLE_ARRAY_TYPE
-
-
Constructor Summary
Constructors Constructor Description SimpleArrayItem(java.util.List<GroundedValue> members)Construct an array whose members are arbitrary sequences
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intarrayLength()Get the size of the arrayArrayItemconcat(ArrayItem other)Concatenate this array with anotherGroundedValueget(int index)Get a member of the arrayAnnotationListgetAnnotations()Get the function annotations (as defined in XQuery).java.util.List<GroundedValue>getMembers()Get a list of the members of the arrayOperandRole[]getOperandRoles()Get the roles of the arguments, for the purposes of streamingArrayIteminsert(int position, GroundedValue member)Insert a new member into an arraybooleanisArray()Ask whether this function item is an arraybooleanisEmpty()Ask whether the array is emptybooleanisMap()Ask whether this function item is a mapvoidmakeGrounded()Ensure that all the members are grounded.static SimpleArrayItemmakeSimpleArrayItem(SequenceIterator input)Construct an array whose members are single itemsjava.lang.Iterable<GroundedValue>members()Get the list of all members of the arrayArrayItemput(int index, GroundedValue newValue)Replace a member of the arrayArrayItemremove(int pos)Remove a member from the arrayArrayItemremoveSeveral(IntSet positions)Remove zero or more members from the arrayArrayItemsubArray(int start, int end)Get a subarray given a start and end positionjava.lang.StringtoShortString()Provide a short string showing the contents of the item, suitable for use in error messages-
Methods inherited from class net.sf.saxon.ma.arrays.AbstractArrayItem
atomize, call, deepEquals, effectiveBooleanValue, export, getArity, getDescription, getFunctionItemType, getFunctionName, getMemberType, getStringValue, getStringValueCS, isTrustedResultType, makeNewContext, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface net.sf.saxon.ma.arrays.ArrayItem
getGenre, getMemberType
-
Methods inherited from interface net.sf.saxon.om.Function
call, deepEquals, export, getArity, getDescription, getFunctionItemType, getFunctionName, isTrustedResultType, makeNewContext
-
Methods inherited from interface net.sf.saxon.om.GroundedValue
asIterable, concatenate, containsNode, effectiveBooleanValue, materialize
-
Methods inherited from interface net.sf.saxon.om.Item
atomize, getLength, getStringValue, getStringValueCS, head, isStreamed, itemAt, iterate, reduce, subsequence
-
Methods inherited from interface net.sf.saxon.om.Sequence
makeRepeatable
-
-
-
-
Field Detail
-
EMPTY_ARRAY
public static final SimpleArrayItem EMPTY_ARRAY
Static constant value representing an empty array
-
-
Constructor Detail
-
SimpleArrayItem
public SimpleArrayItem(java.util.List<GroundedValue> members)
Construct an array whose members are arbitrary sequences- Parameters:
members- the list of values (in general, each value is a sequence) to form the members of the array. The values must be repeatable sequences (not LazySequences); this is not checked.
-
-
Method Detail
-
makeSimpleArrayItem
public static SimpleArrayItem makeSimpleArrayItem(SequenceIterator input) throws XPathException
Construct an array whose members are single items- Parameters:
input- an iterator over the items to make up the array- Returns:
- an array in which each member is a single item, taken from the input sequence
- Throws:
XPathException- if evaluating the SequenceIterator fails
-
getOperandRoles
public OperandRole[] getOperandRoles()
Get the roles of the arguments, for the purposes of streaming- Specified by:
getOperandRolesin interfaceFunction- Overrides:
getOperandRolesin classAbstractArrayItem- Returns:
- an array of OperandRole objects, one for each argument
-
makeGrounded
public void makeGrounded() throws XPathExceptionEnsure that all the members are grounded. The idea is that a member may initially be a reference to a lazily-evaluated sequence, but once computed, the reference will be replaced with the actual value- Throws:
XPathException
-
isArray
public boolean isArray()
Ask whether this function item is an array- Specified by:
isArrayin interfaceFunction- Overrides:
isArrayin classAbstractArrayItem- Returns:
- true (it is an array)
-
isMap
public boolean isMap()
Ask whether this function item is a map- Specified by:
isMapin interfaceFunction- Overrides:
isMapin classAbstractArrayItem- Returns:
- false (it is not a map)
-
getAnnotations
public AnnotationList getAnnotations()
Get the function annotations (as defined in XQuery). Returns an empty list if there are no function annotations.- Specified by:
getAnnotationsin interfaceFunction- Overrides:
getAnnotationsin classAbstractArrayItem- Returns:
- the function annotations
-
get
public GroundedValue get(int index)
Get a member of the array
-
put
public ArrayItem put(int index, GroundedValue newValue)
Replace a member of the array
-
arrayLength
public int arrayLength()
Get the size of the array- Specified by:
arrayLengthin interfaceArrayItem- Returns:
- the number of members in this array
-
isEmpty
public boolean isEmpty()
Ask whether the array is empty
-
members
public java.lang.Iterable<GroundedValue> members()
Get the list of all members of the array
-
removeSeveral
public ArrayItem removeSeveral(IntSet positions)
Remove zero or more members from the array- Specified by:
removeSeveralin interfaceArrayItem- 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
-
remove
public ArrayItem remove(int pos)
Remove a member from the array
-
subArray
public ArrayItem subArray(int start, int end)
Get a subarray given a start and end position- Specified by:
subArrayin interfaceArrayItem- 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:
java.lang.IndexOutOfBoundsException- if start, or start+end, is out of range
-
insert
public ArrayItem insert(int position, GroundedValue member)
Insert a new member into an array
-
getMembers
public java.util.List<GroundedValue> getMembers()
Get a list of the members of the array- Returns:
- the list of members. Note that this returns the actual contained member array, and this is mutable. Changes to this array are permitted only if the caller knows what they are doing, for example during initial construction of an array that will not be presented to the user until construction has finished.
-
toShortString
public java.lang.String toShortString()
Provide a short string showing the contents of the item, suitable for use in error messages- Specified by:
toShortStringin interfaceArrayItem- Specified by:
toShortStringin interfaceFunction- Specified by:
toShortStringin interfaceGroundedValue- Specified by:
toShortStringin interfaceItem- Returns:
- a depiction of the item suitable for use in error messages
-
-