org.geotools.filter
Class ConstantExpression

Object
  extended by ConstantExpression
All Implemented Interfaces:
Cloneable, ExpressionType, LiteralExpression, Expression, Literal
Direct Known Subclasses:
OverlapBehavior

public class ConstantExpression
extends Object
implements LiteralExpression, Cloneable

The Expression class is not immutable!

However we do have a need for immutable literal expressions when defining our API for SLD, and any other standards based on Expression.

Author:
Jody Garnett, Refractions Research

Field Summary
static ConstantExpression BLACK
           
static ConstantExpression NULL
           
static ConstantExpression ONE
           
static ConstantExpression TWO
           
static ConstantExpression UNNAMED
           
static ConstantExpression ZERO
           
 
Fields inherited from interface ExpressionType
ATTRIBUTE, ATTRIBUTE_DOUBLE, ATTRIBUTE_GEOMETRY, ATTRIBUTE_INTEGER, ATTRIBUTE_STRING, ATTRIBUTE_UNDECLARED, FUNCTION, LITERAL_DOUBLE, LITERAL_GEOMETRY, LITERAL_INTEGER, LITERAL_LONG, LITERAL_STRING, LITERAL_UNDECLARED, MATH_ADD, MATH_DIVIDE, MATH_MULTIPLY, MATH_SUBTRACT
 
Fields inherited from interface Expression
NIL
 
Constructor Summary
protected ConstantExpression(Object value)
           
protected ConstantExpression(short type, Object value)
           
 
Method Summary
 Object accept(ExpressionVisitor visitor, Object extraData)
          Accepts a visitor.
 void accept(FilterVisitor visitor)
          Deprecated. use accept(ExpressionVisitor, Object).
protected  Object clone()
           
static ConstantExpression color(Color color)
          Encode provided color as a String
static ConstantExpression constant(double number)
           
static ConstantExpression constant(int number)
           
static ConstantExpression constant(Object value)
           
 boolean equals(Object obj)
           
 Object evaluate(Object object)
          Evaluates the given expression based on the content of the given object.
<T> T
evaluate(Object object, Class<T> context)
          Evaluates the given expressoin based on the content of the given object and the context type.
 Object evaluate(SimpleFeature feature)
          Evaluates the expression against an instance of Feature.
 Object getLiteral()
          Deprecated. use getValue()
 short getType()
          Returns the literal type.
 Object getValue()
          Returns the constant value held by this object.
 Object getValue(SimpleFeature feature)
          Deprecated. use #evaluate(Feature)
 int hashCode()
           
 void setLiteral(Object literal)
          Deprecated. use setValue(Object)
 void setValue(Object constant)
           
 String toString()
           
 
Methods inherited from class Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

NULL

public static final ConstantExpression NULL

BLACK

public static final ConstantExpression BLACK

ZERO

public static final ConstantExpression ZERO

ONE

public static final ConstantExpression ONE

TWO

public static final ConstantExpression TWO

UNNAMED

public static final ConstantExpression UNNAMED
Constructor Detail

ConstantExpression

protected ConstantExpression(Object value)

ConstantExpression

protected ConstantExpression(short type,
                             Object value)
Method Detail

setLiteral

public final void setLiteral(Object literal)
                      throws IllegalFilterException
Deprecated. use setValue(Object)

Description copied from interface: LiteralExpression
Sets the literal.

Specified by:
setLiteral in interface LiteralExpression
Parameters:
literal - The literal to store inside this expression.
Throws:
IllegalFilterException - This literal type is not in scope.

getValue

public final Object getValue(SimpleFeature feature)
Deprecated. use #evaluate(Feature)

Description copied from interface: LiteralExpression
Gets the value of this literal.

Specified by:
getValue in interface LiteralExpression
Parameters:
feature - Required by the interface but not used.
Returns:
the literal held by this expression. Ignores the passed in feature.

evaluate

public Object evaluate(SimpleFeature feature)
Description copied from interface: Expression
Evaluates the expression against an instance of Feature.

Parameters:
feature - The feature being evaluated.
Returns:
The result.

evaluate

public Object evaluate(Object object)
Description copied from interface: Expression
Evaluates the given expression based on the content of the given object.

Specified by:
evaluate in interface Expression

evaluate

public <T> T evaluate(Object object,
                      Class<T> context)
Description copied from interface: Expression
Evaluates the given expressoin based on the content of the given object and the context type.

The context parameter is used to control the type of the result of the expression. A particular expression may not be able to evaluate to an instance of context. Therefore to be safe calling code should do a null check on the return value of this method, and call Expression.evaluate(Object) if neccessary. Example:

  Object input = ...;
  String result = expression.evaluate( input, String.class );
  if ( result == null ) {
     result = expression.evalute( input ).toString();
  }
  ...
 

Implementations that can not return a result as an instance of context should return null.

Specified by:
evaluate in interface Expression
Type Parameters:
T - The type of the returned object.
Parameters:
object - The object to evaluate the expression against.
context - The type of the resulting value of the expression.
Returns:
Evaluates the given expression based on the content of the given object an an instance of context.

getValue

public Object getValue()
Description copied from interface: Literal
Returns the constant value held by this object.

Specified by:
getValue in interface Literal

setValue

public void setValue(Object constant)

getType

public short getType()
Description copied from interface: LiteralExpression
Returns the literal type.

Specified by:
getType in interface LiteralExpression
Returns:
the short representation of the literal expression type.

getLiteral

public final Object getLiteral()
Deprecated. use getValue()

Description copied from interface: LiteralExpression
Retrieves the literal of this expression.

Specified by:
getLiteral in interface LiteralExpression
Returns:
the literal held by this expression.

accept

public void accept(FilterVisitor visitor)
Deprecated. use accept(ExpressionVisitor, Object).

Description copied from interface: Expression
Used by FilterVisitors to perform some action on this filter instance. Typicaly used by Filter decoders, but may also be used by any thing which needs infomration from filter structure. Implementations should always call: visitor.visit(this); It is importatant that this is not left to a parent class unless the parents API is identical.

Parameters:
visitor - The visitor which requires access to this filter, the method must call visitor.visit(this);

accept

public Object accept(ExpressionVisitor visitor,
                     Object extraData)
Description copied from interface: Expression
Accepts a visitor. Subclasses must implement with a method whose content is the following:
return visitor.visit(this, extraData);

Specified by:
accept in interface Expression

clone

protected Object clone()
                throws CloneNotSupportedException
Overrides:
clone in class Object
Throws:
CloneNotSupportedException

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object

color

public static ConstantExpression color(Color color)
Encode provided color as a String


constant

public static ConstantExpression constant(double number)

constant

public static ConstantExpression constant(int number)

constant

public static ConstantExpression constant(Object value)


Copyright © 1996-2014 Geotools. All Rights Reserved.