Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.apache.oro.text
Class GenericPatternCache  view GenericPatternCache download GenericPatternCache.java

java.lang.Object
  extended byorg.apache.oro.text.GenericPatternCache
All Implemented Interfaces:
PatternCache
Direct Known Subclasses:
PatternCacheFIFO, PatternCacheFIFO2, PatternCacheLRU, PatternCacheRandom

public abstract class GenericPatternCache
extends java.lang.Object
implements PatternCache

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.

Since:
1.0
Version:
@version@

Field Summary
(package private)  org.apache.oro.util.Cache _cache
           
(package private)  org.apache.oro.text.regex.PatternCompiler _compiler
           
static int DEFAULT_CAPACITY
          The default capacity to be used by the GenericPatternCache subclasses provided with this package.
 
Constructor Summary
(package private) GenericPatternCache(org.apache.oro.util.Cache cache, org.apache.oro.text.regex.PatternCompiler compiler)
          The primary constructor for GenericPatternCache.
 
Method Summary
 org.apache.oro.text.regex.Pattern addPattern(java.lang.String expression)
          Same as calling
 org.apache.oro.text.regex.Pattern addPattern(java.lang.String expression, int options)
          Adds a pattern to the cache and returns the compiled pattern.
 int capacity()
          Returns the maximum number of patterns that can be cached at one time.
 org.apache.oro.text.regex.Pattern getPattern(java.lang.String expression)
          Same as calling
 org.apache.oro.text.regex.Pattern getPattern(java.lang.String expression, int options)
          This method fetches a pattern from the cache.
 int size()
          Returns the number of elements in the cache, not to be confused with the capacity() 55 which returns the number of elements that can be held in the cache at one time.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_compiler

org.apache.oro.text.regex.PatternCompiler _compiler

_cache

org.apache.oro.util.Cache _cache

DEFAULT_CAPACITY

public static final int DEFAULT_CAPACITY
The default capacity to be used by the GenericPatternCache subclasses provided with this package. Its value is 20.

See Also:
Constant Field Values
Constructor Detail

GenericPatternCache

GenericPatternCache(org.apache.oro.util.Cache cache,
                    org.apache.oro.text.regex.PatternCompiler compiler)
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.

Method Detail

addPattern

public final org.apache.oro.text.regex.Pattern addPattern(java.lang.String expression,
                                                          int options)
                                                   throws org.apache.oro.text.regex.MalformedPatternException
Adds a pattern to the cache and returns the compiled pattern. This method is in principle almost identical to getPattern() 55 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.

Specified by:
addPattern in interface PatternCache

addPattern

public final org.apache.oro.text.regex.Pattern addPattern(java.lang.String expression)
                                                   throws org.apache.oro.text.regex.MalformedPatternException
Same as calling
 addPattern(expression, 0);
 

Specified by:
addPattern in interface PatternCache

getPattern

public final org.apache.oro.text.regex.Pattern getPattern(java.lang.String expression,
                                                          int options)
                                                   throws MalformedCachePatternException
This method fetches a pattern from the cache. It is nearly identical to addPattern() 55 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.

Specified by:
getPattern in interface PatternCache

getPattern

public final org.apache.oro.text.regex.Pattern getPattern(java.lang.String expression)
                                                   throws MalformedCachePatternException
Same as calling
 getPattern(expression, 0)
 

Specified by:
getPattern in interface PatternCache

size

public final int size()
Returns the number of elements in the cache, not to be confused with the capacity() 55 which returns the number of elements that can be held in the cache at one time.

Specified by:
size in interface PatternCache

capacity

public final int capacity()
Returns the maximum number of patterns that can be cached at one time.

Specified by:
capacity in interface PatternCache