Package com.blackrook.expression
Class ExpressionValue
- java.lang.Object
-
- com.blackrook.expression.ExpressionValue
-
- All Implemented Interfaces:
Comparable<ExpressionValue>
public class ExpressionValue extends Object implements Comparable<ExpressionValue>
Expression value encapsulation.- Author:
- Matthew Tropiano
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classExpressionValue.Type
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static voidabsolute(ExpressionValue operand, ExpressionValue out)Absolute calculation.static voidadd(ExpressionValue operand, ExpressionValue operand2, ExpressionValue out)Add calculation.static voidand(ExpressionValue operand, ExpressionValue operand2, ExpressionValue out)Bitwise And calculation.booleanasBoolean()Gets this value as a boolean.byteasByte()Gets this value as a byte.doubleasDouble()Gets this value as a double-precision float.floatasFloat()Gets this value as a short.intasInt()Gets this value as an integer.longasLong()Gets this value as a long integer.shortasShort()Gets this value as a short.StringasString()Gets this value as a string.intcompareTo(ExpressionValue o)voidconvertTo(ExpressionValue.Type newType)Converts this value to another value.static ExpressionValuecreate(boolean value)Creates an expression value.static ExpressionValuecreate(double value)Creates an expression value.static ExpressionValuecreate(long value)Creates an expression value.static ExpressionValuecreate(ExpressionValue value)Creates an expression value.static voiddivide(ExpressionValue operand, ExpressionValue operand2, ExpressionValue out)Divide calculation.static voidequal(ExpressionValue operand, ExpressionValue operand2, ExpressionValue out)Logical Equal calculation.booleanequals(ExpressionValue value)booleanequals(Object obj)static voidgreater(ExpressionValue operand, ExpressionValue operand2, ExpressionValue out)Greater-than calculation.static voidgreaterOrEqual(ExpressionValue operand, ExpressionValue operand2, ExpressionValue out)Greater-than-or-equal calculation.booleanisInfinite()booleanisNaN()static voidleftShift(ExpressionValue operand, ExpressionValue operand2, ExpressionValue out)Left shift calculation.static voidless(ExpressionValue operand, ExpressionValue operand2, ExpressionValue out)Less-than calculation.static voidlessOrEqual(ExpressionValue operand, ExpressionValue operand2, ExpressionValue out)Less-than-or-equal calculation.static voidlogicalAnd(ExpressionValue operand, ExpressionValue operand2, ExpressionValue out)Logical And calculation.static voidlogicalNot(ExpressionValue operand, ExpressionValue out)Logical not calculation.static voidlogicalOr(ExpressionValue operand, ExpressionValue operand2, ExpressionValue out)Logical Or calculation.static voidmodulo(ExpressionValue operand, ExpressionValue operand2, ExpressionValue out)Modulo calculation.static voidmultiply(ExpressionValue operand, ExpressionValue operand2, ExpressionValue out)Multiply calculation.static voidnegate(ExpressionValue operand, ExpressionValue out)Negate calculation.static voidnot(ExpressionValue operand, ExpressionValue out)Bitwise not calculation.static voidnotEqual(ExpressionValue operand, ExpressionValue operand2, ExpressionValue out)Logical Not Equal calculation.static voidor(ExpressionValue operand, ExpressionValue operand2, ExpressionValue out)Bitwise Or calculation.static voidrightShift(ExpressionValue operand, ExpressionValue operand2, ExpressionValue out)Right shift calculation.static voidrightShiftPadded(ExpressionValue operand, ExpressionValue operand2, ExpressionValue out)Right shift padded calculation.voidset(boolean value)Sets this value using another value.voidset(double value)Sets this value using another value.voidset(long value)Sets this value using another value.voidset(ExpressionValue value)Sets this value using another value.static voidstrictEqual(ExpressionValue operand, ExpressionValue operand2, ExpressionValue out)Strict Equal calculation.static voidstrictNotEqual(ExpressionValue operand, ExpressionValue operand2, ExpressionValue out)Strict Not Equal calculation.static voidsubtract(ExpressionValue operand, ExpressionValue operand2, ExpressionValue out)Subtract calculation.StringtoString()voidwriteBytes(OutputStream out)Write value as bytes (for digest later).static voidxor(ExpressionValue operand, ExpressionValue operand2, ExpressionValue out)Bitwise XOr calculation.
-
-
-
Method Detail
-
create
public static ExpressionValue create(boolean value)
Creates an expression value.- Parameters:
value- the source value.- Returns:
- a new expression value.
-
create
public static ExpressionValue create(long value)
Creates an expression value.- Parameters:
value- the source value.- Returns:
- a new expression value.
-
create
public static ExpressionValue create(double value)
Creates an expression value.- Parameters:
value- the source value.- Returns:
- a new expression value.
-
create
public static ExpressionValue create(ExpressionValue value)
Creates an expression value.- Parameters:
value- the source value.- Returns:
- a new expression value.
-
set
public void set(ExpressionValue value)
Sets this value using another value.- Parameters:
value- the source value to use.
-
set
public void set(boolean value)
Sets this value using another value.- Parameters:
value- the source value to use.
-
set
public void set(long value)
Sets this value using another value.- Parameters:
value- the source value to use.
-
set
public void set(double value)
Sets this value using another value.- Parameters:
value- the source value to use.
-
isNaN
public boolean isNaN()
- Returns:
- true if this value is NaN.
-
isInfinite
public boolean isInfinite()
- Returns:
- true if this value is positive or negative infinity.
-
asBoolean
public boolean asBoolean()
Gets this value as a boolean.- Returns:
- true if the value is nonzero and not NaN, false otherwise.
-
asDouble
public double asDouble()
Gets this value as a double-precision float. If this is a boolean type, this returns1.0. If this is a long type, this is cast to a double.- Returns:
- the double value of this value.
-
asLong
public long asLong()
Gets this value as a long integer. If this is a boolean type, this return-1L. If this is a double type, this is cast to a long.- Returns:
- the long value of this value.
-
asByte
public byte asByte()
Gets this value as a byte. Depending on the internal value, this may end up truncating data.(byte)asLong()
- Returns:
- the byte value of this value.
-
asShort
public short asShort()
Gets this value as a short. Depending on the internal value, this may end up truncating data.(short)asLong()
- Returns:
- the byte value of this value.
-
asInt
public int asInt()
Gets this value as an integer. Depending on the internal value, this may end up truncating data.(int)asLong()
- Returns:
- the byte value of this value.
-
asFloat
public float asFloat()
Gets this value as a short. Depending on the internal value, this may end up truncating data.isNaN() ? Float.NaN : (float)asDouble()
- Returns:
- the byte value of this value.
-
asString
public String asString()
Gets this value as a string.- Returns:
- the string value of this value.
-
convertTo
public void convertTo(ExpressionValue.Type newType)
Converts this value to another value.- Parameters:
newType- the new type to convert to.- Throws:
IllegalArgumentException- if newType is null.
-
equals
public boolean equals(ExpressionValue value)
- Parameters:
value- the other value.- Returns:
- true if this value is STRICTLY EQUAL to another.
-
compareTo
public int compareTo(ExpressionValue o)
- Specified by:
compareToin interfaceComparable<ExpressionValue>
-
toString
public String toString()
-
not
public static void not(ExpressionValue operand, ExpressionValue out)
Bitwise not calculation.- Parameters:
operand- the input value.out- the output value.
-
negate
public static void negate(ExpressionValue operand, ExpressionValue out)
Negate calculation.- Parameters:
operand- the input value.out- the output value.
-
absolute
public static void absolute(ExpressionValue operand, ExpressionValue out)
Absolute calculation.- Parameters:
operand- the input value.out- the output value.
-
logicalNot
public static void logicalNot(ExpressionValue operand, ExpressionValue out)
Logical not calculation.- Parameters:
operand- the input value.out- the output value.
-
add
public static void add(ExpressionValue operand, ExpressionValue operand2, ExpressionValue out)
Add calculation.- Parameters:
operand- the source operand.operand2- the second operand.out- the output value.
-
subtract
public static void subtract(ExpressionValue operand, ExpressionValue operand2, ExpressionValue out)
Subtract calculation.- Parameters:
operand- the source operand.operand2- the second operand.out- the output value.
-
multiply
public static void multiply(ExpressionValue operand, ExpressionValue operand2, ExpressionValue out)
Multiply calculation.- Parameters:
operand- the source operand.operand2- the second operand.out- the output value.
-
divide
public static void divide(ExpressionValue operand, ExpressionValue operand2, ExpressionValue out)
Divide calculation.- Parameters:
operand- the source operand.operand2- the second operand.out- the output value.
-
modulo
public static void modulo(ExpressionValue operand, ExpressionValue operand2, ExpressionValue out)
Modulo calculation.- Parameters:
operand- the source operand.operand2- the second operand.out- the output value.
-
and
public static void and(ExpressionValue operand, ExpressionValue operand2, ExpressionValue out)
Bitwise And calculation.- Parameters:
operand- the source operand.operand2- the second operand.out- the output value.
-
or
public static void or(ExpressionValue operand, ExpressionValue operand2, ExpressionValue out)
Bitwise Or calculation.- Parameters:
operand- the source operand.operand2- the second operand.out- the output value.
-
xor
public static void xor(ExpressionValue operand, ExpressionValue operand2, ExpressionValue out)
Bitwise XOr calculation.- Parameters:
operand- the source operand.operand2- the second operand.out- the output value.
-
logicalAnd
public static void logicalAnd(ExpressionValue operand, ExpressionValue operand2, ExpressionValue out)
Logical And calculation.- Parameters:
operand- the source operand.operand2- the second operand.out- the output value.
-
logicalOr
public static void logicalOr(ExpressionValue operand, ExpressionValue operand2, ExpressionValue out)
Logical Or calculation.- Parameters:
operand- the source operand.operand2- the second operand.out- the output value.
-
leftShift
public static void leftShift(ExpressionValue operand, ExpressionValue operand2, ExpressionValue out)
Left shift calculation.- Parameters:
operand- the source operand.operand2- the second operand.out- the output value.
-
rightShift
public static void rightShift(ExpressionValue operand, ExpressionValue operand2, ExpressionValue out)
Right shift calculation.- Parameters:
operand- the source operand.operand2- the second operand.out- the output value.
-
rightShiftPadded
public static void rightShiftPadded(ExpressionValue operand, ExpressionValue operand2, ExpressionValue out)
Right shift padded calculation.- Parameters:
operand- the source operand.operand2- the second operand.out- the output value.
-
less
public static void less(ExpressionValue operand, ExpressionValue operand2, ExpressionValue out)
Less-than calculation.- Parameters:
operand- the source operand.operand2- the second operand.out- the output value.
-
lessOrEqual
public static void lessOrEqual(ExpressionValue operand, ExpressionValue operand2, ExpressionValue out)
Less-than-or-equal calculation.- Parameters:
operand- the source operand.operand2- the second operand.out- the output value.
-
greater
public static void greater(ExpressionValue operand, ExpressionValue operand2, ExpressionValue out)
Greater-than calculation.- Parameters:
operand- the source operand.operand2- the second operand.out- the output value.
-
greaterOrEqual
public static void greaterOrEqual(ExpressionValue operand, ExpressionValue operand2, ExpressionValue out)
Greater-than-or-equal calculation.- Parameters:
operand- the source operand.operand2- the second operand.out- the output value.
-
equal
public static void equal(ExpressionValue operand, ExpressionValue operand2, ExpressionValue out)
Logical Equal calculation.- Parameters:
operand- the source operand.operand2- the second operand.out- the output value.
-
notEqual
public static void notEqual(ExpressionValue operand, ExpressionValue operand2, ExpressionValue out)
Logical Not Equal calculation.- Parameters:
operand- the source operand.operand2- the second operand.out- the output value.
-
strictEqual
public static void strictEqual(ExpressionValue operand, ExpressionValue operand2, ExpressionValue out)
Strict Equal calculation.- Parameters:
operand- the source operand.operand2- the second operand.out- the output value.
-
strictNotEqual
public static void strictNotEqual(ExpressionValue operand, ExpressionValue operand2, ExpressionValue out)
Strict Not Equal calculation.- Parameters:
operand- the source operand.operand2- the second operand.out- the output value.
-
writeBytes
public void writeBytes(OutputStream out) throws IOException
Write value as bytes (for digest later).- Parameters:
out- the output stream.- Throws:
IOException- if a write error occurs.
-
-