Class LiteralExpression
- java.lang.Object
-
- software.amazon.smithy.jmespath.JmespathExpression
-
- software.amazon.smithy.jmespath.ast.LiteralExpression
-
public final class LiteralExpression extends JmespathExpression
Represents a literal value.
-
-
Field Summary
Fields Modifier and Type Field Description static LiteralExpression
ANY
Sentinel value to represent ANY.static LiteralExpression
ARRAY
Sentinel value to represent any ARRAY.static LiteralExpression
BOOLEAN
Sentinel value to represent any BOOLEAN.static LiteralExpression
EXPREF
Sentinel value to represent an expression reference.static LiteralExpression
NULL
Sentinel value to represent null.static LiteralExpression
NUMBER
Sentinel value to represent any NULL.static LiteralExpression
OBJECT
Sentinel value to represent any OBJECT.static LiteralExpression
STRING
Sentinel value to represent any STRING.
-
Constructor Summary
Constructors Constructor Description LiteralExpression(java.lang.Object value)
LiteralExpression(java.lang.Object value, int line, int column)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> T
accept(ExpressionVisitor<T> visitor)
Visits a node using a double-dispatch visitor.boolean
equals(java.lang.Object o)
java.util.List<java.lang.Object>
expectArrayValue()
Gets the value as an array.boolean
expectBooleanValue()
Gets the value as a boolean.java.lang.Number
expectNumberValue()
Gets the value as a number.java.util.Map<java.lang.String,java.lang.Object>
expectObjectValue()
Gets the value as an object.java.lang.String
expectStringValue()
Gets the value as a string.static LiteralExpression
from(java.lang.Object value)
Creates a LiteralExpression fromvalue
, unwrapping it if necessary.LiteralExpression
getArrayIndex(int index)
Expects the value to be an array and gets the value at the given index.LiteralExpression
getObjectField(java.lang.String name)
Expects the value to be an object and gets a field by name.RuntimeType
getType()
Gets the type of the value.java.lang.Object
getValue()
Gets the nullable value contained in the literal value.int
hashCode()
boolean
hasObjectField(java.lang.String name)
Expects the value to be an object and checks if it contains a field by name.boolean
isArrayValue()
Checks if the value is an array.boolean
isBooleanValue()
Checks if the value is a boolean.boolean
isNullValue()
Checks if the value is null.boolean
isNumberValue()
Checks if the value is a number.boolean
isObjectValue()
Checks if the value is an object.boolean
isStringValue()
Checks if the value is a string.boolean
isTruthy()
Returns true if the value is truthy according to JMESPath.java.lang.String
toString()
-
-
-
Field Detail
-
ANY
public static final LiteralExpression ANY
Sentinel value to represent ANY.
-
ARRAY
public static final LiteralExpression ARRAY
Sentinel value to represent any ARRAY.
-
OBJECT
public static final LiteralExpression OBJECT
Sentinel value to represent any OBJECT.
-
BOOLEAN
public static final LiteralExpression BOOLEAN
Sentinel value to represent any BOOLEAN.
-
STRING
public static final LiteralExpression STRING
Sentinel value to represent any STRING.
-
NUMBER
public static final LiteralExpression NUMBER
Sentinel value to represent any NULL.
-
EXPREF
public static final LiteralExpression EXPREF
Sentinel value to represent an expression reference.
-
NULL
public static final LiteralExpression NULL
Sentinel value to represent null.
-
-
Method Detail
-
from
public static LiteralExpression from(java.lang.Object value)
Creates a LiteralExpression fromvalue
, unwrapping it if necessary.- Parameters:
value
- Value to create the expression from.- Returns:
- Returns the LiteralExpression of the given
value
.
-
accept
public <T> T accept(ExpressionVisitor<T> visitor)
Description copied from class:JmespathExpression
Visits a node using a double-dispatch visitor.- Specified by:
accept
in classJmespathExpression
- Type Parameters:
T
- Type of value the visitor returns.- Parameters:
visitor
- Visitor to accept on the node.- Returns:
- Returns the result of applying the visitor.
-
getValue
public java.lang.Object getValue()
Gets the nullable value contained in the literal value.- Returns:
- Returns the contained value.
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getType
public RuntimeType getType()
Gets the type of the value.- Returns:
- Returns the literal expression's runtime type.
-
getObjectField
public LiteralExpression getObjectField(java.lang.String name)
Expects the value to be an object and gets a field by name. If the field does not exist, then aLiteralExpression
with a null value is returned.- Parameters:
name
- Field to get from the expected object.- Returns:
- Returns the object field value.
-
hasObjectField
public boolean hasObjectField(java.lang.String name)
Expects the value to be an object and checks if it contains a field by name.- Parameters:
name
- Field to get from the expected object.- Returns:
- Returns true if the object contains the given key.
-
getArrayIndex
public LiteralExpression getArrayIndex(int index)
Expects the value to be an array and gets the value at the given index. If the index is negative, it is computed to the array length minus the index. If the computed index does not exist, aLiteralExpression
with a null value is returned.- Parameters:
index
- Index to get from the array.- Returns:
- Returns the array value.
-
isStringValue
public boolean isStringValue()
Checks if the value is a string.- Returns:
- Returns true if the value is a string.
-
isNumberValue
public boolean isNumberValue()
Checks if the value is a number.- Returns:
- Returns true if the value is a number.
-
isBooleanValue
public boolean isBooleanValue()
Checks if the value is a boolean.- Returns:
- Returns true if the value is a boolean.
-
isArrayValue
public boolean isArrayValue()
Checks if the value is an array.- Returns:
- Returns true if the value is an array.
-
isObjectValue
public boolean isObjectValue()
Checks if the value is an object.- Returns:
- Returns true if the value is an object.
-
isNullValue
public boolean isNullValue()
Checks if the value is null.- Returns:
- Returns true if the value is null.
-
expectStringValue
public java.lang.String expectStringValue()
Gets the value as a string.- Returns:
- Returns the string value.
- Throws:
JmespathException
- if the value is not a string.
-
expectNumberValue
public java.lang.Number expectNumberValue()
Gets the value as a number.- Returns:
- Returns the number value.
- Throws:
JmespathException
- if the value is not a number.
-
expectBooleanValue
public boolean expectBooleanValue()
Gets the value as a boolean.- Returns:
- Returns the boolean value.
- Throws:
JmespathException
- if the value is not a boolean.
-
expectArrayValue
public java.util.List<java.lang.Object> expectArrayValue()
Gets the value as an array.- Returns:
- Returns the array value.
- Throws:
JmespathException
- if the value is not an array.
-
expectObjectValue
public java.util.Map<java.lang.String,java.lang.Object> expectObjectValue()
Gets the value as an object.- Returns:
- Returns the object value.
- Throws:
JmespathException
- if the value is not an object.
-
isTruthy
public boolean isTruthy()
Returns true if the value is truthy according to JMESPath.- Returns:
- Returns true or false if truthy.
-
-