io.github.kits.cache.PatternCache Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of whimthen-kits Show documentation
Show all versions of whimthen-kits Show documentation
Easy to use java tool library.
The newest version!
package io.github.kits.cache;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Pattern;
/**
* 正则缓存
*
* @project: kits
* @created: with IDEA
* @author: kits
* @date: 2018 08 17 下午4:1909 | 八月. 星期五
*/
public class PatternCache {
private static ConcurrentHashMap PATTERN_MAP = new ConcurrentHashMap<>();
public static void put(Pattern pattern) {
PATTERN_MAP.put(pattern.pattern(), pattern);
}
public static Pattern get(String regex) {
Pattern pattern = PATTERN_MAP.get(regex);
if (pattern == null) {
pattern = Pattern.compile(regex);
put(pattern);
}
return pattern;
}
}