Package net.sf.saxon.expr.sort

## Class ConditionalSorter

- java.lang.Object
- - net.sf.saxon.expr.Expression
  - - net.sf.saxon.expr.sort.ConditionalSorter

- All Implemented Interfaces:
    `ExportAgent`, `Locatable`, `IdentityComparable`, `Traceable`

      public class ConditionalSorter
      extends Expression

  An expression that sorts an underlying sequence into document order if some condition is true, or that returns the sequence "as is" (knowing that it doesn't need sorting) if the condition is false.

- - ### Field Summary

    - ### Fields inherited from class net.sf.saxon.expr.Expression

      `EFFECTIVE_BOOLEAN_VALUE, EVALUATE_METHOD, ITEM_FEED_METHOD, ITERATE_METHOD, MAX_COST, MAX_SEQUENCE_LENGTH, MAX_STRING_LENGTH, PROCESS_METHOD, staticProperties, UNBOUNDED_LOWER, UNBOUNDED_UPPER, UPDATE_METHOD, WATCH_METHOD`

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `ConditionalSorter​(Expression condition, DocumentSorter sorter)` | Create a conditional document sorter

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `protected int` | `computeCardinality()` | Compute the static cardinality of this expression
    `protected int` | `computeSpecialProperties()` | Compute the special properties of this expression.
    `Expression` | `copy​(RebindingMap rebindings)` | Copy an expression.
    `void` | `export​(ExpressionPresenter out)` | Diagnostic print of expression structure.
    `int` | `getCardinality()` | Determine the static cardinality of the expression.
    `Expression` | `getCondition()` | Get the condition under which the nodes need to be sorted
    `DocumentSorter` | `getDocumentSorter()` | Get the document sorter, which sorts the nodes if the condition is true
    `java.lang.String` | `getExpressionName()` | Get a name identifying the kind of expression, in terms meaningful to a user.
    `int` | `getImplementationMethod()` | An implementation of Expression must provide at least one of the methods evaluateItem(), iterate(), or process().
    `ItemType` | `getItemType()` | Determine the data type of the expression, if possible.
    `SequenceIterator` | `iterate​(XPathContext context)` | Return an Iterator to iterate over the values of a sequence.
    `java.lang.Iterable<Operand>` | `operands()` | Get the immediate sub-expressions of this expression, with information about the relationship of each expression to its parent expression.
    `Expression` | `optimize​(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo)` | Perform optimisation of an expression and its subexpressions.
    `void` | `setCondition​(Expression condition)` |
    `void` | `setDocumentSorter​(DocumentSorter documentSorter)` |
    `Expression` | `simplify()` | Simplify an expression.
    `Expression` | `typeCheck​(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo)` | Perform type checking of an expression and its subexpressions.
    `Expression` | `unordered​(boolean retainAllNodes, boolean forStreaming)` | Replace this expression by a simpler expression that delivers the results without regard to order.

    - ### Methods inherited from class net.sf.saxon.expr.Expression

      `addToPathMap, adoptChildExpression, allowExtractingCommonSubexpressions, checkedOperands, checkForUpdatingSubexpressions, checkPermittedContents, computeDependencies, computeHashCode, computeStaticProperties, dynamicError, effectiveBooleanValue, equals, evaluateAsString, evaluateItem, evaluatePendingUpdates, explain, getConfiguration, getCost, getDependencies, getEvaluationMethod, getExtraProperty, getIntegerBounds, getInterpretedExpression, getIntrinsicDependencies, getLocalRetainedStaticContext, getLocation, getNetCost, getObjectName, getPackageData, getParentExpression, getProperties, getProperty, getRetainedStaticContext, getScopingExpression, getSlotsUsed, getSpecialProperties, getStaticBaseURI, getStaticBaseURIString, getStaticType, getStaticUType, getStreamerName, getTracingTag, hasCompatibleStaticContext, hashCode, hasSpecialProperty, hasVariableBinding, identityHashCode, implementsStaticTypeCheck, isCallOn, isEqual, isIdentical, isInstruction, isLiftable, isMultiThreaded, isStaticPropertiesKnown, isSubtreeExpression, isUpdatingExpression, isVacuousExpression, markTailFunctionCalls, operandList, operandSparseList, optimizeChildren, prepareForStreaming, process, resetLocalStaticProperties, restoreParentPointers, setEvaluationMethod, setExtraProperty, setFiltered, setFlattened, setLocation, setParentExpression, setRetainedStaticContext, setRetainedStaticContextLocally, setRetainedStaticContextThoroughly, setStaticProperty, simplifyChildren, staticTypeCheck, suppressValidation, toPattern, toShortString, toString, typeCheckChildren, typeError, verifyParentPointers`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

    - ### Methods inherited from interface net.sf.saxon.trace.Traceable

      `gatherProperties`

- - ### Constructor Detail

    - #### ConditionalSorter

          public ConditionalSorter​(Expression condition,
                                   DocumentSorter sorter)

      Create a conditional document sorter
      Parameters:
        `condition` - the conditional expression
        `sorter` - the sorting expression

  - ### Method Detail

    - #### operands

          public java.lang.Iterable<Operand> operands()

      Description copied from class: `Expression`
      Get the immediate sub-expressions of this expression, with information about the relationship of each expression to its parent expression. Default implementation works off the results of iterateSubExpressions()

      If the expression is a Callable, then it is required that the order of the operands returned by this function is the same as the order of arguments supplied to the corresponding call() method.

      Overrides:
        `operands` in class `Expression`
      Returns:
        an iterator containing the sub-expressions of this expression

    - #### setCondition

          public void setCondition​(Expression condition)

    - #### setDocumentSorter

          public void setDocumentSorter​(DocumentSorter documentSorter)

    - #### getCondition

          public Expression getCondition()

      Get the condition under which the nodes need to be sorted
      Returns:
        the condition (an expression)

    - #### getDocumentSorter

          public DocumentSorter getDocumentSorter()

      Get the document sorter, which sorts the nodes if the condition is true
      Returns:
        the document sorter

    - #### simplify

          public Expression simplify()
                              throws XPathException

      Description copied from class: `Expression`
      Simplify an expression. This performs any static optimization (by rewriting the expression as a different expression). The default implementation simplifies its operands.
      Overrides:
        `simplify` in class `Expression`
      Returns:
        the simplified expression (or the original if unchanged, or if modified in-situ)
      Throws:
        `XPathException` - if an error is discovered during expression rewriting

    - #### typeCheck

          public Expression typeCheck​(ExpressionVisitor visitor,
                                      ContextItemStaticInfo contextInfo)
                               throws XPathException

      Perform type checking of an expression and its subexpressions. This is the second phase of static optimization.
      Overrides:
        `typeCheck` in class `Expression`
      Parameters:
        `visitor` - an expression visitor
        `contextInfo` - Information available statically about the context item: whether it is (possibly) absent; its static type; its streaming posture.
      Returns:
        the original expression, rewritten to perform necessary run-time type checks, and to perform other type-related optimizations
      Throws:
        `XPathException` - if an error is discovered during this phase (typically a type error)

    - #### getCardinality

          public int getCardinality()

      Determine the static cardinality of the expression. This establishes how many items there will be in the result of the expression, at compile time (i.e., without actually evaluating the result.
      Overrides:
        `getCardinality` in class `Expression`
      Returns:
        one of the values Cardinality.ONE_OR_MORE, Cardinality.ZERO_OR_MORE, Cardinality.EXACTLY_ONE, Cardinality.ZERO_OR_ONE, Cardinality.EMPTY. This default implementation returns ZERO_OR_MORE (which effectively gives no information).

    - #### computeSpecialProperties

          protected int computeSpecialProperties()

      Compute the special properties of this expression. These properties are denoted by a bit-significant integer, possible values are in class `StaticProperty`. The "special" properties are properties other than cardinality and dependencies, and most of them relate to properties of node sequences, for example whether the nodes are in document order.
      Overrides:
        `computeSpecialProperties` in class `Expression`
      Returns:
        the special properties, as a bit-significant integer

    - #### getImplementationMethod

          public int getImplementationMethod()

      An implementation of Expression must provide at least one of the methods evaluateItem(), iterate(), or process(). This method indicates which of these methods is provided directly. The other methods will always be available indirectly, using an implementation that relies on one of the other methods.
      Specified by:
        `getImplementationMethod` in class `Expression`
      Returns:
        the implementation method, for example `Expression.ITERATE_METHOD` or `Expression.EVALUATE_METHOD` or `Expression.PROCESS_METHOD`

    - #### optimize

          public Expression optimize​(ExpressionVisitor visitor,
                                     ContextItemStaticInfo contextInfo)
                              throws XPathException

      Description copied from class: `Expression`
      Perform optimisation of an expression and its subexpressions. This is the third and final phase of static optimization.

      This method is called after all references to functions and variables have been resolved to the declaration of the function or variable, and after all type checking has been done.

      Overrides:
        `optimize` in class `Expression`
      Parameters:
        `visitor` - an expression visitor
        `contextInfo` - the static type of "." at the point where this expression is invoked. The parameter is set to null if it is known statically that the context item will be undefined. If the type of the context item is not known statically, the argument is set to `Type.ITEM_TYPE`
      Returns:
        the original expression, rewritten if appropriate to optimize execution
      Throws:
        `XPathException` - if an error is discovered during this phase (typically a type error)

    - #### unordered

          public Expression unordered​(boolean retainAllNodes,
                                      boolean forStreaming)
                               throws XPathException

      Description copied from class: `Expression`
      Replace this expression by a simpler expression that delivers the results without regard to order.
      Overrides:
        `unordered` in class `Expression`
      Parameters:
        `retainAllNodes` - set to true if the result must contain exactly the same nodes as the original; set to false if the result can eliminate (or introduce) duplicates.
        `forStreaming` - set to true if the result is to be optimized for streaming
      Returns:
        an expression that delivers the same nodes in a more convenient order
      Throws:
        `XPathException` - if the rewrite fails

    - #### computeCardinality

          protected int computeCardinality()

      Compute the static cardinality of this expression
      Specified by:
        `computeCardinality` in class `Expression`
      Returns:
        the computed cardinality, as one of the values `StaticProperty.ALLOWS_ZERO_OR_ONE`, `StaticProperty.EXACTLY_ONE`, `StaticProperty.ALLOWS_ONE_OR_MORE`, `StaticProperty.ALLOWS_ZERO_OR_MORE`

    - #### copy

          public Expression copy​(RebindingMap rebindings)

      Copy an expression. This makes a deep copy.
      Specified by:
        `copy` in class `Expression`
      Parameters:
        `rebindings` -
      Returns:
        the copy of the original expression

    - #### export

          public void export​(ExpressionPresenter out)
                      throws XPathException

      Diagnostic print of expression structure. The abstract expression tree is written to the supplied output destination.
      Specified by:
        `export` in interface `ExportAgent`
      Specified by:
        `export` in class `Expression`
      Parameters:
        `out` - the expression presenter used to display the structure
      Throws:
        `XPathException` - if the export fails, for example if an expression is found that won't work in the target environment.

    - #### getItemType

          public ItemType getItemType()

      Determine the data type of the expression, if possible. All expression return sequences, in general; this method determines the type of the items within the sequence, assuming that (a) this is known in advance, and (b) it is the same for all items in the sequence.

      This method should always return a result, though it may be the best approximation that is available at the time.

      Specified by:
        `getItemType` in class `Expression`
      Returns:
        a value such as Type.STRING, Type.BOOLEAN, Type.NUMBER, Type.NODE, or Type.ITEM (meaning not known at compile time)

    - #### iterate

          public SequenceIterator iterate​(XPathContext context)
                                   throws XPathException

      Return an Iterator to iterate over the values of a sequence. The value of every expression can be regarded as a sequence, so this method is supported for all expressions. This default implementation handles iteration for expressions that return singleton values: for non-singleton expressions, the subclass must provide its own implementation.
      Overrides:
        `iterate` in class `Expression`
      Parameters:
        `context` - supplies the context for evaluation
      Returns:
        a SequenceIterator that can be used to iterate over the result of the expression
      Throws:
        `XPathException` - if any dynamic error occurs evaluating the expression

    - #### getExpressionName

          public java.lang.String getExpressionName()

      Get a name identifying the kind of expression, in terms meaningful to a user.
      Overrides:
        `getExpressionName` in class `Expression`
      Returns:
        a name identifying the kind of expression, in terms meaningful to a user. The name will always be in the form of a lexical XML QName, and should match the name used in export() output displaying the expression.