| java.lang.Object org.apache.oro.text.GenericPatternCache
All known Subclasses: org.apache.oro.text.PatternCacheRandom, org.apache.oro.text.PatternCacheFIFO, org.apache.oro.text.PatternCacheLRU, org.apache.oro.text.PatternCacheFIFO2,
GenericPatternCache | abstract public class GenericPatternCache implements PatternCache(Code) | | This is the base class for all cache implementations provided in the
org.apache.oro.text package.
Although 4 subclasses of GenericPatternCache are provided with this
package, users may not derive subclasses from this class.
Rather, users should create their own implmentations of the
PatternCache interface.
version: @version@ since: 1.0 See Also: PatternCache See Also: PatternCacheLRU See Also: PatternCacheFIFO See Also: PatternCacheFIFO2 See Also: PatternCacheRandom |
Method Summary | |
final public synchronized Pattern | addPattern(String expression, int options) Adds a pattern to the cache and returns the compiled pattern. | final public synchronized Pattern | addPattern(String expression) | final public int | capacity() Returns the maximum number of patterns that can be cached at one time. | final public synchronized Pattern | getPattern(String expression, int options) This method fetches a pattern from the cache. | final public synchronized Pattern | getPattern(String expression) | final public int | size() Returns the number of elements in the cache, not to be confused with
the
GenericPatternCache.capacity() which returns the number
of elements that can be held in the cache at one time. |
DEFAULT_CAPACITY | final public static int DEFAULT_CAPACITY(Code) | | The default capacity to be used by the GenericPatternCache subclasses
provided with this package. Its value is 20.
|
GenericPatternCache | GenericPatternCache(Cache cache, PatternCompiler compiler)(Code) | | The primary constructor for GenericPatternCache. It has default
access so it will only be used within the package. It initializes
_cache and _compiler to the arguments provided.
Parameters: cache - The cache with which to store patterns. Parameters: compiler - The PatternCompiler that should be used to compilepatterns. |
addPattern | final public synchronized Pattern addPattern(String expression, int options) throws MalformedPatternException(Code) | | Adds a pattern to the cache and returns the compiled pattern. This
method is in principle almost identical to
GenericPatternCache.getPattern getPattern() except for the fact that
it throws a MalformedPatternException if an expression cannot be
compiled.
addPattern() is meant to be used when you expressly intend to add
an expression to the cache and is useful for front-loading a cache
with expressions before use. If the expression added does not
already exist in the cache, it is compiled, added to the cache,
and returned. If the compiled expression is already in the cache, it
is simply returned.
The expected behavior of this method should be to start replacing
patterns in the cache only after the cache has been filled to capacity.
Parameters: expression - The regular expression to add to the cache. Parameters: options - The compilation options to use when compiling theexpression. The Pattern corresponding to the String representation of theregular expression. exception: MalformedPatternException - If there is an error in compilingthe regular expression. |
capacity | final public int capacity()(Code) | | Returns the maximum number of patterns that can be cached at one time.
The maximum number of patterns that can be cached at one time. |
getPattern | final public synchronized Pattern getPattern(String expression, int options) throws MalformedCachePatternException(Code) | | This method fetches a pattern from the cache. It is nearly identical
to
GenericPatternCache.addPattern addPattern() except that it doesn't
throw a MalformedPatternException. If the pattern is not in the
cache, it is compiled, placed in the cache, and returned. If
the pattern cannot be compiled successfully, it
throws a MalformedCachePatternException.
Note that this exception is derived from RuntimeException, which means
you are NOT forced to catch it by the compiler. Please refer to
MalformedCachePatternException for a discussion of
when you should and shouldn't catch this exception.
Parameters: expression - The regular expression to fetch from the cache incompiled form. Parameters: options - The compilation options to use when compiling theexpression. The Pattern corresponding to the String representation of theregular expression. exception: MalformedCachePatternException - If there is an error incompiling the regular expression. |
size | final public int size()(Code) | | Returns the number of elements in the cache, not to be confused with
the
GenericPatternCache.capacity() which returns the number
of elements that can be held in the cache at one time.
The current size of the cache (i.e., the number of elementscurrently cached). |
|
|