Class LiteralValue

  • All Implemented Interfaces:
    java.lang.Cloneable

    public class LiteralValue
    extends Expression
    This expression class represents literal values. The value is stored as a Object to avoid complexity in the expression processing code, but it requires additional type checking and conversion, which makes it a bit slower than type-specific literal classes would be.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.Object value
      The literal value of this expression.
    • Constructor Summary

      Constructors 
      Constructor Description
      LiteralValue​(java.lang.Object value)  
    • Field Detail

      • value

        private java.lang.Object value
        The literal value of this expression.
    • Constructor Detail

      • LiteralValue

        public LiteralValue​(java.lang.Object value)
    • Method Detail

      • getColumnInfo

        public ColumnInfo getColumnInfo​(Schema schema)
                                 throws SchemaNameException
        Description copied from class: Expression
        Returns a ColumnInfo object describing the type (and possibly the name) of the expression's result.
        Specified by:
        getColumnInfo in class Expression
        Parameters:
        schema - a schema object that can be used to look up name and type details for symbols referenced by the expression.
        Returns:
        a column-information object describing the type (and possibly the name and table-name) of this expression's result
        Throws:
        SchemaNameException - if a symbol cannot be resolved, either because it doesn't appear in the schema, or because the name is ambiguous.
      • evaluate

        public java.lang.Object evaluate​(Environment env)
        For literal values, evaluation simply involves returning the literal value.
        Specified by:
        evaluate in class Expression
        Parameters:
        env - the environment to look up symbol-values from, when evaluating the expression
        Returns:
        the result of the expression evaluation
      • traverse

        public Expression traverse​(ExpressionProcessor p)
        Description copied from class: Expression

        This method allows the entire expression tree to be traversed node by node, either for analysis or for transformation. The ExpressionProcessor instance receives notifications as each node in the expression is entered and left.

        The expression tree can also be manipulated by this traversal process, depending on what the ExpressionProcessor wants to do. If the expression node that traverse() is invoked on, needs to be replaced with a new expression node, the replacement is returned by the traverse() method. (The ExpressionProcessor specifies the replacement as the return-value from the ExpressionProcessor.leave(Expression) method.)

        Specified by:
        traverse in class Expression
        Parameters:
        p - the object that performs analysis or transformation of the expression tree
        Returns:
        an Expression node to replace this node, or null if no changes are to be made.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • simplify

        public Expression simplify()
        Literal values cannot be simplified any further, so this method just returns the expression it's called on.
        Overrides:
        simplify in class Expression
        Returns:
        a reference to an expression, either a simplified version of this expression, or the original unmodified expression
      • equals

        public boolean equals​(java.lang.Object obj)
        Checks if the argument is an expression with the same structure, but not necessarily the same references.
        Specified by:
        equals in class Expression
        Parameters:
        obj - the object to which we are comparing
        Design Note:
        This function operates correctly on the assumption that all supported types override Object.equals().
      • hashCode

        public int hashCode()
        Computes the hashcode of an Expression. This method is used to see if two expressions might be equal.
        Specified by:
        hashCode in class Expression
      • clone

        protected java.lang.Object clone()
                                  throws java.lang.CloneNotSupportedException
        Creates a copy of expression.
        Overrides:
        clone in class Expression
        Throws:
        java.lang.CloneNotSupportedException
        Design Note:
        The reference of the internal value is simply copied since the value types are all immutable.