SilverStream
Application Server 3.5

com.sssw.rt.expr
Class AgLike

java.lang.Object
 |
 +--com.sssw.rt.expr.AgLike

public class AgLike
extends Object

Used to perform String matching using the specifications of SQL 92. The AgLike class supports the use of '%' and '_ 'as wildcards, where % matches zero or more characters and _ matches exactly one character.


Constructor Summary
AgLike()
           
 
Method Summary
static boolean evaluate(String test, String pat)
          Tests a String to see if it matches a specified pattern.
static boolean evaluate(String test, String pat, char escape)
          Tests a String to see if it matches a specified pattern.
static boolean evaluateUsingPrepare(String test, String pattern)
          Tests a String using a prepared pattern as an optimization.
static String prepare(String pat, char escape)
          Takes a String pattern and builds another String that optimizes the test.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AgLike

public AgLike()
Method Detail

evaluate

public static boolean evaluate(String test,
                               String pat,
                               char escape)
Tests a String to see if it matches a specified pattern. Use this method to prepare the pattern and perform the comparison in a single statement.
Parameters:
test - the String to be used to test against a pattern
pat - the String for the pattern
escape - specifies an escape character to use to match against % or _. Otherwise, specify AgLike.NO_ESCAPE.
Usage:

Returns true if the String matches the pattern. Otherwise it returns false. Note that this methos is overloaded. Used this version to treat % and _ as literals in the comparison.

Example:
 if (AgLike.evaluate("100%", "100+%", '+')) ...
 

evaluate

public static boolean evaluate(String test,
                               String pat)
Tests a String to see if it matches a specified pattern. Use this method to prepare the pattern and perform the comparison in a single statement. Returns true if the String matches the pattern. Otherwise it returns false.
Parameters:
test - specifies the String to be used to test against a pattern.
pat - specifies the String for the pattern.
Usage:

Note that this method is overloaded. Use this version if % and _ are always treated as wildcards.

Example:
      if (AgLike.evaluate("Boston", "Bos%") ...
 

evaluateUsingPrepare

public static boolean evaluateUsingPrepare(String test,
                                           String pattern)
Tests a String using a prepared pattern as an optimization. Use this method to reuse the same pattern for multiple tests. Returns true if the String matches the prepared pattern. Otherwise it returns false.
Parameters:
test - specifies the String to test against a pattern.
pattern - specifies a prepared pattern generated using AgLike.prepare().
Example:
      String pat = AgLike.prepare("Bos%", AgLike.NO_ESCAPE);
      for (int i=0; i < 10; i++)
      {
         if (AgLike.evaluateUsingPrepare(array[i], pat)) ...
      }
 
See Also:
AgLike.prepare( String pat, char escape )

prepare

public static String prepare(String pat,
                             char escape)
Takes a String pattern and builds another String that optimizes the test. Returns a String object that contains a prepared pattern.
Parameters:
pat - specifies the String for the pattern.
escape - specifies an escape character to use when matching against % or _ literally in the comparison. Otherwise, specify AgLike.NO_ESCAPE.
Example:
      String pat = AgLike.prepare("Bos%", AgLike.NO_ESCAPE); ...
 
See Also:
AgLike.evaluateUsingPrepare( String test, String pattern)

SilverStream
Application Server 3.5