org.geotools.filter
Class CompareFilterImpl

java.lang.Object
  extended byorg.geotools.filter.AbstractFilter
      extended byorg.geotools.filter.AbstractFilterImpl
          extended byorg.geotools.filter.CompareFilterImpl
All Implemented Interfaces:
CompareFilter, Filter, FilterType
Direct Known Subclasses:
BetweenFilterImpl

public class CompareFilterImpl
extends AbstractFilterImpl
implements CompareFilter

Defines a comparison filter (can be a math comparison or generic equals). This filter implements a comparison - of some sort - between two expressions. The comparison may be a math comparison or a generic equals comparison. If it is a math comparison, only math expressions are allowed; if it is an equals comparison, any expression types are allowed. Note that this comparison does not attempt to restrict its expressions to be meaningful. This means that it considers itself a valid filter as long as the expression comparison returns a valid result. It does no checking to see whether or not the expression comparison is meaningful with regard to checking feature attributes. In other words, this is a valid filter: 52 = 92, even though it will always return the same result and could be simplified away. It is up the the filter creator, therefore, to attempt to simplify/make meaningful filter logic.

Version:
$Id: CompareFilterImpl.java,v 1.12 2004/03/13 06:25:31 cholmesny Exp $
Author:
Rob Hranac, Vision for New York

Field Summary
protected  Expression leftValue
          Holds the 'left' value of this comparison filter.
protected  Expression rightValue
          Holds the 'right' value of this comparison filter.
 
Fields inherited from class org.geotools.filter.AbstractFilter
filterType, permissiveConstruction
 
Fields inherited from interface org.geotools.filter.Filter
ALL, NONE
 
Fields inherited from interface org.geotools.filter.FilterType
BETWEEN, COMPARE_EQUALS, COMPARE_GREATER_THAN, COMPARE_GREATER_THAN_EQUAL, COMPARE_LESS_THAN, COMPARE_LESS_THAN_EQUAL, COMPARE_NOT_EQUALS, FID, GEOMETRY_BBOX, GEOMETRY_BEYOND, GEOMETRY_CONTAINS, GEOMETRY_CROSSES, GEOMETRY_DISJOINT, GEOMETRY_DWITHIN, GEOMETRY_EQUALS, GEOMETRY_INTERSECTS, GEOMETRY_OVERLAPS, GEOMETRY_TOUCHES, GEOMETRY_WITHIN, LIKE, LOGIC_AND, LOGIC_NOT, LOGIC_OR, NULL
 
Constructor Summary
protected CompareFilterImpl(short filterType)
          Constructor with filter type.
 
Method Summary
 void accept(FilterVisitor visitor)
          Used by FilterVisitors to perform some action on this filter instance.
 void addLeftValue(Expression leftValue)
          Adds the 'left' value to this filter.
 void addRightValue(Expression rightValue)
          Adds the 'right' value to this filter.
 boolean contains(Feature feature)
          Determines whether or not a given feature is 'inside' this filter.
 boolean equals(java.lang.Object obj)
          Compares this filter to the specified object.
 Expression getLeftValue()
          Gets the left expression.
 Expression getRightValue()
          Gets the right expression.
 int hashCode()
          Override of hashCode method.
 java.lang.String toString()
          Returns a string representation of this filter.
 
Methods inherited from class org.geotools.filter.AbstractFilterImpl
and, not, or
 
Methods inherited from class org.geotools.filter.AbstractFilter
getFilterType, isCompareFilter, isGeometryDistanceFilter, isGeometryFilter, isLogicFilter, isMathFilter, isSimpleFilter
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.geotools.filter.Filter
and, getFilterType, not, or
 

Field Detail

leftValue

protected Expression leftValue
Holds the 'left' value of this comparison filter.


rightValue

protected Expression rightValue
Holds the 'right' value of this comparison filter.

Constructor Detail

CompareFilterImpl

protected CompareFilterImpl(short filterType)
                     throws IllegalFilterException
Constructor with filter type.

Parameters:
filterType - The type of comparison.
Throws:
IllegalFilterException - Non-compare type.
Method Detail

addLeftValue

public void addLeftValue(Expression leftValue)
                  throws IllegalFilterException
Adds the 'left' value to this filter.

Specified by:
addLeftValue in interface CompareFilter
Parameters:
leftValue - Expression for 'left' value.
Throws:
IllegalFilterException - Filter is not internally consistent.
Task:
REVISIT: immutability?

addRightValue

public void addRightValue(Expression rightValue)
                   throws IllegalFilterException
Adds the 'right' value to this filter.

Specified by:
addRightValue in interface CompareFilter
Parameters:
rightValue - Expression for 'right' value.
Throws:
IllegalFilterException - Filter is not internally consistent.
Task:
REVISIT: make immutable.

getLeftValue

public Expression getLeftValue()
Gets the left expression.

Specified by:
getLeftValue in interface CompareFilter
Returns:
The expression on the left of the comparison.

getRightValue

public Expression getRightValue()
Gets the right expression.

Specified by:
getRightValue in interface CompareFilter
Returns:
The expression on the right of the comparison.

contains

public boolean contains(Feature feature)
Determines whether or not a given feature is 'inside' this filter.

Specified by:
contains in interface CompareFilter
Specified by:
contains in class AbstractFilter
Parameters:
feature - Specified feature to examine.
Returns:
Flag confirming whether or not this feature is inside the filter.

toString

public java.lang.String toString()
Returns a string representation of this filter.

Returns:
String representation of the compare filter.

equals

public boolean equals(java.lang.Object obj)
Compares this filter to the specified object. Returns true if the passed in object is the same as this filter. Checks to make sure the filter types are the same as well as both of the values.

Parameters:
obj - - the object to compare this CompareFilter against.
Returns:
true if specified object is equal to this filter; false otherwise.

hashCode

public int hashCode()
Override of hashCode method.

Returns:
a code to hash this object by.

accept

public void accept(FilterVisitor visitor)
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.

Specified by:
accept in interface Filter
Specified by:
accept in class AbstractFilter
Parameters:
visitor - The visitor which requires access to this filter, the method must call visitor.visit(this);


Copyright © GeoTools. All Rights Reserved.