Package com.helger.commons.regex
Class RegExCache
- java.lang.Object
-
- com.helger.commons.cache.MappedCache<KEYTYPE,KEYTYPE,VALUETYPE>
-
- com.helger.commons.cache.Cache<RegExPattern,Pattern>
-
- com.helger.commons.regex.RegExCache
-
- All Implemented Interfaces:
ICache<RegExPattern,Pattern>,IMutableCache<RegExPattern,Pattern>,IHasSize,IHasName
@ThreadSafe @Singleton public final class RegExCache extends Cache<RegExPattern,Pattern>
This class provides a cached for compiled regular expressions. It caches up to a limited number of compiledPatternobjects.- Author:
- Philip Helger
-
-
Field Summary
Fields Modifier and Type Field Description static intMAX_CACHE_SIZEThe default number of items to keep in the cache-
Fields inherited from class com.helger.commons.cache.Cache
DEFAULT_ALLOW_NULL_VALUES
-
Fields inherited from class com.helger.commons.cache.MappedCache
m_aRWLock, NO_MAX_SIZE, STATISTICS_PREFIX
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static RegExCachegetInstance()static PatterngetPattern(String sRegEx)Get the cached regular expression pattern.static PatterngetPattern(String sRegEx, int nOptions)Get the cached regular expression pattern.static booleanisInstantiated()-
Methods inherited from class com.helger.commons.cache.MappedCache
clearCache, createCache, getCacheKeyProvider, getFromCache, getFromCacheNoStats, getFromCacheNoStatsNotLocked, getMaxSize, getName, getValueProvider, hasMaxSize, isAllowNullValues, isEmpty, isInCache, isNotEmpty, putInCache, putInCacheNotLocked, removeFromCache, size, toString
-
-
-
-
Field Detail
-
MAX_CACHE_SIZE
public static final int MAX_CACHE_SIZE
The default number of items to keep in the cache- See Also:
- Constant Field Values
-
-
Method Detail
-
isInstantiated
public static boolean isInstantiated()
-
getInstance
@Nonnull public static RegExCache getInstance()
-
getPattern
@Nonnull public static Pattern getPattern(@Nonnull @Nonempty @RegEx String sRegEx)
Get the cached regular expression pattern.- Parameters:
sRegEx- The regular expression to retrieve. May neither benullnor empty.- Returns:
- The compiled regular expression pattern and never
null. - Throws:
IllegalArgumentException- If the passed regular expression has an illegal syntax
-
getPattern
@Nonnull public static Pattern getPattern(@Nonnull @Nonempty @RegEx String sRegEx, @Nonnegative int nOptions)
Get the cached regular expression pattern.- Parameters:
sRegEx- The regular expression to retrieve. May neither benullnor empty.nOptions- The options used for Pattern.compile- Returns:
- The compiled regular expression pattern and never
null. - Throws:
IllegalArgumentException- If the passed regular expression has an illegal syntax- See Also:
Pattern.compile(String, int)
-
-