Class LiteralExpression


  • public final class LiteralExpression
    extends JmespathExpression
    Represents a literal value.
    • Field Detail

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

      • LiteralExpression

        public LiteralExpression​(java.lang.Object value)
      • LiteralExpression

        public LiteralExpression​(java.lang.Object value,
                                 int line,
                                 int column)
    • Method Detail

      • from

        public static LiteralExpression from​(java.lang.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 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 class java.lang.Object
      • hashCode

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

        public java.lang.String toString()
        Overrides:
        toString in class java.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 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​(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, 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 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.