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 Details

    • 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.
  • Constructor Details

    • LiteralExpression

      public LiteralExpression(Object value)
    • LiteralExpression

      public LiteralExpression(Object value, int line, int column)
  • Method Details

    • from

      public static LiteralExpression from(Object value)
      Creates a LiteralExpression from value, 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 class JmespathExpression
      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 Object getValue()
      Gets the nullable value contained in the literal value.
      Returns:
      Returns the contained value.
    • equals

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

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

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

      public RuntimeType getType()
      Gets the type of the value.
      Returns:
      Returns the literal expression's runtime type.
    • getObjectField

      public LiteralExpression getObjectField(String name)
      Expects the value to be an object and gets a field by name. If the field does not exist, then a LiteralExpression 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(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, a LiteralExpression 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 String expectStringValue()
      Gets the value as a string.
      Returns:
      Returns the string value.
      Throws:
      JmespathException - if the value is not a string.
    • expectNumberValue

      public 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 List<Object> expectArrayValue()
      Gets the value as an array.
      Returns:
      Returns the array value.
      Throws:
      JmespathException - if the value is not an array.
    • expectObjectValue

      public Map<String,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.