public class Operator
extends java.lang.Object
implements java.io.Serializable
Operators have a number of properties:
Modifier and Type | Field and Description |
---|---|
static int |
ASSOCIATIVE
Associative operators x*(y*z) == (x*y)*z .
|
static int |
BINARY
Binary operators, such as x+y, x>y
|
static int |
COMMUTATIVE
Commutative operators x*y = y*x.
|
static int |
COMPOSITE
composite operators, like a-b which is a+(-b)
|
static int |
EQUIVALENCE
Equivalence relations = reflexive, transitive and symmetric.
|
protected int |
flags
Flags for type of operator
Access level changed to protected in version 3.5
|
protected int |
key
Key used to identify the operator in the operator table
Access level changed to protected in version 3.5
|
static int |
LEFT
Left binding like +: 1+2+3 -> (1+2)+3
|
protected java.lang.String |
name
A unique name defining the operator.
|
static int |
NARY
Trinary ops such as ?
|
static int |
NO_ARGS
No arguments to operator
|
static int |
NOT_IN_PARSER
Non standard operators, like array access.
|
protected PostfixMathCommandI |
pfmc
The PostfixMathCommandI for evaluating
Access level changed to protected in version 3.5
|
protected int |
precedence
Precedence of operator, 0 is most tightly bound, so prec("*") < prec("+").
|
static int |
PREFIX
prefix operators -x
|
protected java.lang.String |
printSymbol
The symbol for the operator, used for printing.
|
static int |
REFLEXIVE
Reflective relations x=x for all x.
|
static int |
RIGHT
Right binding like =: 1=2=3 -> 1=(2=3)
|
static int |
SELF_INVERSE
self inverse operators like -(-x) !
|
static int |
SUFFIX
postfix operators x%
|
protected java.lang.String |
symbol
The symbol for the operator, used for printing.
|
static int |
SYMMETRIC
Symmetric relation x=y implies y=x.
|
static int |
TERNARY
three argument operators like java's cond?
|
static int |
TRANSITIVE
Transitive relations x=y and y=z implies x=z
|
static int |
UNARY
Unary operators, such as -x !
|
static int |
USE_BINDING_FOR_PRINT
For non commutative operators printing can be determined by the left or right binding.
|
Constructor and Description |
---|
Operator(java.lang.String name,
PostfixMathCommandI pfmc,
int flags)
Construct a new operator with no precedence set.
|
Operator(java.lang.String name,
PostfixMathCommandI pfmc,
int flags,
int precedence)
Constructs a new operator with a given precedence.
|
Operator(java.lang.String name,
java.lang.String symbol,
PostfixMathCommandI pfmc,
int flags)
Constructs a new operator, with a different name and symbol
|
Operator(java.lang.String name,
java.lang.String symbol,
PostfixMathCommandI pfmc,
int flags,
int precedence)
Constructs a new operator, with a different name and symbol and allows
a given precedence to be set.
|
Modifier and Type | Method and Description |
---|---|
boolean |
addAltSymbol(java.lang.String altSymbol)
Adds an alternate symbol which can be used at parse time.
|
java.util.List<java.lang.String> |
getAltSymbols()
List of alternative symbols which can represent the same operator
|
Operator |
getBinaryInverseOp()
The composite or binaryInverse operator (e.g. subtract) associated with a root or unary inverse operator
|
int |
getBinding()
Deprecated.
|
int |
getFlags()
The flags for this operator.
|
Operator |
getInverseOp()
The unary inverse operator associated with a root or composite operator.
|
int |
getKey()
Get the key code used to identify the operator in the operator table.
|
java.lang.String |
getName()
returns a unique name defining this operator.
|
PostfixMathCommandI |
getPFMC() |
int |
getPrecedence()
Get the precedence of the operator.
|
java.lang.String |
getPrintSymbol()
The symbol used for printing.
|
Operator |
getRootOp()
The basic group operator associated with the inverse or composite operator.
|
java.lang.String |
getSymbol()
returns the symbol used by this operator.
|
boolean |
isAssociative() |
boolean |
isBinary() |
boolean |
isCommutative() |
boolean |
isComposite() |
boolean |
isDistributiveOver(Operator op) |
boolean |
isEquivalence() |
boolean |
isLeftBinding() |
boolean |
isNary() |
boolean |
isPrefix() |
boolean |
isReflexive() |
boolean |
isRightBinding() |
boolean |
isSelfInverse() |
boolean |
isSuffix() |
boolean |
isSymmetric() |
boolean |
isTernary() |
boolean |
isTransitive() |
boolean |
isUnary() |
boolean |
notInParser() |
int |
numArgs() |
void |
setBinaryInverseOp(Operator inv)
In a mathematical group with operator + and inverse uminus (-y) the binary inverse operator
is the composition x + (-y) in other words subtraction -.
|
void |
setDistributiveOver(Operator op) |
void |
setFlag(int flag,
boolean val)
Set the value of a specific flag.
|
void |
setInverseOp(Operator inv)
For composite operators like a-b which can be considered as
a+(-b)
there is a root operator (+) and an inverse operator (UMinus).
|
void |
setKey(int key)
Key code used to identify the operator in the operator table.
|
void |
setPFMC(PostfixMathCommandI pfmc) |
void |
setPrecedence(int i)
Set the precedence of the operator.
|
void |
setPrintSymbol(java.lang.String printSymbol)
The symbol used for printing.
|
void |
setRootOp(Operator root)
For composite operators like a-b which can be considered as
a+(-b)
there is a root operator (+) and an inverse operator (UMinus).
|
void |
setSymbol(java.lang.String sym)
Sets the symbol used by the operator.
|
java.lang.String |
toFullString()
returns a verbose representation of the operator and all its properties.
|
java.lang.String |
toString() |
boolean |
useBindingForPrint() |
public static final int NO_ARGS
public static final int UNARY
public static final int BINARY
public static final int NARY
public static final int LEFT
public static final int RIGHT
public static final int ASSOCIATIVE
public static final int COMMUTATIVE
public static final int REFLEXIVE
public static final int SYMMETRIC
public static final int TRANSITIVE
public static final int EQUIVALENCE
public static final int PREFIX
public static final int SUFFIX
public static final int SELF_INVERSE
public static final int COMPOSITE
public static final int USE_BINDING_FOR_PRINT
public static final int NOT_IN_PARSER
public static final int TERNARY
TernaryOperator
,
Constant Field Valuesprotected final java.lang.String name
protected java.lang.String symbol
protected java.lang.String printSymbol
protected PostfixMathCommandI pfmc
protected int flags
protected int precedence
protected int key
public Operator(java.lang.String name, PostfixMathCommandI pfmc, int flags)
name
- printable name of the operatorpfmc
- postfix math command for the operatorflags
- set of flags defining the properties of the operator.public Operator(java.lang.String name, PostfixMathCommandI pfmc, int flags, int precedence)
name
- printable name of the operatorpfmc
- postfix math command for the operatorflags
- set of flags defining the properties of the operatorprecedence
- operator precedence to be setpublic Operator(java.lang.String name, java.lang.String symbol, PostfixMathCommandI pfmc, int flags)
name
- name of operator, must be unique, used when describing operatorsymbol
- printable name of operator, used for printing equationspfmc
- postfix math command for operatorflags
- set of flags defining the properties of the operatorpublic Operator(java.lang.String name, java.lang.String symbol, PostfixMathCommandI pfmc, int flags, int precedence)
name
- name of operator, must be unique, used when describing operatorsymbol
- printable name of operator, used for printing equationspfmc
- postfix math command for operatorflags
- set of flags defining the properties of the operator.precedence
- operator precedence to be setpublic final java.lang.String getSymbol()
public final void setSymbol(java.lang.String sym)
Jep.reinitializeComponents()
must be called after using this method.sym
- the new symbol to use.public final java.lang.String getName()
public java.lang.String getPrintSymbol()
public void setPrintSymbol(java.lang.String printSymbol)
public final PostfixMathCommandI getPFMC()
public final void setPFMC(PostfixMathCommandI pfmc)
public final int getPrecedence()
public void setPrecedence(int i)
i
- the precedencepublic final void setDistributiveOver(Operator op)
public boolean isDistributiveOver(Operator op)
public void setRootOp(Operator root)
root
- the root operatorpublic void setInverseOp(Operator inv)
inv
- the unary inverse operatorpublic void setBinaryInverseOp(Operator inv)
inv
- public Operator getRootOp()
public Operator getInverseOp()
public Operator getBinaryInverseOp()
public final int getFlags()
@Deprecated public final int getBinding()
isLeftBinding()
,
isRightBinding()
public final boolean isLeftBinding()
public final boolean isRightBinding()
public final boolean isAssociative()
public final boolean isCommutative()
public final boolean isBinary()
public final boolean isUnary()
public final boolean isNary()
public final int numArgs()
public final boolean isTransitive()
public final boolean isSymmetric()
public final boolean isReflexive()
public final boolean isEquivalence()
public final boolean isPrefix()
public final boolean isSuffix()
public final boolean isTernary()
public final boolean isComposite()
public final boolean isSelfInverse()
public final boolean useBindingForPrint()
public final boolean notInParser()
public void setFlag(int flag, boolean val)
flag
- flag to setval
- value for that flagpublic java.lang.String toFullString()
public java.lang.String toString()
toString
in class java.lang.Object
public int getKey()
public void setKey(int key)
key
- the keypublic java.util.List<java.lang.String> getAltSymbols()
public boolean addAltSymbol(java.lang.String altSymbol)
Adds an alternate symbol which can be used at parse time. The alternate symbol added will be recognised at parse time by configurable parser the normal symbol will be used in output.
For example unicode U+002D the hyphen minus (-), U+2212 the unicode minus symbol (−), U+2013 then en-dash (–) may appear in some input to represent minus. Other possible alternative characters include U+2264 less-than or equals (≤), U+2264 greater-than or equals (≥), U+00D7 multiplication sign (×), U+00F7 division sign (÷), U+2044 fraction slash (⁄) and U+2215 division slash (∕).
altSymbol
- the symbol to addCopyright © 2018 Singular Systems http://www.singularsys.com/jep