All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.kits.cache.PatternCache Maven / Gradle / Ivy

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;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy