org.geotools.filter
Class LikeFilterImpl

java.lang.Object
  extended byorg.geotools.filter.AbstractFilter
      extended byorg.geotools.filter.AbstractFilterImpl
          extended byorg.geotools.filter.LikeFilterImpl
All Implemented Interfaces:
Filter, FilterType, LikeFilter

public class LikeFilterImpl
extends AbstractFilterImpl
implements LikeFilter

Defines a like filter, which checks to see if an attribute matches a REGEXP.

Version:
$Id: LikeFilterImpl.java,v 1.8 2003/08/11 18:48:25 cholmesny Exp $
Author:
Rob Hranac, Vision for New York

Field Summary
 
Fields inherited from class org.geotools.filter.AbstractFilter
filterType, LOGGER, 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 LikeFilterImpl()
          Constructor which flags the operator as like.
 
Method Summary
 void accept(FilterVisitor visitor)
          Used by FilterVisitors to perform some action on this filter instance.
 boolean contains(Feature feature)
          Determines whether or not a given feature matches this pattern.
static java.lang.String convertToSQL92(char escape, char multi, char single, java.lang.String pattern)
          Given OGC PropertyIsLike Filter information, construct an SQL-compatible 'like' pattern.
 boolean equals(java.lang.Object obj)
          Compares this filter to the specified object.
 java.lang.String getEscape()
          Getter for property escape.
 java.lang.String getPattern()
          Accessor method to retrieve the pattern.
 java.lang.String getSQL92LikePattern()
          see convertToSQL92
 Expression getValue()
          Gets the Value (left hand side) of this filter.
 java.lang.String getWildcardMulti()
          Getter for property wildcardMulti.
 java.lang.String getWildcardSingle()
          Getter for property wildcardSingle.
 int hashCode()
          Override of hashCode method.
 void setPattern(Expression p, java.lang.String wildcardMulti, java.lang.String wildcardSingle, java.lang.String escape)
          Sets the match pattern for this FilterLike.
 void setPattern(java.lang.String pattern, java.lang.String wildcardMulti, java.lang.String wildcardSingle, java.lang.String escape)
          Sets the match pattern for this FilterLike.
 void setValue(Expression attribute)
          Sets the expression to be evalutated as being like the pattern
 java.lang.String toString()
          Return this filter as a string.
 
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
 

Constructor Detail

LikeFilterImpl

protected LikeFilterImpl()
Constructor which flags the operator as like.

Method Detail

convertToSQL92

public static java.lang.String convertToSQL92(char escape,
                                              char multi,
                                              char single,
                                              java.lang.String pattern)
                                       throws java.lang.IllegalArgumentException
Given OGC PropertyIsLike Filter information, construct an SQL-compatible 'like' pattern. SQL % --> match any number of characters _ --> match a single character NOTE; the SQL command is 'string LIKE pattern [ESCAPE escape-character]' We could re-define the escape character, but I'm not doing to do that in this code since some databases will not handle this case. Method: 1. Examples: ( escape ='!', multi='*', single='.' ) broadway* -> 'broadway%' broad_ay -> 'broad_ay' broadway -> 'broadway' broadway!* -> 'broadway*' (* has no significance and is escaped) can't -> 'can''t' ( ' escaped for SQL compliance) NOTE: we also handle "'" characters as special because they are end-of-string characters. SQL will convert ' to '' (double single quote). NOTE: we dont handle "'" as a 'special' character because it would be too confusing to have a special char as another special char. Using this will throw an error (IllegalArgumentException).

Parameters:
escape -
multi -
single -
pattern -
Returns:
Throws:
java.lang.IllegalArgumentException

getSQL92LikePattern

public java.lang.String getSQL92LikePattern()
                                     throws java.lang.IllegalArgumentException
see convertToSQL92

Returns:
Throws:
java.lang.IllegalArgumentException

setValue

public void setValue(Expression attribute)
              throws IllegalFilterException
Sets the expression to be evalutated as being like the pattern

Specified by:
setValue in interface LikeFilter
Parameters:
attribute - The value of the attribute for comparison.
Throws:
IllegalFilterException - Filter is illegal.

getValue

public Expression getValue()
Gets the Value (left hand side) of this filter.

Specified by:
getValue in interface LikeFilter
Returns:
The expression that is the value of the filter.

setPattern

public void setPattern(Expression p,
                       java.lang.String wildcardMulti,
                       java.lang.String wildcardSingle,
                       java.lang.String escape)
Sets the match pattern for this FilterLike.

Specified by:
setPattern in interface LikeFilter
Parameters:
p - the expression which evaluates to the match pattern for this filter
wildcardMulti - the string that represents a mulitple character (1->n) wildcard
wildcardSingle - the string that represents a single character (1) wildcard
escape - the string that represents an escape character

setPattern

public void setPattern(java.lang.String pattern,
                       java.lang.String wildcardMulti,
                       java.lang.String wildcardSingle,
                       java.lang.String escape)
Sets the match pattern for this FilterLike.

Specified by:
setPattern in interface LikeFilter
Parameters:
pattern - the string which contains the match pattern for this filter
wildcardMulti - the string that represents a mulitple character (1->n) wildcard
wildcardSingle - the string that represents a single character (1) wildcard
escape - the string that represents an escape character

getPattern

public java.lang.String getPattern()
Accessor method to retrieve the pattern.

Specified by:
getPattern in interface LikeFilter
Returns:
the pattern being matched.

contains

public boolean contains(Feature feature)
Determines whether or not a given feature matches this pattern.

Specified by:
contains in interface LikeFilter
Specified by:
contains in class AbstractFilter
Parameters:
feature - Specified feature to examine.
Returns:
Flag confirming whether or not this feature is inside the filter.
Task:
REVISIT: could the pattern be null such that a null = null?

toString

public java.lang.String toString()
Return this filter as a string.

Returns:
String representation of this like filter.

getEscape

public java.lang.String getEscape()
Getter for property escape.

Specified by:
getEscape in interface LikeFilter
Returns:
Value of property escape.

getWildcardMulti

public java.lang.String getWildcardMulti()
Getter for property wildcardMulti.

Specified by:
getWildcardMulti in interface LikeFilter
Returns:
Value of property wildcardMulti.

getWildcardSingle

public java.lang.String getWildcardSingle()
Getter for property wildcardSingle.

Specified by:
getWildcardSingle in interface LikeFilter
Returns:
Value of property wildcardSingle.

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, the value, and the pattern are the same. &

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

hashCode

public int hashCode()
Override of hashCode method.

Returns:
the hash code for this like filter implementation.

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.