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 class
ExpressionValue.Type
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
absolute(ExpressionValue operand, ExpressionValue out)
Absolute calculation.static void
add(ExpressionValue operand, ExpressionValue operand2, ExpressionValue out)
Add calculation.static void
and(ExpressionValue operand, ExpressionValue operand2, ExpressionValue out)
Bitwise And calculation.boolean
asBoolean()
Gets this value as a boolean.byte
asByte()
Gets this value as a byte.double
asDouble()
Gets this value as a double-precision float.float
asFloat()
Gets this value as a short.int
asInt()
Gets this value as an integer.long
asLong()
Gets this value as a long integer.short
asShort()
Gets this value as a short.String
asString()
Gets this value as a string.int
compareTo(ExpressionValue o)
void
convertTo(ExpressionValue.Type newType)
Converts this value to another value.static ExpressionValue
create(boolean value)
Creates an expression value.static ExpressionValue
create(double value)
Creates an expression value.static ExpressionValue
create(long value)
Creates an expression value.static ExpressionValue
create(ExpressionValue value)
Creates an expression value.static void
divide(ExpressionValue operand, ExpressionValue operand2, ExpressionValue out)
Divide calculation.static void
equal(ExpressionValue operand, ExpressionValue operand2, ExpressionValue out)
Logical Equal calculation.boolean
equals(ExpressionValue value)
boolean
equals(Object obj)
static void
greater(ExpressionValue operand, ExpressionValue operand2, ExpressionValue out)
Greater-than calculation.static void
greaterOrEqual(ExpressionValue operand, ExpressionValue operand2, ExpressionValue out)
Greater-than-or-equal calculation.boolean
isInfinite()
boolean
isNaN()
static void
leftShift(ExpressionValue operand, ExpressionValue operand2, ExpressionValue out)
Left shift calculation.static void
less(ExpressionValue operand, ExpressionValue operand2, ExpressionValue out)
Less-than calculation.static void
lessOrEqual(ExpressionValue operand, ExpressionValue operand2, ExpressionValue out)
Less-than-or-equal calculation.static void
logicalAnd(ExpressionValue operand, ExpressionValue operand2, ExpressionValue out)
Logical And calculation.static void
logicalNot(ExpressionValue operand, ExpressionValue out)
Logical not calculation.static void
logicalOr(ExpressionValue operand, ExpressionValue operand2, ExpressionValue out)
Logical Or calculation.static void
modulo(ExpressionValue operand, ExpressionValue operand2, ExpressionValue out)
Modulo calculation.static void
multiply(ExpressionValue operand, ExpressionValue operand2, ExpressionValue out)
Multiply calculation.static void
negate(ExpressionValue operand, ExpressionValue out)
Negate calculation.static void
not(ExpressionValue operand, ExpressionValue out)
Bitwise not calculation.static void
notEqual(ExpressionValue operand, ExpressionValue operand2, ExpressionValue out)
Logical Not Equal calculation.static void
or(ExpressionValue operand, ExpressionValue operand2, ExpressionValue out)
Bitwise Or calculation.static void
rightShift(ExpressionValue operand, ExpressionValue operand2, ExpressionValue out)
Right shift calculation.static void
rightShiftPadded(ExpressionValue operand, ExpressionValue operand2, ExpressionValue out)
Right shift padded calculation.void
set(boolean value)
Sets this value using another value.void
set(double value)
Sets this value using another value.void
set(long value)
Sets this value using another value.void
set(ExpressionValue value)
Sets this value using another value.static void
strictEqual(ExpressionValue operand, ExpressionValue operand2, ExpressionValue out)
Strict Equal calculation.static void
strictNotEqual(ExpressionValue operand, ExpressionValue operand2, ExpressionValue out)
Strict Not Equal calculation.static void
subtract(ExpressionValue operand, ExpressionValue operand2, ExpressionValue out)
Subtract calculation.String
toString()
void
writeBytes(OutputStream out)
Write value as bytes (for digest later).static void
xor(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:
compareTo
in 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.
-
-