kandi background
Explore Kits

QLExpress | dynamic language for the Java platform aimed

 by   alibaba Java Version: v3.3.0 License: Apache-2.0

 by   alibaba Java Version: v3.3.0 License: Apache-2.0

Download this library from

kandi X-RAY | QLExpress Summary

QLExpress is a Java library typically used in Framework applications. QLExpress has no bugs, it has no vulnerabilities, it has build file available, it has a Permissive License and it has medium support. You can download it from GitHub, Maven.
QLExpress is a powerful, lightweight, dynamic language for the Java platform aimed at improving developers’ productivity in different business scenes.
Support
Support
Quality
Quality
Security
Security
License
License
Reuse
Reuse

kandi-support Support

  • QLExpress has a medium active ecosystem.
  • It has 3260 star(s) with 904 fork(s). There are 217 watchers for this library.
  • There were 1 major release(s) in the last 6 months.
  • There are 33 open issues and 124 have been closed. On average issues are closed in 287 days. There are 11 open pull requests and 0 closed requests.
  • It has a neutral sentiment in the developer community.
  • The latest version of QLExpress is v3.3.0
QLExpress Support
Best in #Java
Average in #Java
QLExpress Support
Best in #Java
Average in #Java

quality kandi Quality

  • QLExpress has 0 bugs and 0 code smells.
QLExpress Quality
Best in #Java
Average in #Java
QLExpress Quality
Best in #Java
Average in #Java

securitySecurity

  • QLExpress has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
  • QLExpress code analysis shows 0 unresolved vulnerabilities.
  • There are 0 security hotspots that need review.
QLExpress Security
Best in #Java
Average in #Java
QLExpress Security
Best in #Java
Average in #Java

license License

  • QLExpress is licensed under the Apache-2.0 License. This license is Permissive.
  • Permissive licenses have the least restrictions, and you can use them in most projects.
QLExpress License
Best in #Java
Average in #Java
QLExpress License
Best in #Java
Average in #Java

buildReuse

  • QLExpress releases are available to install and integrate.
  • Deployable package is available in Maven.
  • Build file is available. You can build the component from source.
  • Installation instructions are not available. Examples and code snippets are available.
QLExpress Reuse
Best in #Java
Average in #Java
QLExpress Reuse
Best in #Java
Average in #Java
Top functions reviewed by kandi - BETA

kandi has reviewed QLExpress and discovered the below as its top functions. This is intended to give you an instant insight into QLExpress implemented functionality, and help decide if they suit your requirements.

  • Find match and add root .
  • Transfer word to expression
  • Splits child node .
  • Split the given string into words .
  • check if target class is assignable
  • Compare two numbers .
  • Calculate the condition .
  • Get class .
  • translate parameters from arraySwap
  • expect an environment variable

QLExpress Key Features

QLExpress is a powerful, lightweight, dynamic language for the Java platform aimed at improving developers’ productivity in different business scenes.

二、依赖和调用说明

copy iconCopydownload iconDownload
<dependency>
  <groupId>com.alibaba</groupId>
  <artifactId>QLExpress</artifactId>
  <version>3.2.0</version>
</dependency>

普通java语法

copy iconCopydownload iconDownload
//支持 +,-,*,/,<,>,<=,>=,==,!=,<>【等同于!=】,%,mod【取模等同于%】,++,--,
//in【类似sql】,like【sql语法】,&&,||,!,等操作符
//支持for,break、continue、if then else 等标准的程序控制逻辑
n = 10;
sum = 0;
for(i = 0; i < n; i++) {
   sum = sum + i;
}
return sum;

//逻辑三元操作
a = 1;
b = 2;
maxnum = a > b ? a : b;

和java语法相比,要避免的一些ql写法错误

copy iconCopydownload iconDownload
//java语法:使用泛型来提醒开发者检查类型
keys = new ArrayList<String>();
deviceName2Value = new HashMap<String, String>(7);
String[] deviceNames = {"ng", "si", "umid", "ut", "mac", "imsi", "imei"};
int[] mins = {5, 30};

//ql写法:
keys = new ArrayList();
deviceName2Value = new HashMap();
deviceNames = ["ng", "si", "umid", "ut", "mac", "imsi", "imei"];
mins = [5, 30];

//java语法:对象类型声明
FocFulfillDecisionReqDTO reqDTO = param.getReqDTO();
//ql写法:
reqDTO = param.getReqDTO();

