info.sswap.http.representation
Class LiteralValue

java.lang.Object
  extended by info.sswap.http.representation.ValueBase
      extended by info.sswap.http.representation.LiteralValue
All Implemented Interfaces:
Value

public class LiteralValue
extends ValueBase

Represents a value (e.g., of a property) in the intermediate representation.

Author:
Blazej Bulka

Field Summary
private  java.lang.String datatype
          An optional information about the datatype.
private  java.lang.String internalRepresentation
          The internal representation of the value as string.
 
Constructor Summary
LiteralValue(java.lang.String datatype, boolean value)
          Creates a new value object initialized with a boolean value.
LiteralValue(java.lang.String datatype, double value)
          Creates a new value object initialized with a double value
LiteralValue(java.lang.String datatype, int value)
          Creates a new value object initialized with an integer value
LiteralValue(java.lang.String datatype, java.lang.String string)
          Creates a new value and initializes it with the given string value.
 
Method Summary
 boolean asBoolean()
          Gets the boolean representation of this value
 double asDouble()
          Returns the representation of this value as a double
 int asInteger()
          Returns the representation of this value as an integer
 LiteralValue asLiteral()
          Returns this value as a literal.
 java.lang.String asString()
          Returns the representation of this value as string (without the quotes).
 java.lang.String getDatatype()
          Gets the URI of the datatype (may be null)
 boolean isBoolean()
          Checks whether this value can be as a boolean (i.e., contains "true" or "false", case insensitive)
 boolean isDouble()
          Checks whether this value can be represented as a double
 boolean isInteger()
          Checks whether this value is a valid integer.
 boolean isLiteral()
          Checks whether this value is a literal (i.e., not an array or entity)
 void setDatatype(java.lang.String datatype)
          Sets the URI of the datatype
 
Methods inherited from class info.sswap.http.representation.ValueBase
asArray, asEntity, isArray, isEntity
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

datatype

private java.lang.String datatype
An optional information about the datatype. It should contain the URI of the datatype or null.


internalRepresentation

private java.lang.String internalRepresentation
The internal representation of the value as string. (Null for arrays.)

Constructor Detail

LiteralValue

public LiteralValue(java.lang.String datatype,
                    java.lang.String string)
Creates a new value and initializes it with the given string value.

Parameters:
datatype - the URI of the datatype or null
string - the string value or null

LiteralValue

public LiteralValue(java.lang.String datatype,
                    boolean value)
Creates a new value object initialized with a boolean value.

Parameters:
datatype - the URI of the datatype or null
value - the boolean value

LiteralValue

public LiteralValue(java.lang.String datatype,
                    int value)
Creates a new value object initialized with an integer value

Parameters:
datatype - the URI of the datatype or null
value - the integer value

LiteralValue

public LiteralValue(java.lang.String datatype,
                    double value)
Creates a new value object initialized with a double value

Parameters:
datatype - the URI of the datatype or null
value - the double value
Method Detail

getDatatype

public java.lang.String getDatatype()
Gets the URI of the datatype (may be null)

Returns:
the URI of the datatype or null

setDatatype

public void setDatatype(java.lang.String datatype)
Sets the URI of the datatype

Parameters:
datatype - the new URI of the datatype or null

isLiteral

public boolean isLiteral()
Description copied from interface: Value
Checks whether this value is a literal (i.e., not an array or entity)

Specified by:
isLiteral in interface Value
Overrides:
isLiteral in class ValueBase
Returns:
true if this value is a literal

asLiteral

public LiteralValue asLiteral()
Description copied from interface: Value
Returns this value as a literal.

Specified by:
asLiteral in interface Value
Overrides:
asLiteral in class ValueBase
Returns:
this value typed as LiteralValue

asString

public java.lang.String asString()
Description copied from interface: Value
Returns the representation of this value as string (without the quotes).

Specified by:
asString in interface Value
Overrides:
asString in class ValueBase
Returns:
the string representation of this value

isInteger

public boolean isInteger()
Description copied from interface: Value
Checks whether this value is a valid integer.

Specified by:
isInteger in interface Value
Overrides:
isInteger in class ValueBase
Returns:
true, if this is a valid integer, false otherwise

asInteger

public int asInteger()
              throws java.lang.IllegalArgumentException
Description copied from interface: Value
Returns the representation of this value as an integer

Specified by:
asInteger in interface Value
Overrides:
asInteger in class ValueBase
Returns:
the representation of this value as an integer
Throws:
java.lang.IllegalArgumentException - if this value cannot be represented as an integer (isInteger() should return false in such a case)

isDouble

public boolean isDouble()
Description copied from interface: Value
Checks whether this value can be represented as a double

Specified by:
isDouble in interface Value
Overrides:
isDouble in class ValueBase
Returns:
true if this is a valid double, false otherwise

asDouble

public double asDouble()
                throws java.lang.IllegalArgumentException
Description copied from interface: Value
Returns the representation of this value as a double

Specified by:
asDouble in interface Value
Overrides:
asDouble in class ValueBase
Returns:
the representation of this value as a double
Throws:
java.lang.IllegalArgumentException - if this value cannot be represented as a double (isDouble() should return false in such a case)

isBoolean

public boolean isBoolean()
Description copied from interface: Value
Checks whether this value can be as a boolean (i.e., contains "true" or "false", case insensitive)

Specified by:
isBoolean in interface Value
Overrides:
isBoolean in class ValueBase
Returns:
true if this value can be a boolean, false otherwise

asBoolean

public boolean asBoolean()
Description copied from interface: Value
Gets the boolean representation of this value

Specified by:
asBoolean in interface Value
Overrides:
asBoolean in class ValueBase
Returns:
true if the value contains "true" (case insensitive), false otherwise


Copyright (c) 2010, iPlant Collaborative, University of Arizona, Cold Spring Harbor Laboratories, University of Texas at Austin.