Class Value

java.lang.Object
org.oristool.lello.Value

public class Value extends Object
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

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    Represents the value type.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Value(boolean booleanValue)
    Initializes a value to a given boolean.
    Value(double realValue)
    Initializes a value to a given real.
    Value(int integerValue)
    Initializes a value to a given integer.
    Value(String stringValue)
    Initializes a value to a given string.
  • Method Summary

    Modifier and Type
    Method
    Description
    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.
    Returns the type of this value.
    int
     
    boolean
    Returns whether this value is of type BOOLEAN or not.
    boolean
    Returns whether this value is of type INTEGER or not.
    boolean
    Returns whether this value is nil or not.
    boolean
    Returns whether this value is numeric, which means either INTEGER or REAL.
    boolean
    Returns whether this value is of type REAL or not.
    boolean
    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.
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Value

      public Value(String stringValue)
      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

      public Value 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

      public static Value nil()
      Returns the nil value.
      Returns:
      The nil value.
    • parseBoolean

      public static Value parseBoolean(String s)
      Creates a BOOLEAN value from a Java string.
      Parameters:
      s - The input Java string.
      Returns:
      The parsed value.
    • parseInteger

      public static Value parseInteger(String s)
      Creates an INTEGER value from a Java string.
      Parameters:
      s - The input Java string.
      Returns:
      The parsed value.
    • parseReal

      public static Value parseReal(String s)
      Creates a REAL value from a Java string.
      Parameters:
      s - The input Java string.
      Returns:
      The parsed value.
    • parseString

      public static Value parseString(String s)
      Creates a STRING value from a Java string.
      Parameters:
      s - The input Java string.
      Returns:
      The parsed value.
    • getType

      public Value.Type getType()
      Returns the type of this value.
      Returns:
      The type of this value.
    • getStringValue

      public String 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

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object