//java语法:数组遍历
for(Item item : list) {
}
//ql写法:
for(i = 0; i < list.size(); i++){
    item = list.get(i);
}

//java语法:map遍历
for(String key : map.keySet()) {
    System.out.println(map.get(key));
}
//ql写法:
keySet = map.keySet();
objArr = keySet.toArray();
for (i = 0; i < objArr.length; i++) {
    key = objArr[i];
    System.out.println(map.get(key));
}

java的对象操作

copy iconCopydownload iconDownload
import com.ql.util.express.test.OrderQuery;
//系统自动会import java.lang.*,import java.util.*;

query = new OrderQuery();           // 创建class实例,自动补全类路径
query.setCreateDate(new Date());    // 设置属性
query.buyer = "张三";                // 调用属性,默认会转化为setBuyer("张三")
result = bizOrderDAO.query(query);  // 调用bean对象的方法
System.out.println(result.getId()); // 调用静态方法

2、脚本中定义function

copy iconCopydownload iconDownload
function add(int a, int b){
    return a + b;
};

function sub(int a, int b){
    return a - b;
};

a = 10;
return add(a, 4) + sub(a, 9);

替换 if then else 等关键字

copy iconCopydownload iconDownload
runner.addOperatorWithAlias("如果", "if", null);
runner.addOperatorWithAlias("则", "then", null);
runner.addOperatorWithAlias("否则", "else", null);

express = "如果 (语文 + 数学 + 英语 > 270) 则 {return 1;} 否则 {return 0;}";
DefaultContext<String, Object> context = new DefaultContext<String, Object>();
runner.execute(express, context, null, false, false, null);

如何自定义Operator

copy iconCopydownload iconDownload
import java.util.ArrayList;
import java.util.List;

/**
 * 定义一个继承自com.ql.util.express.Operator的操作符
 */
public class JoinOperator extends Operator {
    public Object executeInner(Object[] list) throws Exception {
        Object opdata1 = list[0];
        Object opdata2 = list[1];
        if (opdata1 instanceof List) {
            ((List)opdata1).add(opdata2);
            return opdata1;
        } else {
            List result = new ArrayList();
            for (Object opdata : list) {
                result.add(opdata);
            }
            return result;
        }
    }
}

如何使用Operator

copy iconCopydownload iconDownload
//(1)addOperator
ExpressRunner runner = new ExpressRunner();
DefaultContext<String, Object> context = new DefaultContext<String, Object>();
runner.addOperator("join", new JoinOperator());
Object r = runner.execute("1 join 2 join 3", context, null, false, false);
System.out.println(r); // 返回结果 [1, 2, 3]

//(2)replaceOperator
ExpressRunner runner = new ExpressRunner();
DefaultContext<String, Object> context = new DefaultContext<String, Object>();
runner.replaceOperator("+", new JoinOperator());
Object r = runner.execute("1 + 2 + 3", context, null, false, false);
System.out.println(r); // 返回结果 [1, 2, 3]

//(3)addFunction
ExpressRunner runner = new ExpressRunner();
DefaultContext<String, Object> context = new DefaultContext<String, Object>();
runner.addFunction("join", new JoinOperator());
Object r = runner.execute("join(1, 2, 3)", context, null, false, false);
System.out.println(r); // 返回结果 [1, 2, 3]

4、绑定java类或者对象的method

copy iconCopydownload iconDownload
public class BeanExample {
    public static String upper(String abc) {
        return abc.toUpperCase();
    }
    public boolean anyContains(String str, String searchStr) {
        char[] s = str.toCharArray();
        for (char c : s) {
            if (searchStr.contains(c+"")) {
                return true;
            }
        }
        return false;
    }
}

runner.addFunctionOfClassMethod("取绝对值", Math.class.getName(), "abs", new String[] {"double"}, null);
runner.addFunctionOfClassMethod("转换为大写", BeanExample.class.getName(), "upper", new String[] {"String"}, null);

runner.addFunctionOfServiceMethod("打印", System.out, "println", new String[] { "String" }, null);
runner.addFunctionOfServiceMethod("contains", new BeanExample(), "anyContains", new Class[] {String.class, String.class}, null);

String express = "取绝对值(-100); 转换为大写(\"hello world\"); 打印(\"你好吗?\"); contains("helloworld",\"aeiou\")";
runner.execute(express, context, null, false, false);

5、macro 宏定义

