Class Seq

All Implemented Interfaces:
Iterable<Item>
Direct Known Subclasses:
BlnSeq, BytSeq, DblSeq, DBNodeSeq, DecSeq, FltSeq, IntSeq, ItemSeq, RangeSeq, SingletonSeq, StrSeq, SubSeq, TreeSeq

public abstract class Seq extends Value
Sequence, containing at least two items.
Author:
BaseX Team 2005-21, BSD License, Christian Gruen
  • Field Details

    • size

      protected long size
      Length.
  • Constructor Details

    • Seq

      protected Seq(long size, Type type)
      Constructor, specifying a type.
      Parameters:
      size - size
      type - exact type, item()* otherwise
  • Method Details

    • toJava

      public 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
    • size

      public final long size()
      Description copied from class: Expr
      Returns the result size, or -1 if the size is unknown.
      Specified by:
      size in class Expr
      Returns:
      result of check
    • item

      public final Item item(QueryContext qc, InputInfo ii) throws QueryException
      Description copied from class: Expr
      Evaluates the expression and returns the resulting item, or Empty.VALUE if the expression yields an empty sequence. If this method is not implemented, Expr.value(QueryContext) must be implemented instead.
      Specified by:
      item in class Expr
      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
    • test

      public final Item test(QueryContext qc, InputInfo ii) throws QueryException
      Description copied from class: Expr
      Performs a predicate test and returns the item if the test was successful. The returned item is required for full-text scoring.
      Specified by:
      test in class Expr
      Parameters:
      qc - query context
      ii - input info (required for Seq instances, which have no input info)
      Returns:
      item or null
      Throws:
      QueryException - query exception
    • iter

      public BasicIter<Item> iter()
      Description copied from class: Value
      Returns an iterator.
      Specified by:
      iter in class Value
      Returns:
      iterator
    • ddo

      public boolean ddo()
      Description copied from class: Expr
      Indicates if this expression returns nodes in document order without duplicates.
      Overrides:
      ddo in class Expr
      Returns:
      result of check
    • subsequence

      public final Value subsequence(long start, long length, QueryContext qc)
      Description copied from class: Value
      Returns a subsequence of this value with the given start and length. The following properties must hold:
      • start >= 0,
      • length >= 0,
      • length <= size() - start
      Specified by:
      subsequence in class Value
      Parameters:
      start - starting position
      length - number of items
      qc - query context
      Returns:
      sub sequence
    • subSeq

      protected Seq subSeq(long offset, long length, QueryContext qc)
      Returns a sub sequence of this value with the given start and length.
      Parameters:
      offset - offset (ge 0)
      length - number of items (1 lt length lt size())
      qc - query context
      Returns:
      sub sequence
    • insertBefore

      public final Value insertBefore(long pos, Value value, QueryContext qc)
      Inserts a value at the given position into this sequence and returns the resulting sequence.
      Parameters:
      pos - position at which the value should be inserted, must be between 0 and size
      value - value to insert
      qc - query context
      Returns:
      resulting value
    • insert

      public abstract Value insert(long pos, Item item, QueryContext qc)
      Inserts an item at the given position into this sequence and returns the resulting sequence.
      Parameters:
      pos - position at which the item should be inserted, must be between 0 and size
      item - item to insert
      qc - query context
      Returns:
      resulting value
    • copyInsert

      protected Value copyInsert(long pos, Value value, QueryContext qc)
      Helper for insertBefore(long, Value, QueryContext) that copies all items into a TreeSeq.
      Parameters:
      pos - position at which the value should be inserted, must be between 0 and size
      value - value to insert
      qc - query context
      Returns:
      resulting value
    • remove

      public abstract Value remove(long pos, QueryContext qc)
      Removes the item at the given position in this sequence and returns the resulting sequence.
      Parameters:
      pos - position of the item to remove, must be between 0 and size - 1
      qc - query context
      Returns:
      resulting sequence
    • refineType

      public final void refineType(Expr expr)
      Description copied from class: Expr
      Refines the expression type.
      Specified by:
      refineType in class Expr
      Parameters:
      expr - original expression
    • hash

      public final int hash(InputInfo ii) throws QueryException
      Description copied from class: Value
      Returns a hash code for this value.
      Specified by:
      hash in class Value
      Parameters:
      ii - input info
      Returns:
      hash code
      Throws:
      QueryException - if atomization can't be applied (e.g. function item)
    • seqType

      public final SeqType seqType()
      Description copied from class: Expr
      Returns the static type of the resulting value.
      Specified by:
      seqType in class Expr
      Returns:
      result of check
    • equals

      public boolean equals(Object obj)
      Description copied from class: Expr
      This function is e.g. called by:
      Specified by:
      equals in class Expr
    • description

      public 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 ExprInfo
      Returns:
      result of check
    • plan

      public void plan(QueryPlan plan)
      Description copied from class: ExprInfo
      Creates a query plan.
      Specified by:
      plan in class ExprInfo
      Parameters:
      plan - expression plan
    • toErrorString

      public final String toErrorString()
      Description copied from class: ExprInfo
      Returns a string representation of the expression that can be embedded in error messages. Defaults to ExprInfo.toString().
      Overrides:
      toErrorString in class ExprInfo
      Returns:
      class name
    • 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
    • get

      public static Value get(int size, Type type, Value... values) throws QueryException
      Tries to create a typed sequence with the items of the specified values.
      Parameters:
      size - size of resulting sequence
      values - values
      type - type
      Returns:
      value, or null if sequence could not be created
      Throws:
      QueryException - query exception
    • initialCapacity

      public static int initialCapacity(long size) throws QueryException
      Returns an initial array capacity for the expected result size. Throws an exception if the requested size will take too much memory.
      Parameters:
      size - expected result size
      Returns:
      capacity
      Throws:
      QueryException - query exception