Class XQArray

All Implemented Interfaces:
Iterable<Item>, XQFunction, XQFunctionExpr

public abstract class XQArray extends XQData
An array storing Values.
Author:
BaseX Team 2005-21, BSD License, Leo Woerteler
  • Method Details

    • empty

      public static XQArray empty()
      The empty array. Running time: O(1) and no allocation
      Returns:
      (unique) instance of an empty array
    • singleton

      public static XQArray singleton(Value elem)
      Creates a singleton array containing the given element.
      Parameters:
      elem - the contained element
      Returns:
      the singleton array
    • from

      @SafeVarargs public static XQArray from(Value... values)
      Creates an array containing the given elements.
      Parameters:
      values - elements
      Returns:
      the resulting array
    • cons

      public abstract XQArray cons(Value elem)
      Prepends an element to the front of this array. Running time: O(1)*
      Parameters:
      elem - element to prepend
      Returns:
      resulting array
    • snoc

      public abstract XQArray snoc(Value elem)
      Appends an element to the back of this array. Running time: O(1)*
      Parameters:
      elem - element to append
      Returns:
      resulting array
    • get

      public abstract Value get(long index)
      Gets the element at the given position in this array. Running time: O(log n)
      Parameters:
      index - index of the element to get
      Returns:
      the corresponding element
    • put

      public abstract XQArray put(long pos, Value value)
      Returns a copy of this array where the entry at the given position is replaced by the given value.
      Parameters:
      pos - position of the entry to replace
      value - value to put into this array
      Returns:
      resulting array
    • arraySize

      public abstract long arraySize()
      Returns the number of elements in this array. Running time: O(1)
      Returns:
      number of elements
    • concat

      public abstract XQArray concat(XQArray other)
      Concatenates this array with another one. Running time: O(log (min { this.arraySize(), other.arraySize() }))
      Parameters:
      other - array to append to the end of this array
      Returns:
      resulting array
    • head

      public abstract Value head()
      First element of this array, equivalent to array.get(0). Running time: O(1)
      Returns:
      the first element
    • last

      public abstract Value last()
      Last element of this array, equivalent to array.get(array.arraySize() - 1). Running time: O(1)
      Returns:
      last element
    • init

      public abstract XQArray init()
      Initial segment of this array, i.e. an array containing all elements of this array (in the same order), except for the last one. Running time: O(1)*
      Returns:
      initial segment
    • tail

      public abstract XQArray tail()
      Tail segment of this array, i.e. an array containing all elements of this array (in the same order), except for the first one. Running time: O(1)*
      Returns:
      tail segment
    • subArray

      public abstract XQArray subArray(long pos, long len, QueryContext qc)
      Extracts a contiguous part of this array.
      Parameters:
      pos - position of first element
      len - number of elements
      qc - query context
      Returns:
      the sub-array
    • reverseArray

      public abstract XQArray reverseArray(QueryContext qc)
      Returns an array with the same elements as this one, but their order reversed. Running time: O(n)
      Parameters:
      qc - query context
      Returns:
      reversed version of this array
    • isEmptyArray

      public abstract boolean isEmptyArray()
      Checks if this array is empty. Running time: O(1)
      Returns:
      true if the array is empty, false otherwise
    • insertBefore

      public abstract XQArray insertBefore(long pos, Value value, QueryContext qc)
      Inserts the given element at the given position into this array. Running time: O(log n)
      Parameters:
      pos - insertion position, must be between 0 and arraySize()
      value - element to insert
      qc - query context
      Returns:
      resulting array
    • remove

      public abstract XQArray remove(long pos, QueryContext qc)
      Removes the element at the given position in this array. Running time: O(log n)
      Parameters:
      pos - deletion position, must be between 0 and arraySize() - 1
      qc - query context
      Returns:
      resulting array
    • cache

      public final void cache(boolean lazy, InputInfo ii) throws QueryException
      Description copied from class: Item
      Caches lazy values. Overwritten by Lazy, XQMap and XQArray.
      Overrides:
      cache in class Item
      Parameters:
      lazy - lazy caching
      ii - input info
      Throws:
      QueryException - query exception
    • iterator

      public abstract ListIterator<Value> iterator(long start)
      Iterator over the members of this array.
      Parameters:
      start - starting position (i.e. the position initially returned by ListIterator.nextIndex())
      Returns:
      array over the array members
    • members

      public final Iterable<Value> members()
      Iterator over the members of this array.
      Returns:
      array over the array members
    • get

      public final Value get(Item key, InputInfo ii) throws QueryException
      Description copied from class: XQData
      Gets a value from this item.
      Specified by:
      get in class XQData
      Parameters:
      key - key to look for (must not be null)
      ii - input info
      Returns:
      bound value if found, the empty sequence () otherwise
      Throws:
      QueryException - query exception
    • paramName

      public final QNm paramName(int pos)
      Description copied from interface: XQFunctionExpr
      Name of the parameter at the given position.
      Parameters:
      pos - position of the parameter
      Returns:
      name of the parameter
    • atomValue

      public final Value atomValue(QueryContext qc, InputInfo ii) throws QueryException
      Description copied from class: Item
      Evaluates the expression and returns the atomized items. Overwritten by XQArray, FuncItem and ANode.
      Overrides:
      atomValue in class Item
      Parameters:
      qc - query context
      ii - input info (only required by Seq instances, which have no input info)
      Returns:
      atomized item
      Throws:
      QueryException - query exception
    • atomItem

      public final Item atomItem(QueryContext qc, InputInfo ii) throws QueryException
      Description copied from class: Item
      Evaluates the expression and returns the resulting, atomized item, or Empty.VALUE if the expression yields an empty sequence. Overwritten by XQArray, FuncItem and ANode.
      Overrides:
      atomItem in class Item
      Parameters:
      qc - query context
      ii - input info (only required by Seq instances, which have no input info)
      Returns:
      item or Empty.VALUE
      Throws:
      QueryException - query exception
    • atomSize

      public final long atomSize()
      Description copied from class: Item
      Computes the number of atomized items. Overwritten by XQArray.
      Overrides:
      atomSize in class Item
      Returns:
      atomized item
    • string

      public final void string(boolean indent, TokenBuilder tb, int level, InputInfo ii) throws QueryException
      Description copied from class: XQData
      Returns a string representation of the item.
      Specified by:
      string in class XQData
      Parameters:
      indent - indent output
      tb - token builder
      level - current level
      ii - input info
      Throws:
      QueryException - query exception
    • materialize

      public Item materialize(QueryContext qc, boolean copy)
      Description copied from class: Item
      Returns a materialized, context-independent version of this item.
      Overrides:
      materialize in class Item
      Parameters:
      qc - query context (if null, process cannot be interrupted)
      copy - create full copy
      Returns:
      item copy, or null) if the item cannot be materialized
    • instanceOf

      public boolean instanceOf(Type tp)
      Description copied from class: Item
      Checks if this item is instance of the specified type. Overwritten by XQMap and XQArray.
      Overrides:
      instanceOf in class Item
      Parameters:
      tp - type
      Returns:
      result of check
    • deep

      public final boolean deep(Item item, Collation coll, InputInfo ii) throws QueryException
      Description copied from class: FItem
      Performs a deep comparison of two items.
      Specified by:
      deep in class FItem
      Parameters:
      item - item to be compared
      coll - collation (can be null)
      ii - input info
      Returns:
      result of check
      Throws:
      QueryException - query exception
    • toJava

      public final Object[] toJava() throws QueryException
      Description copied from class: Value
      Returns a Java representation of the value.
      Specified by:
      toJava in class Value
      Returns:
      Java object
      Throws:
      QueryException - query exception
    • description

      public final String description()
      Description copied from class: ExprInfo
      Returns a string description of the expression. This method is only called by error messages. Contrary to the ExprInfo.toString() method, arguments are not included in the output.
      Overrides:
      description in class Item
      Returns:
      result of check
    • plan

      public final void plan(QueryPlan plan)
      Description copied from class: ExprInfo
      Creates a query plan.
      Overrides:
      plan in class Item
      Parameters:
      plan - expression plan
    • plan

      public void plan(QueryString qs)
      Description copied from class: ExprInfo
      Creates a query string.
      Specified by:
      plan in class ExprInfo
      Parameters:
      qs - query string builder