Class LabeledArrayItem

All Implemented Interfaces:
LabeledItem, Callable, FunctionItem, GroundedValue, Item, Sequence

public class LabeledArrayItem extends DelegatingArrayItem implements LabeledItem
A LabeledArrayItem represents an XDM array together with a label, which is a map: generally containing retained information about how the array was selected within a JSON-like tree.
  • Constructor Details

    • LabeledArrayItem

      public LabeledArrayItem(ArrayItem base, MapItem label)
      Create a PedigreeArrayItem with an empty pedigree
      Parameters:
      base - the underlying array item
  • Method Details

    • getSubject

      public ArrayItem getSubject()
      Description copied from interface: LabeledItem
      Get the subject item without its label
      Specified by:
      getSubject in interface LabeledItem
      Returns:
      the subject item
    • makePinnedArrayItem

      public static LabeledArrayItem makePinnedArrayItem(ArrayItem base)
    • get

      public GroundedValue get(int index)
      Get the member of the array at a specified index, retaining information about how that member was selected
      Overrides:
      get in class DelegatingArrayItem
      Parameters:
      index - the zero-based subscript of the selected member of the array
      Returns:
      the requested array member, which will itself have a pedigree if it is a singleton map or array.
      Throws:
      IndexOutOfBoundsException - if the index is out of bounds
    • getIfPresent

      public GroundedValue getIfPresent(int index)
      Get a member of the array at a specific offset, or an empty sequence if the supplied offset is out of range
      Overrides:
      getIfPresent in class DelegatingArrayItem
      Parameters:
      index - the position of the member to retrieve (zero-based)
      Returns:
      the value at the given position, or an empty sequence if the index is out of range
    • members

      public Iterable<GroundedValue> members()
      Description copied from class: ArrayItem
      Get the list of all members of the array
      Overrides:
      members in class DelegatingArrayItem
      Returns:
      an iterator over the members of the array
    • remove

      public ArrayItem remove(int index)
      Get all members of the array except that at a specified position, retaining information about how the remaining members were selected
      Overrides:
      remove in class DelegatingArrayItem
      Parameters:
      index - the zero-based subscript of the member of the array that is to be removed
      Returns:
      the remaining array members, which will themselves have a pedigree (indicating their original position in the original array) in the case of members that are singleton maps or arrays.
      Throws:
      IndexOutOfBoundsException - if the index is out of bounds
    • removeSeveral

      public ArrayItem removeSeveral(IntSet positions)
      Description copied from class: ArrayItem
      Remove zero or more members from the array
      Overrides:
      removeSeveral in class DelegatingArrayItem
      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
    • subArray

      public ArrayItem subArray(int start, int end)
      Get a sub-array given a start and end position
      Overrides:
      subArray in class DelegatingArrayItem
      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
    • getLabel

      public MapItem getLabel()
      Get the pedigree of this array item, providing information as to how it was selected.
      Specified by:
      getLabel in interface Item
      Specified by:
      getLabel in interface LabeledItem
      Returns:
      the pedigree of this array item
    • getBaseItem

      public ArrayItem getBaseItem()
      Overrides:
      getBaseItem in class DelegatingArrayItem
    • toString

      public String toString()
      Description copied from class: AbstractArrayItem
      Output a string representation of the array, suitable for diagnostics
      Overrides:
      toString in class AbstractArrayItem