public class SimpleMathCompare extends EvaluateBase implements EvaluateMathDef
String
, Integer
,
Long
, Float
or Double
. The Character
type is also
accommodated, but that would have a specific range that is not checked for. Also
required is the value type, when two values of that type are compared, and an operator
to define the comparison type. There are two main methods. The mathOperation
method can be
used to return a mathematical operation over the two values. The evalComparison
method returns a boolean reply of whether the comparison operation is true or false.
If the value Object is a MetricValue
, then this is checked for and the
value stored in it used instead.
Constructor and Description |
---|
SimpleMathCompare()
Create a new instance of SimpleMathCompare.
|
Modifier and Type | Method and Description |
---|---|
protected BagOfWords |
add(BagOfWords value1,
BagOfWords value2)
Add the two bag-of-words together.
|
protected java.lang.Character |
add(java.lang.Character value1,
java.lang.Character value2)
Add the two char values together.
|
protected java.lang.Double |
add(java.lang.Double value1,
java.lang.Double value2)
Add the two double values together.
|
protected java.lang.Float |
add(java.lang.Float value1,
java.lang.Float value2)
Add the two float values together.
|
protected java.lang.Integer |
add(java.lang.Integer value1,
java.lang.Integer value2)
Add the two integer values together.
|
protected java.lang.Long |
add(java.lang.Long value1,
java.lang.Long value2)
Add the two long values together.
|
<T> T |
add(java.lang.String valueType,
T value1,
T value2)
Add the two objects together and return.
|
protected java.lang.Character |
divide(java.lang.Character value1,
java.lang.Character value2)
Divide the first value by the second and return the result.
|
protected java.lang.Double |
divide(java.lang.Double value1,
java.lang.Double value2)
Divide the first value by the second and return the result.
|
protected java.lang.Float |
divide(java.lang.Float value1,
java.lang.Float value2)
Divide the first value by the second and return the result.
|
protected java.lang.Integer |
divide(java.lang.Integer value1,
java.lang.Integer value2)
Divide the first value by the second and return the result.
|
protected java.lang.Long |
divide(java.lang.Long value1,
java.lang.Long value2)
Divide the first value by the second and return the result.
|
<T> T |
divide(java.lang.String valueType,
T value1,
T value2)
Divide the first value by the second and return the result.
|
protected boolean |
evaluate(java.lang.Character value1,
java.lang.Character value2,
java.lang.String operator)
Evaluate the expression and return true if true.
|
protected boolean |
evaluate(java.lang.Double value1,
java.lang.Double value2,
java.lang.String operator)
Evaluate the expression and return true if true.
|
protected boolean |
evaluate(java.lang.Float value1,
java.lang.Float value2,
java.lang.String operator)
Evaluate the expression and return true if true.
|
protected boolean |
evaluate(java.lang.Integer value1,
java.lang.Integer value2,
java.lang.String operator)
Evaluate the expression and return true if true.
|
protected boolean |
evaluate(java.lang.Long value1,
java.lang.Long value2,
java.lang.String operator)
Evaluate the expression and return true if true.
|
protected boolean |
evaluate(java.lang.String value1,
java.lang.String value2,
java.lang.String operator)
Evaluate the expression and return true if true.
|
protected <T> java.util.List<T> |
intersection(java.util.List<T> list1,
java.util.List<T> list2)
Calculate the intersection between two lists of objects.
|
<T> boolean |
mathCompare(java.lang.String valueType,
T value1,
T value2,
java.lang.String operator)
Evaluate the mathematical expression
value1 operator value2 . |
<T> java.lang.Object |
mathOperation(java.lang.String valueType,
T value1,
T value2,
java.lang.String operator)
Evaluate the mathematical expression
value1 operator value2 . |
protected java.lang.Character |
multiply(java.lang.Character value1,
java.lang.Character value2)
Multiply the first value by the second and return the result.
|
protected java.lang.Double |
multiply(java.lang.Double value1,
java.lang.Double value2)
Multiply the first value by the second and return the result.
|
protected java.lang.Float |
multiply(java.lang.Float value1,
java.lang.Float value2)
Multiply the first value by the second and return the result.
|
protected java.lang.Integer |
multiply(java.lang.Integer value1,
java.lang.Integer value2)
Multiply the first value by the second and return the result.
|
protected java.lang.Long |
multiply(java.lang.Long value1,
java.lang.Long value2)
Multiply the first value by the second and return the result.
|
<T> T |
multiply(java.lang.String valueType,
T value1,
T value2)
Multiply the first value by the second and return the result.
|
protected BagOfWords |
subtract(BagOfWords value1,
BagOfWords value2)
Subtract the second value from the first and return the result.
|
protected java.lang.Character |
subtract(java.lang.Character value1,
java.lang.Character value2)
Subtract the second value from the first and return the result.
|
protected java.lang.Double |
subtract(java.lang.Double value1,
java.lang.Double value2)
Subtract the second value from the first and return the result.
|
protected java.lang.Float |
subtract(java.lang.Float value1,
java.lang.Float value2)
Subtract the second value from the first and return the result.
|
protected java.lang.Integer |
subtract(java.lang.Integer value1,
java.lang.Integer value2)
Subtract the second value from the first and return the result.
|
protected java.lang.Long |
subtract(java.lang.Long value1,
java.lang.Long value2)
Subtract the second value from the first and return the result.
|
<T> T |
subtract(java.lang.String valueType,
T value1,
T value2)
Subtract the second value from the first and return the result.
|
protected <T> java.util.List<T> |
union(java.util.List<T> list1,
java.util.List<T> list2)
Calculate the union between two lists of objects.
|
randomValue, randomValueDouble, randomValueFloat, randomValueInteger, randomValueLong, randomValueString, valueFromSet, valueFromString, valueToString
public SimpleMathCompare() throws java.lang.Exception
java.lang.Exception
- any error.public <T> java.lang.Object mathOperation(java.lang.String valueType, T value1, T value2, java.lang.String operator) throws java.lang.Exception
value1 operator value2
.mathOperation
in interface EvaluateMathDef
valueType
- the type of the value. This is the object type class name.value1
- first value.value2
- second value.operator
- mathematical operator - can be add, subtract, multiply, divide.
These are all defined in the AiHeuristicConst
class.java.lang.Exception
- any error.public <T> boolean mathCompare(java.lang.String valueType, T value1, T value2, java.lang.String operator)
value1 operator value2
.mathCompare
in interface EvaluateMathDef
valueType
- the type of the value. This is the object type class name.
Numerical or String is evaluated as is. Any other type is converted to a String
using EvaluateBase
.valueToString
and that is used instead.value1
- first value.value2
- second value.operator
- comparison operator, which evaluates 'value1 operator value2'.
Operator can be greater than (GT), less than (LT), etc. These are all defined in
the AiHeuristicConst
class.protected boolean evaluate(java.lang.Integer value1, java.lang.Integer value2, java.lang.String operator)
value1
- first value.value2
- second value.operator
- comparison operator.protected boolean evaluate(java.lang.Character value1, java.lang.Character value2, java.lang.String operator)
value1
- first value.value2
- second value.operator
- comparison operator.protected boolean evaluate(java.lang.Long value1, java.lang.Long value2, java.lang.String operator)
value1
- first value.value2
- second value.operator
- comparison operator.protected boolean evaluate(java.lang.Float value1, java.lang.Float value2, java.lang.String operator)
value1
- first value.value2
- second value.operator
- comparison operator.protected boolean evaluate(java.lang.Double value1, java.lang.Double value2, java.lang.String operator)
value1
- first value.value2
- second value.operator
- comparison operator.protected boolean evaluate(java.lang.String value1, java.lang.String value2, java.lang.String operator)
value1
- first value.value2
- second value.operator
- comparison operator.protected <T> java.util.List<T> intersection(java.util.List<T> list1, java.util.List<T> list2)
List
type but then the elements can be different types.
If the element type is recognised then the intersection can be recognised.
Take the element type from the instance to avoid confusion with the list type.
The only exception is a cast to the BagOfWords
of this package.list1
- the first list of elements.list2
- the second list of elements.protected <T> java.util.List<T> union(java.util.List<T> list1, java.util.List<T> list2)
List
type but then the elements can be different types.
If the element type is recognised then the union can be recognised.
Take the element type from the instance to avoid confusion with the list type.
The only exception is a cast to the BagOfWords
of this package.list1
- the first list of elements.list2
- the second list of elements.public <T> T add(java.lang.String valueType, T value1, T value2) throws java.lang.Exception
add
in interface EvaluateMathDef
valueType
- the type of the value.value1
- first value.value2
- second value.java.lang.Exception
- any error.protected java.lang.Integer add(java.lang.Integer value1, java.lang.Integer value2)
value1
- first value.value2
- second value.protected java.lang.Character add(java.lang.Character value1, java.lang.Character value2)
value1
- first value.value2
- second value.protected java.lang.Long add(java.lang.Long value1, java.lang.Long value2)
value1
- first value.value2
- second value.protected java.lang.Float add(java.lang.Float value1, java.lang.Float value2)
value1
- first value.value2
- second value.protected java.lang.Double add(java.lang.Double value1, java.lang.Double value2)
value1
- first value.value2
- second value.protected BagOfWords add(BagOfWords value1, BagOfWords value2) throws java.lang.Exception
value1
- first value.value2
- second value.java.lang.Exception
- any error.public <T> T subtract(java.lang.String valueType, T value1, T value2) throws java.lang.Exception
subtract
in interface EvaluateMathDef
valueType
- the type of the value.value1
- first value.value2
- second value.java.lang.Exception
- any error.protected java.lang.Integer subtract(java.lang.Integer value1, java.lang.Integer value2)
value1
- first value.value2
- second value.protected java.lang.Character subtract(java.lang.Character value1, java.lang.Character value2)
value1
- first value.value2
- second value.protected java.lang.Long subtract(java.lang.Long value1, java.lang.Long value2)
value1
- first value.value2
- second value.protected java.lang.Float subtract(java.lang.Float value1, java.lang.Float value2)
value1
- first value.value2
- second value.protected java.lang.Double subtract(java.lang.Double value1, java.lang.Double value2)
value1
- first value.value2
- second value.protected BagOfWords subtract(BagOfWords value1, BagOfWords value2) throws java.lang.Exception
value1
- first value.value2
- second value.java.lang.Exception
- any error.public <T> T multiply(java.lang.String valueType, T value1, T value2)
multiply
in interface EvaluateMathDef
valueType
- the type of the value.value1
- first value.value2
- second value.protected java.lang.Integer multiply(java.lang.Integer value1, java.lang.Integer value2)
value1
- first value.value2
- second value.protected java.lang.Character multiply(java.lang.Character value1, java.lang.Character value2)
value1
- first value.value2
- second value.protected java.lang.Long multiply(java.lang.Long value1, java.lang.Long value2)
value1
- first value.value2
- second value.protected java.lang.Float multiply(java.lang.Float value1, java.lang.Float value2)
value1
- first value.value2
- second value.protected java.lang.Double multiply(java.lang.Double value1, java.lang.Double value2)
value1
- first value.value2
- second value.public <T> T divide(java.lang.String valueType, T value1, T value2)
divide
in interface EvaluateMathDef
valueType
- the type of the value.value1
- first value.value2
- second value.protected java.lang.Integer divide(java.lang.Integer value1, java.lang.Integer value2)
value1
- first value.value2
- second value.protected java.lang.Character divide(java.lang.Character value1, java.lang.Character value2)
value1
- first value.value2
- second value.protected java.lang.Long divide(java.lang.Long value1, java.lang.Long value2)
value1
- first value.value2
- second value.protected java.lang.Float divide(java.lang.Float value1, java.lang.Float value2)
value1
- first value.value2
- second value.protected java.lang.Double divide(java.lang.Double value1, java.lang.Double value2)
value1
- first value.value2
- second value.