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

cn.hutool.extra.expression.engine.ExpressionFactory Maven / Gradle / Ivy

Go to download

Hutool是一个小而全的Java工具类库,通过静态方法封装,降低相关API的学习成本,提高工作效率,使Java拥有函数式语言般的优雅,让Java语言也可以“甜甜的”。

There is a newer version: 5.8.34
Show newest version
package cn.hutool.extra.expression.engine;

import cn.hutool.core.lang.Singleton;
import cn.hutool.core.util.ServiceLoaderUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.log.StaticLog;

import cn.hutool.extra.expression.ExpressionEngine;
import cn.hutool.extra.expression.ExpressionException;

/**
 * 表达式语言引擎工厂类,用于根据用户引入的表达式jar,自动创建对应的引擎对象
 *
 * @since 5.5.0
 * @author looly
 */
public class ExpressionFactory {

	/**
	 * 获得单例的{@link ExpressionEngine}
	 *
	 * @return 单例的{@link ExpressionEngine}
	 */
	public static ExpressionEngine get(){
		return Singleton.get(ExpressionEngine.class.getName(), ExpressionFactory::create);
	}

	/**
	 * 根据用户引入的表达式引擎jar,自动创建对应的拼音引擎对象
* 推荐创建的引擎单例使用,此方法每次调用会返回新的引擎 * * @return {@link ExpressionEngine} */ public static ExpressionEngine create() { final ExpressionEngine engine = doCreate(); StaticLog.debug("Use [{}] Engine As Default.", StrUtil.removeSuffix(engine.getClass().getSimpleName(), "Engine")); return engine; } /** * 根据用户引入的拼音引擎jar,自动创建对应的拼音引擎对象
* 推荐创建的引擎单例使用,此方法每次调用会返回新的引擎 * * @return {@link ExpressionEngine} */ private static ExpressionEngine doCreate() { final ExpressionEngine engine = ServiceLoaderUtil.loadFirstAvailable(ExpressionEngine.class); if(null != engine){ return engine; } throw new ExpressionException("No expression jar found ! Please add one of it to your project !"); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy