Package org.oristool.lello
Class Value
java.lang.Object
org.oristool.lello.Value
Represent a value of one of the supported types in Lello. These are the
following:
- NIL: contains the only value nil, which corresponds to an undefined value;
- STRING: Unicode string;
- INTEGER: signed integer type;
- REAL: floating point number;
- BOOLEAN: either true or false.
Constructors and factory methods are provided to construct values any of these types from those in Java.
-
Nested Class Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptioncopy()
Creates a copy of this object.boolean
boolean
Retrieves the Java string contained in this BOOLEAN value; if this value is not a BOOLEAN an exception is thrown.int
Retrieves the Java string contained in this INTEGER value; if this value is not a INTEGER an exception is thrown.int
Casts the numeric value of this object to integer.double
Casts the numeric value of this object to real.double
Retrieves the Java string contained in this REAL value; if this value is not a REAL an exception is thrown.Retrieves the Java string contained in this STRING value; if this value is not a STRING an exception is thrown.getType()
Returns the type of this value.int
hashCode()
boolean
Returns whether this value is of type BOOLEAN or not.boolean
Returns whether this value is of type INTEGER or not.boolean
isNil()
Returns whether this value is nil or not.boolean
Returns whether this value is numeric, which means either INTEGER or REAL.boolean
isReal()
Returns whether this value is of type REAL or not.boolean
isString()
Returns whether this value is of type STRING or not.static Value
nil()
Returns the nil value.static Value
Creates a BOOLEAN value from a Java string.static Value
Creates an INTEGER value from a Java string.static Value
Creates a REAL value from a Java string.static Value
Creates a STRING value from a Java string.toString()
-
Constructor Details
-
Value
Initializes a value to a given string.- Parameters:
stringValue
- The initial value.
-
Value
public Value(int integerValue) Initializes a value to a given integer.- Parameters:
integerValue
- The initial value.
-
Value
public Value(double realValue) Initializes a value to a given real.- Parameters:
realValue
- The initial value.
-
Value
public Value(boolean booleanValue) Initializes a value to a given boolean.- Parameters:
booleanValue
- The initial value.
-
-
Method Details
-
copy
Creates a copy of this object.- Returns:
- a copy
-
isString
public boolean isString()Returns whether this value is of type STRING or not.- Returns:
- true if this value is a STRING, false otherwise.
-
isInteger
public boolean isInteger()Returns whether this value is of type INTEGER or not.- Returns:
- true if this value is a INTEGER, false otherwise.
-
isReal
public boolean isReal()Returns whether this value is of type REAL or not.- Returns:
- true if this value is a REAL, false otherwise.
-
isBoolean
public boolean isBoolean()Returns whether this value is of type BOOLEAN or not.- Returns:
- true if this value is a BOOLEAN, false otherwise.
-
isNil
public boolean isNil()Returns whether this value is nil or not.- Returns:
- true if this value is nil, false otherwise.
-
isNumeric
public boolean isNumeric()Returns whether this value is numeric, which means either INTEGER or REAL.- Returns:
- true if this value is either INTEGER or REAL, false otherwise.
-
getNumericValueAsReal
public double getNumericValueAsReal()Casts the numeric value of this object to real.This method requires this value to be numeric.
- Returns:
- The value as real.
-
getNumericValueAsInteger
public int getNumericValueAsInteger()Casts the numeric value of this object to integer.This method requires this value to be numeric.
- Returns:
- The value as integer.
-
nil
Returns the nil value.- Returns:
- The nil value.
-
parseBoolean
Creates a BOOLEAN value from a Java string.- Parameters:
s
- The input Java string.- Returns:
- The parsed value.
-
parseInteger
Creates an INTEGER value from a Java string.- Parameters:
s
- The input Java string.- Returns:
- The parsed value.
-
parseReal
Creates a REAL value from a Java string.- Parameters:
s
- The input Java string.- Returns:
- The parsed value.
-
parseString
Creates a STRING value from a Java string.- Parameters:
s
- The input Java string.- Returns:
- The parsed value.
-
getType
Returns the type of this value.- Returns:
- The type of this value.
-
getStringValue
Retrieves the Java string contained in this STRING value; if this value is not a STRING an exception is thrown.- Returns:
- the string value
-
getIntegerValue
public int getIntegerValue()Retrieves the Java string contained in this INTEGER value; if this value is not a INTEGER an exception is thrown.- Returns:
- the integer value
-
getRealValue
public double getRealValue()Retrieves the Java string contained in this REAL value; if this value is not a REAL an exception is thrown.- Returns:
- the real value
-
getBooleanValue
public boolean getBooleanValue()Retrieves the Java string contained in this BOOLEAN value; if this value is not a BOOLEAN an exception is thrown.- Returns:
- the boolean value
-
toString
-
equals
-
hashCode
public int hashCode()
-