org.geotools.filter
Class LikeFilterImpl

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

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 18021 2006-02-14 20:36:18Z jdeolive $
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
 java.lang.Object accept(org.opengis.filter.FilterVisitor visitor, java.lang.Object extraData)
          Used by FilterVisitors to perform some action on this filter instance.
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.
 boolean evaluate(Feature feature)
          Determines whether or not a given feature matches this pattern.
 java.lang.String getEscape()
          Getter for property escape.
 org.opengis.filter.expression.Expression getExpression()
          Gets the expression for hte filter.
 java.lang.String getLiteral()
          Returns the pattern.
 java.lang.String getPattern()
          Deprecated. use getLiteral()
 java.lang.String getSingleChar()
           THis method calls getWildcardSingle()() for subclass backwards compatability.
 java.lang.String getSQL92LikePattern()
          see convertToSQL92
 Expression getValue()
          Deprecated. use getExpression().
 java.lang.String getWildCard()
           THis method calls getWildcardMulti() for subclass backwards compatability.
 java.lang.String getWildcardMulti()
          Deprecated. use getWildCard().
 java.lang.String getWildcardSingle()
          Deprecated. use getSingleChar()
 int hashCode()
          Override of hashCode method.
 void setEscape(java.lang.String escape)
           
 void setExpression(org.opengis.filter.expression.Expression e)
           
 void setLiteral(java.lang.String literal)
          Sets the pattern.
 void setPattern(Expression p, java.lang.String wildcardMulti, java.lang.String wildcardSingle, java.lang.String escape)
          Deprecated. use one of PropertyIsLike.setExpression(Expression) PropertyIsLike#setWildCard(String) {@link PropertyIsLike#setSingleChar(String)} {@link PropertyIsLike#setEscape(String)}
 void setPattern(java.lang.String pattern, java.lang.String wildcardMulti, java.lang.String wildcardSingle, java.lang.String escape)
          Deprecated. use one of PropertyIsLike.setLiteral(String) PropertyIsLike#setWildCard(String) {@link PropertyIsLike#setSingleChar(String)} {@link PropertyIsLike#setEscape(String)}
 void setSingleChar(java.lang.String singleChar)
           
 void setValue(Expression attribute)
          Sets the expression to be evalutated as being like the pattern
 void setWildCard(java.lang.String wildCard)
           
 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
accept, contains, evaluate, getFilterType, isCompareFilter, isGeometryDistanceFilter, isGeometryFilter, isLogicFilter, isMathFilter, isSimpleFilter
 
Methods inherited from class org.geotools.filter.FilterAbstract
accepts, comparable, eval, eval
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.geotools.filter.LikeFilter
contains
 
Methods inherited from interface org.geotools.filter.Filter
accept, and, getFilterType, not, or
 
Methods inherited from interface org.opengis.filter.Filter
evaluate
 

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

setWildCard

public void setWildCard(java.lang.String wildCard)
Specified by:
setWildCard in interface org.opengis.filter.PropertyIsLike

setSingleChar

public void setSingleChar(java.lang.String singleChar)
Specified by:
setSingleChar in interface org.opengis.filter.PropertyIsLike

setEscape

public void setEscape(java.lang.String escape)
Specified by:
setEscape in interface org.opengis.filter.PropertyIsLike

setValue

public final 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 final Expression getValue()
Deprecated. use getExpression().

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.

getExpression

public org.opengis.filter.expression.Expression getExpression()
Gets the expression for hte filter.

This method calls th deprecated getValue() for backwards compatability with subclasses.

Specified by:
getExpression in interface org.opengis.filter.PropertyIsLike

setExpression

public void setExpression(org.opengis.filter.expression.Expression e)
Specified by:
setExpression in interface org.opengis.filter.PropertyIsLike

setPattern

public final void setPattern(Expression p,
                             java.lang.String wildcardMulti,
                             java.lang.String wildcardSingle,
                             java.lang.String escape)
Deprecated. use one of PropertyIsLike.setExpression(Expression) PropertyIsLike#setWildCard(String) {@link PropertyIsLike#setSingleChar(String)} {@link PropertyIsLike#setEscape(String)}

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 final void setPattern(java.lang.String pattern,
                             java.lang.String wildcardMulti,
                             java.lang.String wildcardSingle,
                             java.lang.String escape)
Deprecated. use one of PropertyIsLike.setLiteral(String) PropertyIsLike#setWildCard(String) {@link PropertyIsLike#setSingleChar(String)} {@link PropertyIsLike#setEscape(String)}

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 final java.lang.String getPattern()
Deprecated. use getLiteral()

Accessor method to retrieve the pattern.

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

getLiteral

public java.lang.String getLiteral()
Returns the pattern.

Specified by:
getLiteral in interface org.opengis.filter.PropertyIsLike

setLiteral

public void setLiteral(java.lang.String literal)
Sets the pattern.

Specified by:
setLiteral in interface org.opengis.filter.PropertyIsLike

evaluate

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

Specified by:
evaluate in interface Filter
Overrides:
evaluate in class FilterAbstract
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 final java.lang.String getWildcardMulti()
Deprecated. use getWildCard().

Getter for property wildcardMulti.

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

getWildCard

public java.lang.String getWildCard()

THis method calls getWildcardMulti() for subclass backwards compatability.

Specified by:
getWildCard in interface org.opengis.filter.PropertyIsLike
See Also:
PropertyIsLike.getWildCard().

getWildcardSingle

public final java.lang.String getWildcardSingle()
Deprecated. use getSingleChar()

Getter for property wildcardSingle.

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

getSingleChar

public java.lang.String getSingleChar()

THis method calls getWildcardSingle()() for subclass backwards compatability.

Specified by:
getSingleChar in interface org.opengis.filter.PropertyIsLike
See Also:
PropertyIsLike.getSingleChar()().

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 java.lang.Object accept(org.opengis.filter.FilterVisitor visitor,
                               java.lang.Object extraData)
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 org.opengis.filter.Filter
Overrides:
accept in class FilterAbstract
Parameters:
visitor - The visitor which requires access to this filter, the method must call visitor.visit(this);


Copyright © GeoTools. All Rights Reserved.