public class Value extends java.lang.Object implements java.lang.Comparable<Value>, Saveable, ReferenceSaveable
Modifier and Type | Field and Description |
---|---|
protected ValueType |
type
Value type.
|
protected java.lang.Object |
value
Value itself.
|
Modifier and Type | Method and Description |
---|---|
static Value |
absolute(Value value1)
Returns the absolute value of a literal value.
|
static Value |
add(Value value1,
Value value2)
Returns the addition of two literal values.
|
boolean |
asBoolean()
Returns this value as a boolean value.
|
double |
asDouble()
Returns the double value of this value.
|
long |
asLong()
Returns this value as a long value.
|
java.lang.String |
asString()
Returns the String value of this value (not the same as toString()!!).
|
int |
compareTo(Value v) |
static Value |
create(boolean value)
Creates a boolean value.
|
static Value |
create(double value)
Creates a value typed as float.
|
static Value |
create(float value)
Creates a value typed as float.
|
static Value |
create(int value)
Creates an integer value.
|
static Value |
create(long value)
Creates a long integer value.
|
static Value |
create(Value inputValue)
Creates a copy of a value.
|
static Value |
create(java.lang.String value)
Creates a value typed as string.
|
static Value |
createAction(java.lang.String identity)
Creates a action value.
|
static Value |
createContainer(java.lang.String identity)
Creates a container value.
|
static Value |
createEmptyList()
Creates an empty list value.
|
static Value |
createEmptyList(int capacity)
Creates an empty list value.
|
static Value |
createList(Value... values)
Creates a list value.
|
static Value |
createObject(java.lang.String identity)
Creates an object value.
|
static Value |
createPlayer(java.lang.String identity)
Creates a player value.
|
static Value |
createRoom(java.lang.String identity)
Creates a room value.
|
static Value |
createVariable(java.lang.String name)
Creates a variable reference value.
|
static Value |
createWorld()
Creates a world value.
|
static Value |
divide(Value value1,
Value value2)
Returns the division of two literal values.
|
boolean |
equals(Value otherValue)
Returns if this value is equal to another: PERFECTLY EQUAL, type strict.
|
static Value |
equals(Value value1,
Value value2)
Returns if two values are equal, no type safety if they are literals.
|
boolean |
equals(java.lang.Object obj) |
boolean |
equalsIgnoreType(Value otherValue)
Returns if this value is equal to another, value-wise.
|
ValueType |
getType()
Returns this value's type.
|
java.lang.Object |
getValue() |
static Value |
greater(Value value1,
Value value2)
Returns if the first literal value is greater than the second.
|
static Value |
greaterOrEqual(Value value1,
Value value2)
Returns if the first literal value is greater than or equal to the second.
|
int |
hashCode() |
boolean |
isAction()
Returns if this value represents an action.
|
boolean |
isBoolean()
Returns if this value is a boolean value.
|
boolean |
isElement()
Returns if this value represents an element.
|
boolean |
isEmpty()
Gets if this value is "empty."
If boolean, this returns true if and only if this is false. |
boolean |
isFloatingPoint()
Returns if this value is a floating-point number.
|
boolean |
isInfinite()
Returns if this value evaluates to positive or negative infinity.
|
boolean |
isInteger()
Returns if this value is an integer.
|
boolean |
isList()
Returns if this value is a string value.
|
boolean |
isLiteral()
Returns if this value is a literal value (or list).
|
boolean |
isNaN()
Returns if this value evaluates to
NaN . |
boolean |
isNumeric()
Returns if this value is a number.
|
boolean |
isObjectContainer()
Returns if this value represents an object container.
|
boolean |
isReferenceCopied()
Returns if this value is intended to be passed around by reference internally.
|
boolean |
isStrictlyNaN()
Returns if this value is strictly a floating point value that is
NaN . |
boolean |
isString()
Returns if this value is a string value.
|
boolean |
isTrue()
Returns if this value evaluates to
true . |
boolean |
isVariable()
Returns if this value represents a variable.
|
int |
length()
Gets the length of this value.
|
static Value |
less(Value value1,
Value value2)
Returns if the first literal value is less than the second.
|
static Value |
lessOrEqual(Value value1,
Value value2)
Returns if the first literal value is less than or equal to the second.
|
boolean |
listAdd(Value v)
Adds a value to this, if this is a list.
|
boolean |
listAddAt(int i,
Value v)
Adds a value to this at a specific index, if this is a list.
|
boolean |
listContains(Value v)
Checks if this value contains a value, if this is a list.
|
Value |
listGet(int i)
Gets a value on this at a specific index, if this is a list.
|
int |
listIndexOf(Value v)
Gets the index of a value from this, if this is a list.
|
boolean |
listRemove(Value v)
Removes a value from inside this value, if this is a list.
|
Value |
listRemoveAt(int i)
Removes a value from this at a specific index, if this is a list.
|
boolean |
listSet(int i,
Value v)
Sets a value on this at a specific index, if this is a list.
|
static Value |
logicalAnd(Value value1,
Value value2)
Returns the "logical and" of two literal values.
|
static Value |
logicalNot(Value value1)
Returns the "logical not" value of a literal value.
|
static Value |
logicalOr(Value value1,
Value value2)
Returns the "logical or" of two literal values.
|
static Value |
logicalXOr(Value value1,
Value value2)
Returns the "logical xor" of two literal values.
|
static Value |
modulo(Value value1,
Value value2)
Returns the modulo of one literal value using another.
|
static Value |
multiply(Value value1,
Value value2)
Returns the multiplication of two literal values.
|
static Value |
negate(Value value1)
Returns the negative value of a literal value.
|
static Value |
notEquals(Value value1,
Value value2)
Returns if two values are not equal, no type safety if they are literals.
|
static Value |
power(Value value1,
Value value2)
Returns the result of one value raised to a certain power.
|
static Value |
read(java.io.InputStream in)
Reads a value from an input stream, using a reference map to pick up seen references.
|
static Value |
read(java.util.Map<java.lang.Long,Value> referenceMap,
java.io.InputStream in)
Reads a value from an input stream, using a reference map to pick up seen references.
|
void |
readBytes(java.io.InputStream in)
Imports this object from bytes.
|
void |
readReferentialBytes(java.util.Map<java.lang.Long,Value> referenceMap,
java.io.InputStream in)
Imports this object from bytes, looking up value references in a map.
|
static Value |
strictEquals(Value value1,
Value value2)
Returns if two values are equal, with type strictness.
|
static Value |
strictNotEquals(Value value1,
Value value2)
Returns if two values are not equal, with type strictness.
|
static Value |
subtract(Value value1,
Value value2)
Returns the subtraction of the second literal value from the first.
|
java.lang.String |
toString() |
void |
writeBytes(java.io.OutputStream out)
Exports this object to bytes.
|
void |
writeReferentialBytes(java.util.concurrent.atomic.AtomicLong referenceCounter,
java.util.Map<java.lang.Object,java.lang.Long> referenceSet,
java.io.OutputStream out)
Exports this object to bytes, preserving up value references from a map.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
fromReferentialBytes, toReferentialBytes
protected ValueType type
protected java.lang.Object value
public static Value create(boolean value)
value
- the boolean value.public static Value create(int value)
value
- the integer value.public static Value create(long value)
value
- the long value.public static Value create(float value)
value
- the float value.public static Value create(double value)
value
- the double value.public static Value create(java.lang.String value)
value
- the string value.java.lang.IllegalArgumentException
- if value is null.public static Value createEmptyList()
public static Value createEmptyList(int capacity)
capacity
- the initial capacity.public static Value createList(Value... values)
values
- the values to set in the list (converted to Value
s).public static Value createObject(java.lang.String identity)
identity
- the object identity.java.lang.IllegalArgumentException
- if identity is null.public static Value createContainer(java.lang.String identity)
identity
- the container identity.java.lang.IllegalArgumentException
- if identity is null.public static Value createRoom(java.lang.String identity)
identity
- the room identity.java.lang.IllegalArgumentException
- if identity is null.public static Value createPlayer(java.lang.String identity)
identity
- the player identity.java.lang.IllegalArgumentException
- if identity is null.public static Value createAction(java.lang.String identity)
identity
- the action identity.java.lang.IllegalArgumentException
- if identity is null.public static Value createWorld()
public static Value createVariable(java.lang.String name)
name
- the variable name.public static Value create(Value inputValue)
inputValue
- the input value.isReferenceCopied()
public static Value read(java.io.InputStream in) throws java.io.IOException
in
- the stream to read from.java.io.IOException
- if a value could not be read.public static Value read(java.util.Map<java.lang.Long,Value> referenceMap, java.io.InputStream in) throws java.io.IOException
referenceMap
- the reference map to use for "seen" value references.in
- the stream to read from.java.io.IOException
- if a value could not be read.public int hashCode()
hashCode
in class java.lang.Object
public boolean equalsIgnoreType(Value otherValue)
otherValue
- the other value.public boolean equals(Value otherValue)
otherValue
- the other value.public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public int compareTo(Value v)
compareTo
in interface java.lang.Comparable<Value>
public void writeReferentialBytes(java.util.concurrent.atomic.AtomicLong referenceCounter, java.util.Map<java.lang.Object,java.lang.Long> referenceSet, java.io.OutputStream out) throws java.io.IOException
ReferenceSaveable
writeReferentialBytes
in interface ReferenceSaveable
referenceCounter
- the reference counter to use for when unique values are seen.referenceSet
- the reference set to use for "seen" value references - maps object reference to counter value.out
- the output stream to write to.java.io.IOException
- if a write problem occurs.public void readReferentialBytes(java.util.Map<java.lang.Long,Value> referenceMap, java.io.InputStream in) throws java.io.IOException
ReferenceSaveable
readReferentialBytes
in interface ReferenceSaveable
referenceMap
- the reference map to use for "seen" value references.in
- the input stream to read from.java.io.IOException
- if a read problem occurs.public void writeBytes(java.io.OutputStream out) throws java.io.IOException
Saveable
writeBytes
in interface Saveable
out
- the output stream to write to.java.io.IOException
- if a write problem occurs.public void readBytes(java.io.InputStream in) throws java.io.IOException
Saveable
public ValueType getType()
public java.lang.Object getValue()
public boolean asBoolean()
public long asLong()
public double asDouble()
Double.NaN
if not parsable as a number.public java.lang.String asString()
public boolean isTrue()
true
.public boolean isNaN()
NaN
.public boolean isStrictlyNaN()
NaN
.public boolean isInfinite()
public boolean isBoolean()
public boolean isInteger()
public boolean isFloatingPoint()
public boolean isNumeric()
public boolean isString()
public boolean isList()
public boolean isLiteral()
public boolean isReferenceCopied()
public boolean isElement()
public boolean isObjectContainer()
public boolean isAction()
public boolean isVariable()
public boolean isEmpty()
public int length()
public boolean listAdd(Value v)
v
- the value to add.public boolean listAddAt(int i, Value v)
i
is less than 0.i
- the index to add the value at.v
- the value to add.public boolean listSet(int i, Value v)
i
- the index to set.v
- the value to set.public Value listGet(int i)
i
- the index to get.create(Value)
) or false if not found.public boolean listRemove(Value v)
v
- the value to remove.public Value listRemoveAt(int i)
i
- the index to get.create(Value)
) or false if not found.public int listIndexOf(Value v)
v
- the value to search for.public boolean listContains(Value v)
v
- the value to search for.public java.lang.String toString()
toString
in class java.lang.Object
public static Value absolute(Value value1)
value1
- the first operand.public static Value negate(Value value1)
value1
- the first operand.java.lang.ArithmeticException
- If an arithmetic exception occurs.public static Value logicalNot(Value value1)
value1
- the first operand.public static Value add(Value value1, Value value2)
value1
- the first operand.value2
- the second operand.public static Value subtract(Value value1, Value value2)
value1
- the first operand.value2
- the second operand.public static Value multiply(Value value1, Value value2)
value1
- the first operand.value2
- the second operand.public static Value divide(Value value1, Value value2)
value1
- the first operand.value2
- the second operand.java.lang.ArithmeticException
- an arithmetic exception, if any (or divide by zero).public static Value modulo(Value value1, Value value2)
value1
- the first operand.value2
- the second operand.java.lang.ArithmeticException
- an arithmetic exception, if any (or divide by zero).public static Value power(Value value1, Value value2)
value1
- the first operand.value2
- the second operand.java.lang.ArithmeticException
- an arithmetic exception, if any (or divide by zero).public static Value logicalAnd(Value value1, Value value2)
value1
- the first operand.value2
- the second operand.java.lang.ArithmeticException
- If an arithmetic exception occurs.public static Value logicalOr(Value value1, Value value2)
value1
- the first operand.value2
- the second operand.java.lang.ArithmeticException
- If an arithmetic exception occurs.public static Value logicalXOr(Value value1, Value value2)
value1
- the first operand.value2
- the second operand.java.lang.ArithmeticException
- If an arithmetic exception occurs.public static Value equals(Value value1, Value value2)
value1
- the first operand.value2
- the second operand.java.lang.ArithmeticException
- If an arithmetic exception occurs.public static Value notEquals(Value value1, Value value2)
value1
- the first operand.value2
- the second operand.java.lang.ArithmeticException
- If an arithmetic exception occurs.public static Value strictEquals(Value value1, Value value2)
value1
- the first operand.value2
- the second operand.java.lang.ArithmeticException
- If an arithmetic exception occurs.public static Value strictNotEquals(Value value1, Value value2)
value1
- the first operand.value2
- the second operand.java.lang.ArithmeticException
- If an arithmetic exception occurs.public static Value less(Value value1, Value value2)
value1
- the first operand.value2
- the second operand.java.lang.ArithmeticException
- If an arithmetic exception occurs.public static Value lessOrEqual(Value value1, Value value2)
value1
- the first operand.value2
- the second operand.java.lang.ArithmeticException
- If an arithmetic exception occurs.public static Value greater(Value value1, Value value2)
value1
- the first operand.value2
- the second operand.java.lang.ArithmeticException
- If an arithmetic exception occurs.public static Value greaterOrEqual(Value value1, Value value2)
value1
- the first operand.value2
- the second operand.java.lang.ArithmeticException
- If an arithmetic exception occurs.