copy iconCopydownload iconDownload
runner.addMacro("计算平均成绩", "(语文+数学+英语)/3.0");
runner.addMacro("是否优秀", "计算平均成绩>90");
IExpressContext<String, Object> context = new DefaultContext<String, Object>();
context.put("语文", 88);
context.put("数学", 99);
context.put("英语", 95);
Object result = runner.execute("是否优秀", context, null, false, false);
System.out.println(r);
//返回结果true

6、编译脚本,查询外部需要定义的变量和函数。

copy iconCopydownload iconDownload
String express = "int 平均分 = (语文 + 数学 + 英语 + 综合考试.科目2) / 4.0; return 平均分";
ExpressRunner runner = new ExpressRunner(true, true);
String[] names = runner.getOutVarNames(express);
for(String s:names){
    System.out.println("var : " + s);
}

//输出结果:
var : 数学
var : 综合考试
var : 英语
var : 语文

7、关于不定参数的使用

copy iconCopydownload iconDownload
@Test
public void testMethodReplace() throws Exception {
    ExpressRunner runner = new ExpressRunner();
    IExpressContext<String, Object> expressContext = new DefaultContext<String, Object>();
    runner.addFunctionOfServiceMethod("getTemplate", this, "getTemplate", new Class[]{Object[].class}, null);

    //(1)默认的不定参数可以使用数组来代替
    Object r = runner.execute("getTemplate([11,'22', 33L, true])", expressContext, null, false, false);
    System.out.println(r);
    //(2)像java一样,支持函数动态参数调用,需要打开以下全局开关,否则以下调用会失败
    DynamicParamsUtil.supportDynamicParams = true;
    r = runner.execute("getTemplate(11, '22', 33L, true)", expressContext, null, false, false);
    System.out.println(r);
}

//等价于getTemplate(Object[] params)
public Object getTemplate(Object... params) throws Exception{
    String result = "";
    for(Object obj:params){
        result = result + obj + ",";
    }
    return result;
}

8、关于集合的快捷写法

copy iconCopydownload iconDownload
@Test
public void testSet() throws Exception {
    ExpressRunner runner = new ExpressRunner(false, false);
    DefaultContext<String, Object> context = new DefaultContext<String, Object>();
    String express = "abc = NewMap(1:1, 2:2); return abc.get(1) + abc.get(2);";
    Object r = runner.execute(express, context, null, false, false);
    System.out.println(r);
    express = "abc = NewList(1, 2, 3); return abc.get(1) + abc.get(2)";
    r = runner.execute(express, context, null, false, false);
    System.out.println(r);
    express = "abc = [1, 2, 3]; return abc[1] + abc[2];";
    r = runner.execute(express, context, null, false, false);
    System.out.println(r);
}

9、集合的遍历

copy iconCopydownload iconDownload
//遍历map
map = new HashMap();
map.put("a", "a_value");
map.put("b", "b_value");
keySet = map.keySet();
objArr = keySet.toArray();
for (i = 0; i < objArr.length; i++) {
    key = objArr[i];
    System.out.println(map.get(key));
}

isPrecise

copy iconCopydownload iconDownload
/**
 * 是否需要高精度计算
 */
private boolean isPrecise = false;

isShortCircuit

copy iconCopydownload iconDownload
/**
 * 是否使用逻辑短路特性
 */
private boolean isShortCircuit = true;

isTrace

copy iconCopydownload iconDownload
/**
 * 是否输出所有的跟踪信息,同时还需要log级别是DEBUG级别
 */
private boolean isTrace = false;

2、调用入参

copy iconCopydownload iconDownload
/**
 * 执行一段文本
 * @param expressString 程序文本
 * @param context 执行上下文,可以扩展为包含ApplicationContext
 * @param errorList 输出的错误信息List
 * @param isCache 是否使用Cache中的指令集,建议为true
 * @param isTrace 是否输出详细的执行指令信息,建议为false
 * @param aLog 输出的log
 * @return
 * @throws Exception
 */
Object execute(String expressString, IExpressContext<String, Object> context, List<String> errorList, boolean isCache, boolean isTrace, Log aLog);

3、功能扩展API列表

copy iconCopydownload iconDownload
public abstract Object executeInner(Object[] list) throws Exception;

(1)function相关API

copy iconCopydownload iconDownload
//通过name获取function的定义
OperatorBase getFunciton(String name);

//通过自定义的Operator来实现类似:fun(a, b, c)
void addFunction(String name, OperatorBase op);

//fun(a, b, c) 绑定 object.function(a, b, c)对象方法
void addFunctionOfServiceMethod(String name, Object aServiceObject, String aFunctionName, Class<?>[] aParameterClassTypes, String errorInfo);

