Package com.singularsys.jep.misc.overloadedfunctions

# Class OverloadedOperator

java.lang.Object
com.singularsys.jep.Operator
com.singularsys.jep.misc.overloadedfunctions.OverloadedOperator

All Implemented Interfaces:
  `Serializable`

public class OverloadedOperator extends Operator
An operator representing two alternative operators that can be used in alternative contexts based on the structure of the node. Two alternative operators are defined and the `OverloadResolver` will substitute the appropriate one when it visits the node.

See Also:
  - Serialized Form

- ## Field Summary

  ### Fields inherited from class com.singularsys.jep.Operator

  `ASSOCIATIVE, BINARY, COMMUTATIVE, COMPOSITE, EQUIVALENCE, flags, key, LEFT, name, NARY, NO_ARGS, NOT_IN_PARSER, pfmc, precedence, PREFIX, printSymbol, REFLEXIVE, RIGHT, SELF_INVERSE, SUFFIX, symbol, SYMMETRIC, TERNARY, TRANSITIVE, UNARY, USE_BINDING_FOR_PRINT`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `OverloadedOperator(String name, String symbol, Operator op1, Operator op2, Predicate<Node> pred, int flags, int prec)`
  Constructor.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static void`
  `applyPrintRules(OverloadedOperator op, Jep jep)`
  Apply the `PrintVisitor.PrintRulesI` to an operators created using `extendOperator(OperatorTable2, PostfixMathCommandI, Operator, Predicate, OperatorKey, OperatorKey, OperatorKey)`.
  `static OverloadedOperator`
  `extendOperator(Jep jep, PostfixMathCommandI fun1, Operator originalOp, Predicate<Node> pred, EmptyOperatorTable.OperatorKey overKey, EmptyOperatorTable.OperatorKey altKey, EmptyOperatorTable.OperatorKey origKey)`
  Extends an existing operator to form an overloaded operator, using a additional function and predicate, and add them to the Jep instance.
  `static OverloadedOperator`
  `extendOperator(OperatorTable2 ot, PostfixMathCommandI fun1, Operator originalOp, Predicate<Node> pred, EmptyOperatorTable.OperatorKey overKey, EmptyOperatorTable.OperatorKey altKey, EmptyOperatorTable.OperatorKey originalKey)`
  Extends an existing operator to form an overloaded operator, using a additional function and predicate, and add them to the OperatorTable, does not set the PrintRules.
  `Operator`
  `getOp1()`
  `Operator`
  `getOp2()`
  `Operator`
  `getOpFor(Node n)`
  Run the predicate against a node, returning the corresponding operator.
  `Predicate<Node>`
  `getPredicate()`

  ### Methods inherited from class com.singularsys.jep.Operator

  `addAltSymbol, duplicate, getAltSymbols, getBinaryInverseOp, getBinding, getFlags, getInverseOp, getKey, getName, getPFMC, getPrecedence, getPrintSymbol, getRootOp, getSymbol, isAssociative, isBinary, isCommutative, isComposite, isDistributiveOver, isEquivalence, isLeftBinding, isNary, isPrefix, isReflexive, isRightBinding, isSelfInverse, isSuffix, isSymmetric, isTernary, isTransitive, isUnary, notInParser, numArgs, setBinaryInverseOp, setDistributiveOver, setFlag, setInverseOp, setKey, setPFMC, setPrecedence, setPrintSymbol, setRootOp, setSymbol, toFullString, toString, useBindingForPrint`

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

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

- ## Constructor Details

  - ### OverloadedOperator

    public OverloadedOperator(String name, String symbol, Operator op1, Operator op2, Predicate<Node> pred, int flags, int prec)
    Constructor. The two component operators should both have the same symbol and precedence. The flags for all three operators should be the same, apart from the NOT_IN_PARSER flag which should be set for the two component operators, and unset for the overloaded operator. All three operators should be added to the operator table.
    Parameters:
      `name` - unique name of the operator
      `symbol` - the symbol for the operator
      `op1` - the first operator, used if the predicate returns true
      `op2` - the second operator, used if the predicate returns false
      `pred` - a predicate that tests the structure of the parse tree
      `flags` - the flags for the operator, see `Operator`
      `prec` - the precedence of the operator

- ## Method Details

  - ### getOp1

    public Operator getOp1()

  - ### getOp2

    public Operator getOp2()

  - ### getPredicate

    public Predicate<Node> getPredicate()

  - ### getOpFor

    public Operator getOpFor(Node n)
    Run the predicate against a node, returning the corresponding operator.
    Parameters:
      `n` - node to test
    Returns:
      the selected operator

  - ### extendOperator

    public static OverloadedOperator extendOperator(Jep jep, PostfixMathCommandI fun1, Operator originalOp, Predicate<Node> pred, EmptyOperatorTable.OperatorKey overKey, EmptyOperatorTable.OperatorKey altKey, EmptyOperatorTable.OperatorKey origKey)
    Extends an existing operator to form an overloaded operator, using a additional function and predicate, and add them to the Jep instance.

    This method creates three operators:

    - The original operator that will be used when the predicate returns false.
    - An alternate operator that will be used when the predicate returns true. This uses the supplied PostfixMathCommand.
    - An OverloadedOperator that will be used in parsing.

    The three operators share the same, precedence, symbol and flags but the first two have the NO_IN_PARSER flag set. All three operators are added to the operator table. If the PrintVisitor has a special rule for the original operator then rules are also added for the alternate operator and overloaded operator. Names for alternate operator and overloaded operator are constructed using message properties.

    Parameters:
      `jep` - Jep instance
      `fun1` - pfmc used by first operator
      `originalOp` - existing operator
      `pred` - predicate used to test the node
      `overKey` - key for the overloaded operator
      `altKey` - key for the alternate operator
      `origKey` - key for the original operator
    Returns:
      a new OverloadedOperator

  - ### applyPrintRules

    public static void applyPrintRules(OverloadedOperator op, Jep jep)
    Apply the `PrintVisitor.PrintRulesI` to an operators created using `extendOperator(OperatorTable2, PostfixMathCommandI, Operator, Predicate, OperatorKey, OperatorKey, OperatorKey)`. This method takes the rule, if specified, for the second operator and applies it to the root operator and the second operator.
    Parameters:
      `op` -
      `jep` -

  - ### extendOperator

    public static OverloadedOperator extendOperator(OperatorTable2 ot, PostfixMathCommandI fun1, Operator originalOp, Predicate<Node> pred, EmptyOperatorTable.OperatorKey overKey, EmptyOperatorTable.OperatorKey altKey, EmptyOperatorTable.OperatorKey originalKey)
    Extends an existing operator to form an overloaded operator, using a additional function and predicate, and add them to the OperatorTable, does not set the PrintRules.

    This method creates three operators:

    - The original operator that will be used when the predicate returns false.
    - An alternate operator that will be used when the predicate returns true. This uses the supplied PostfixMathCommand.
    - An OverloadedOperator that will be used in parsing.

    The three operators share the same, precedence, symbol and flags but the first two have the NO_IN_PARSER flag set. All three operators are added to the operator table. Names for alternate operator and overloaded operator are constructed using message properties.

    If the `PrintVisitor.PrintRulesI` of the operators need to be set call `applyPrintRules(OverloadedOperator, Jep)` when the Jep instance is available.

    Parameters:
      `ot` - the operator table to which the operators should be added
      `fun1` - pfmc used by first operator
      `originalOp` - existing operator
      `pred` - predicate used to test the node
      `overKey` - key for the overloaded operator
      `altKey` - key for the alternate operator
      `originalKey` - key for the original operator
    Returns:
      a new OverloadedOperator