com.ibm.net.ssl.internal.www.protocol.https
Class RegexpPool

java.lang.Object
  |
  +--com.ibm.net.ssl.internal.www.protocol.https.RegexpPool

public class RegexpPool
extends java.lang.Object

A class to represent a pool of regular expressions. A string can be matched against the whole pool all at once. It is much faster than doing individual regular expression matches one-by-one.

Author:
James Gosling
See Also:
java.misc.RegexpTarget

Constructor Summary
RegexpPool()
           
 
Method Summary
 void add(java.lang.String re, java.lang.Object ret)
          Add a regular expression to the pool of regular expressions.
 java.lang.Object delete(java.lang.String re)
          Delete the regular expression and its target.
static void main(java.lang.String[] argv)
           
 java.lang.Object match(java.lang.String s)
          Search for a match to a string & return the object associated with it with the match.
 java.lang.Object matchNext(java.lang.String s)
          Identical to match except that it will only find matches to regular expressions that were added to the pool after the last regular expression that matched in the last call to match() or matchNext()
 void print(java.io.PrintStream out)
          Print this pool to standard output
 void replace(java.lang.String re, java.lang.Object ret)
          Replace the target for the regular expression with a different target.
 void reset()
          Resets the pool so that the next call to matchNext looks at all regular expressions in the pool.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RegexpPool

public RegexpPool()
Method Detail

add

public void add(java.lang.String re,
                java.lang.Object ret)
         throws REException
Add a regular expression to the pool of regular expressions.
Parameters:
re - The regular expression to add to the pool. For now, only handles strings that either begin or end with a '*'.
ret - The object to be returned when this regular expression is matched. If ret is an instance of the RegexpTarget class, ret.found is called with the string fragment that matched the '*' as its parameter.
Throws:
REException - error

replace

public void replace(java.lang.String re,
                    java.lang.Object ret)
Replace the target for the regular expression with a different target.
Parameters:
re - The regular expression to be replaced in the pool. For now, only handles strings that either begin or end with a '*'.
ret - The object to be returned when this regular expression is matched. If ret is an instance of the RegexpTarget class, ret.found is called with the string fragment that matched the '*' as its parameter.

delete

public java.lang.Object delete(java.lang.String re)
Delete the regular expression and its target.
Parameters:
re - The regular expression to be deleted from the pool. must begin or end with a '*'
Returns:
target - the old target.

match

public java.lang.Object match(java.lang.String s)
Search for a match to a string & return the object associated with it with the match. When multiple regular expressions would match the string, the best match is returned first. The next best match is returned the next time matchNext is called.
Parameters:
s - The string to match against the regular expressions in the pool.
Returns:
null on failure, otherwise the object associated with the regular expression when it was added to the pool. If the object is an instance of RegexpTarget, then the return value is the result from calling return.found(string_that_matched_wildcard).

matchNext

public java.lang.Object matchNext(java.lang.String s)
Identical to match except that it will only find matches to regular expressions that were added to the pool after the last regular expression that matched in the last call to match() or matchNext()

reset

public void reset()
Resets the pool so that the next call to matchNext looks at all regular expressions in the pool. match(s); is equivalent to reset(); matchNext(s);

Multithreading note: reset/nextMatch leave state in the regular expression pool. If multiple threads could be using this pool this way, they should be syncronized to avoid race hazards. match() was done in such a way that there are no such race hazards: multiple threads can be matching in the same pool simultaneously.


main

public static void main(java.lang.String[] argv)

print

public void print(java.io.PrintStream out)
Print this pool to standard output