//fun(a, b, c) 绑定 Class.function(a, b, c)类方法
void addFunctionOfClassMethod(String name, String aClassName, String aFunctionName, Class<?>[] aParameterClassTypes, String errorInfo);

//给Class增加或者替换method,同时支持 a.fun(b), fun(a, b) 两种方法调用
//比如扩展String.class的isBlank方法:"abc".isBlank()和isBlank("abc")都可以调用
void addFunctionAndClassMethod(String name, Class<?> bindingClass, OperatorBase op);

(2)Operator相关API

copy iconCopydownload iconDownload
//添加操作符号,可以设置优先级
void addOperator(String name, Operator op);
void addOperator(String name, String aRefOpername, Operator op);

//替换操作符处理
OperatorBase replaceOperator(String name, OperatorBase op);

//添加操作符和关键字的别名,比如 if..then..else -> 如果。。那么。。否则。。
void addOperatorWithAlias(String keyWordName, String realKeyWordName, String errorInfo);

(3)宏定义相关API

copy iconCopydownload iconDownload
//比如addMacro("天猫卖家", "userDO.userTag &1024 == 1024")
void addMacro(String macroName, String express);

(4)java class的相关api

copy iconCopydownload iconDownload
//添加类的属性字段
void addClassField(String field, Class<?>bindingClass, Class<?>returnType, Operator op);

//添加类的方法
void addClassMethod(String name, Class<?>bindingClass, OperatorBase op);

(4)语法树解析变量、函数的API

copy iconCopydownload iconDownload
//获取一个表达式需要的外部变量名称列表
String[] getOutVarNames(String express);
String[] getOutFunctionNames(String express);

(5)语法解析校验api

copy iconCopydownload iconDownload
String expressString = "for(i = 0; i < 10; i++) {sum = i + 1;} return sum;";
InstructionSet instructionSet = expressRunner.parseInstructionSet(expressString);
//如果调用过程不出现异常,指令集instructionSet就是可以被加载运行(execute)了!

(6)指令集缓存相关的api

copy iconCopydownload iconDownload
//优先从本地指令集缓存获取指令集,没有的话生成并且缓存在本地
InstructionSet getInstructionSetFromLocalCache(String expressString);
//清除缓存
void clearExpressCache();

(7)安全风险控制

copy iconCopydownload iconDownload
try {
    express = "sum = 0; for(i = 0; i < 1000000000; i++) {sum = sum + i;} return sum;";
    //可通过timeoutMillis参数设置脚本的运行超时时间:1000ms
    Object r = runner.execute(express, context, null, true, false, 1000);
    System.out.println(r);
    throw new Exception("没有捕获到超时异常");
} catch (QLTimeOutException e) {
    System.out.println(e);
}

(8)增强上下文参数Context相关的api

copy iconCopydownload iconDownload
public class QLExpressContext extends HashMap<String, Object> implements IExpressContext<String, Object> {
    private final ApplicationContext context;

    // 构造函数,传入context 和 ApplicationContext
    public QLExpressContext(Map<String, Object> map, ApplicationContext aContext) {
        super(map);
        this.context = aContext;
    }

    /**
     * 抽象方法:根据名称从属性列表中提取属性值
     */
    public Object get(Object name) {
        Object result;
        result = super.get(name);
        try {
            if (result == null && this.context != null && this.context.containsBean((String)name)) {
                // 如果在Spring容器中包含bean,则返回String的Bean
                result = this.context.getBean((String)name);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return result;
    }

    public Object put(String name, Object object) {
        return super.put(name, object);
    }
}

Community Discussions

No Community Discussions are available at this moment for QLExpress.Refer to stack overflow page for discussions.

No Community Discussions are available at this moment for QLExpress.Refer to stack overflow page for discussions.

Community Discussions, Code Snippets contain sources that include Stack Exchange Network

Vulnerabilities

No vulnerabilities reported

Install QLExpress

You can download it from GitHub, Maven.
You can use QLExpress like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the QLExpress component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .

Support

Gitter channel - Online chat room with QLExpress developers. Gitter channelemail:tianqiao@alibaba-inc.com,baoxingjie@126.comwechart:371754252QLExpress blogs: https://yq.aliyun.com/album/130

DOWNLOAD this Library from

Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases

Save this library and start creating your kit

Explore Related Topics

Share this Page

share link
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases

Save this library and start creating your kit

  • © 2022 Open Weaver Inc.