public class Constant extends NonStatement implements IExpression
This AST element represents a literal, or constant value.
Constant types are one of the eight primitive types (boolean, byte, char, short, int, long, float, double) or a literal string.
Constants can be created via the use of a Constant.Builder
.
Note: Constants are read-only elements.
Modifier and Type | Class and Description |
---|---|
static class |
Constant.Builder
This class is used to generate AST
Constant elements. |
Modifier and Type | Method and Description |
---|---|
boolean |
getBoolean()
Retrieve the boolean value.
|
byte |
getByte()
Retrieve the byte value.
|
char |
getChar()
Retrieve the character value.
|
double |
getDouble()
Retrieve the double value.
|
float |
getFloat()
Retrieve the float value.
|
int |
getInt()
Retrieve the integer value.
|
long |
getLong()
Retrieve the long value.
|
short |
getShort()
Retrieve the short value.
|
java.lang.String |
getString()
Retrieve the string value.
|
java.lang.String |
getType()
Retrieve the constant type.
|
boolean |
isFalse()
Determine if a constant is the false literal.
|
boolean |
isMinusOne()
Determine if a constant is a numeric literal whose value is -1.
|
boolean |
isNegative()
Determine if a constant is a numeric literal whose value is strictly negative.
|
boolean |
isNull()
Determine if the constant is the 'null' literal.
|
boolean |
isOne()
Determine if a constant is a numeric literal whose value is 1.
|
boolean |
isPositive()
Determine if a constant is a numeric literal whose value is strictly positive.
|
boolean |
isString()
Determine if the constant is of type
java.lang.String . |
boolean |
isTrue()
Determine if a constant is the true literal.
|
boolean |
isZero()
Determine if a constant is a numeric literal whose value is 0.
|
attachTag, getSubElements, replaceSubElement, retrieveTag
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
attachTag, getSubElements, replaceSubElement, retrieveTag
public java.lang.String getType()
Retrieve the constant type.
public boolean isNull()
Determine if the constant is the 'null' literal.
public boolean isString()
Determine if the constant is of type java.lang.String
. Convenience routine.
public boolean getBoolean()
Retrieve the boolean value.
java.lang.IllegalStateException
- if the constant is not a booleanpublic byte getByte()
Retrieve the byte value.
java.lang.IllegalStateException
- if the constant is not a bytepublic char getChar()
Retrieve the character value.
java.lang.IllegalStateException
- if the constant is not a charpublic short getShort()
Retrieve the short value.
java.lang.IllegalStateException
- if the constant is not a shortpublic int getInt()
Retrieve the integer value.
java.lang.IllegalStateException
- if the constant is not an intpublic long getLong()
Retrieve the long value.
java.lang.IllegalStateException
- if the constant is not a longpublic float getFloat()
Retrieve the float value.
java.lang.IllegalStateException
- if the constant is not a floatpublic double getDouble()
Retrieve the double value.
java.lang.IllegalStateException
- if the constant is not a doublepublic java.lang.String getString()
Retrieve the string value.
java.lang.IllegalStateException
- if the constant is not a stringpublic boolean isTrue()
Determine if a constant is the true literal. This method does not raise.
public boolean isFalse()
Determine if a constant is the false literal. This method does not raise.
public boolean isZero()
Determine if a constant is a numeric literal whose value is 0. This method does not raise.
public boolean isOne()
Determine if a constant is a numeric literal whose value is 1. This method does not raise.
public boolean isMinusOne()
Determine if a constant is a numeric literal whose value is -1. This method does not raise.
public boolean isPositive()
Determine if a constant is a numeric literal whose value is strictly positive. This method does not raise.
public boolean isNegative()
Determine if a constant is a numeric literal whose value is strictly negative. This method does not raise.