111
This commit is contained in:
1 parent
68a2b4f68c
commit
7cd697187c
308 files changed
+30454
-75
No files matched your search
@@ -0,0 +1,43 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<artifactId>ruoyi</artifactId>
|
||||
<version>3.4.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>luqj-plugin</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>luqj-plugin</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>net.sf.json-lib</groupId>
|
||||
<artifactId>json-lib</artifactId>
|
||||
<version>2.3</version>
|
||||
<classifier>jdk13</classifier>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>2.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>33.0.0-jre</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<artifactId>luqj-common</artifactId>
|
||||
<version>3.4.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,142 @@
|
||||
package org.code.modules.plugins;
|
||||
|
||||
import com.luqj.util.log.LogUtil;
|
||||
import com.luqj.util.reflect.ClassUtils;
|
||||
import com.luqj.util.reflect.GSetterUtil;
|
||||
import org.code.modules.plugins.service.IBeanFactory;
|
||||
import org.code.modules.plugins.service.IPluginRegistry;
|
||||
import org.code.modules.plugins.service.IllegalPluginException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.context.annotation.DependsOn;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.lang.reflect.Field;
|
||||
@DependsOn(value = "defPluginRegistry")
|
||||
@Component(value = "pluginBeanFactory")
|
||||
public class PluginBeanFactory implements IBeanFactory {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(PluginBeanFactory.class);
|
||||
@Autowired
|
||||
private IPluginRegistry pluginRegistry;
|
||||
@Autowired
|
||||
@Qualifier("springBeanFactory")
|
||||
private IBeanFactory springBeanFactory;
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
pluginRegistry.init();
|
||||
}
|
||||
|
||||
public <T> T getBean(String beanName, Class<T> beanClass) {
|
||||
if (beanName.endsWith("Action")) {
|
||||
LOGGER.debug("获取bean: {}", beanName);
|
||||
}
|
||||
return getBean(beanName, "def", beanClass);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public <T> T getBean(String beanName, String version, Class<T> beanClass) {
|
||||
try {
|
||||
T obj = pluginRegistry.instancePluginBean(beanName, version, beanClass);
|
||||
if (obj != null) {
|
||||
injectBean(obj);
|
||||
return obj;
|
||||
} else {
|
||||
if (this.springBeanFactory.containsBean(beanName)) {
|
||||
return this.springBeanFactory.getBean(beanName, beanClass);
|
||||
} else {
|
||||
LOGGER.debug("找不到指定的bean[{}]", beanName);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
|
||||
LOGGER.error(LogUtil.exceptionMsg("bean[" + beanName + ":" + version + "],加载异常", e), e);
|
||||
new IllegalPluginException(LogUtil.exceptionMsg("bean[" + beanName + ":" + version + "],加载异常", e), e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getBean(String beanName) {
|
||||
return getBean(beanName, Object.class);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void injectBean(Object obj, String version) {
|
||||
Class<?> classType = obj.getClass();
|
||||
Field[] fields = ClassUtils.getDeclaredFields(classType);
|
||||
for (Field field : fields) {
|
||||
try {
|
||||
if (this.springBeanFactory.containsBean(field.getName())) {
|
||||
if (GSetterUtil.existSetter(classType, field)) {
|
||||
if (LOGGER.isTraceEnabled()) {
|
||||
LOGGER.trace(classType.getSimpleName() + "." + field.getName() + "spring注入成功!");
|
||||
}
|
||||
GSetterUtil.setValueBySetter(obj, field, this.springBeanFactory.getBean(field.getName()));
|
||||
}
|
||||
} else if (this.pluginRegistry.containsPluginBean(field.getName())
|
||||
&& GSetterUtil.getValueByGetter(obj, field) == null) {//有值不注入
|
||||
Object fBean = this.getBean(field.getName(), Object.class);
|
||||
injectBean(fBean, version);
|
||||
GSetterUtil.setValueBySetter(obj, field, fBean);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
LOGGER.error(classType.getSimpleName() + "." + field.getName() +
|
||||
"注入异常,异常消息[" + e.getMessage() + "]", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void injectBean(Object obj) {
|
||||
Class<?> classType = obj.getClass();
|
||||
Field[] fields = ClassUtils.getDeclaredFields(classType);
|
||||
for (Field field : fields) {
|
||||
try {
|
||||
if (this.springBeanFactory.containsBean(field.getName())) {
|
||||
if (GSetterUtil.existSetter(classType, field)) {
|
||||
if (LOGGER.isTraceEnabled()) {
|
||||
LOGGER.trace(classType.getSimpleName() + "." + field.getName() + "spring注入成功!");
|
||||
}
|
||||
GSetterUtil.setValueBySetter(obj, field, this.springBeanFactory.getBean(field.getName()));
|
||||
}
|
||||
} else if (this.pluginRegistry.containsPluginBean(field.getName())
|
||||
&& GSetterUtil.getValueByGetter(obj, field) == null) {//有值不注入
|
||||
Object fBean = this.getBean(field.getName());
|
||||
injectBean(fBean);
|
||||
GSetterUtil.setValueBySetter(obj, field, fBean);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
LOGGER.error(classType.getSimpleName() + "." + field.getName() +
|
||||
"注入异常,异常消息[" + e.getMessage() + "]", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean containsBean(String beanName) {
|
||||
return pluginRegistry.containsPluginBean(beanName)
|
||||
|| springBeanFactory.containsBean(beanName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void autowireComponent(Object bean) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public IPluginRegistry getPluginRegistry() {
|
||||
return pluginRegistry;
|
||||
}
|
||||
|
||||
public void setPluginRegistry(IPluginRegistry pluginRegistry) {
|
||||
this.pluginRegistry = pluginRegistry;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package org.code.modules.plugins;;
|
||||
|
||||
import com.luqj.util.assertion.Assert;
|
||||
import org.code.modules.plugins.service.IBeanFactory;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component(value = "springBeanFactory")
|
||||
public class SpringBeanFactory implements ApplicationContextAware, IBeanFactory {
|
||||
private static ApplicationContext applicationContext;
|
||||
|
||||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||
if (SpringBeanFactory.applicationContext == null) {
|
||||
SpringBeanFactory.applicationContext = applicationContext;
|
||||
}
|
||||
System.out.println("========ApplicationContext配置成功========");
|
||||
System.out.println("========在普通类可以通过调用SpringUtils.getAppContext()获取applicationContext对象========");
|
||||
System.out.println("========applicationContext=" + SpringBeanFactory.applicationContext + "========");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取applicationContext
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static ApplicationContext getApplicationContext() {
|
||||
return applicationContext;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean containsBean(String beanName) {
|
||||
return this.applicationContext.containsBean(beanName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T getBean(String beanName, Class<T> beanClass) {
|
||||
return applicationContext.getBean(beanName, beanClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getBean(String beanName) {
|
||||
return applicationContext.getBean(beanName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectBean(Object obj) {
|
||||
Assert.fail("此类禁用此方法");
|
||||
}
|
||||
|
||||
public void injectBean(Object obj, String version) {
|
||||
Assert.fail("此类禁用此方法");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void autowireComponent(Object bean) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T getBean(String beanName, String version, Class<T> beanClass) {
|
||||
// TODO Auto-generated method stub
|
||||
return getBean(beanName, beanClass);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package org.code.modules.plugins.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.TYPE)
|
||||
public @interface DBTypeMapping {
|
||||
|
||||
String name();
|
||||
|
||||
String dbType();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package org.code.modules.plugins.annotation;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
@Target({ElementType.TYPE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Component
|
||||
public @interface EtlApiDubboService {
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package org.code.modules.plugins.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface EtlApiSave {
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package org.code.modules.plugins.annotation;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
@Target({ElementType.TYPE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Component
|
||||
public @interface EtlApiService {
|
||||
String pluginCode();
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package org.code.modules.plugins.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Created by chenzm on 2016/12/27.
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.FIELD)
|
||||
public @interface PluginAttribute {
|
||||
String code() default "";
|
||||
String name();
|
||||
String type() default "";
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package org.code.modules.plugins.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* 实现数据备份所需的插件
|
||||
* @author xufm
|
||||
* @date 2018/4/2
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.TYPE)
|
||||
public @interface PluginBackup {
|
||||
/**
|
||||
* 别名
|
||||
* @return
|
||||
*/
|
||||
String name() default "";
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
package org.code.modules.plugins.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.TYPE)
|
||||
public @interface PluginBean {
|
||||
/**
|
||||
* 插件名称
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
String name() default "";
|
||||
|
||||
/**
|
||||
* 别名
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
String aliasName() default "";
|
||||
|
||||
/**
|
||||
* 插件类
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
PluginEnum clazz() default PluginEnum.DEFAULT;
|
||||
|
||||
/**
|
||||
* 插件所属分类
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
String pluginClassify() default "";
|
||||
|
||||
/**
|
||||
* 插件类型
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
PluginType beanType();
|
||||
|
||||
/**
|
||||
* 分区模式
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
String partitionPattern() default "";
|
||||
|
||||
/**
|
||||
* 线程模式
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
String workThreadPattern() default "";
|
||||
|
||||
/**
|
||||
* 分区
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
PluginPartition[] partitions() default {};
|
||||
|
||||
/**
|
||||
* 执行模式
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
EnumExecuteMod executeMod() default EnumExecuteMod.NOTHING;
|
||||
|
||||
|
||||
enum EnumExecuteMod {
|
||||
/**
|
||||
* 表示不显示
|
||||
*/
|
||||
NOTHING(""),
|
||||
/**
|
||||
* ETL显示
|
||||
*/
|
||||
ETL("1"),
|
||||
/**
|
||||
* 魔方显示
|
||||
*/
|
||||
MF("2"),
|
||||
/**
|
||||
* 所有都显示
|
||||
*/
|
||||
ALL("3");
|
||||
|
||||
private String code;
|
||||
|
||||
EnumExecuteMod(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package org.code.modules.plugins.annotation;
|
||||
|
||||
/**
|
||||
* 插件类型
|
||||
* Created by chenzm on 2017/1/12.
|
||||
*/
|
||||
public enum PluginEnum {
|
||||
INPUT_PLUGIN("输入插件", "org.code.modules.plugin.common.InputTransPlugin"),
|
||||
|
||||
OUTPUT_PLUGIN("输出插件", "org.code.modules.plugin.common.OutputTransPlugin"),
|
||||
|
||||
TRANSFORM_PLUGIN("转换插件", "org.code.modules.plugin.common.TransformPlugin"),
|
||||
|
||||
BATCH_TRANSFORM_PLUGIN("批量转换插件", "org.code.modules.plugin.common.BatchTransformPlugin"),
|
||||
|
||||
SAVEPOINT_PLUGIN("增量输出插件", "org.code.modules.plugin.common.SavePointTransformPlugin"),
|
||||
|
||||
AGGREGATOR_PLUGIN("聚合插件", "org.code.modules.plugin.common.AggregatorPlugin"),
|
||||
|
||||
DEFAULT("", "");
|
||||
|
||||
public String name;
|
||||
|
||||
public String javaClass;
|
||||
|
||||
PluginEnum(String name, String javaClass) {
|
||||
this.name = name;
|
||||
this.javaClass = javaClass;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package org.code.modules.plugins.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* 分区注解
|
||||
* Created by chenzm on 2016/12/27.
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.TYPE)
|
||||
public @interface PluginPartition {
|
||||
String code() default "";
|
||||
|
||||
String name();
|
||||
|
||||
String type();
|
||||
|
||||
String pattern();
|
||||
|
||||
String javaClass();
|
||||
|
||||
/**
|
||||
* 是否默认分区
|
||||
* @return
|
||||
*/
|
||||
boolean isDefaultPartition() default false;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package org.code.modules.plugins.annotation;
|
||||
|
||||
public enum PluginType {
|
||||
DB_PLUGIN,
|
||||
ETL_TRANS_PLUGIN,
|
||||
BS_PLUGIN,
|
||||
ETL_TRANS_EXP,
|
||||
//ETL的VO对象
|
||||
ETL_TRANS_META,
|
||||
FUNC,
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package org.code.modules.plugins.annotation;
|
||||
|
||||
import org.code.modules.plugins.types.TypeEnum;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.METHOD)
|
||||
public @interface TransNonStandard {
|
||||
|
||||
TypeEnum stdType();
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package org.code.modules.plugins.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.METHOD)
|
||||
public @interface TransStandard {
|
||||
|
||||
String typeCode();
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package org.code.modules.plugins.annotation.function;
|
||||
|
||||
public @interface Asscocation {
|
||||
String relationName();
|
||||
|
||||
Asscocation.RefType refType() default Asscocation.RefType.aggregation;
|
||||
|
||||
public static enum RefType {
|
||||
aggregation,
|
||||
composite;
|
||||
|
||||
private RefType() {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package org.code.modules.plugins.annotation.function;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.FIELD})
|
||||
public @interface Feature {
|
||||
Feature.RefType refType() default Feature.RefType.aggregation;
|
||||
|
||||
Feature.HandlerType handler() default Feature.HandlerType.HANDLER;
|
||||
|
||||
public static enum RefType {
|
||||
aggregation,
|
||||
composite;
|
||||
|
||||
private RefType() {
|
||||
}
|
||||
}
|
||||
|
||||
public static enum HandlerType {
|
||||
IGNORE,
|
||||
HANDLER;
|
||||
|
||||
private HandlerType() {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package org.code.modules.plugins.annotation.function;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.TYPE})
|
||||
public @interface Meta {
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package org.code.modules.plugins.annotation.function;
|
||||
|
||||
public @interface Relation {
|
||||
String relationName();
|
||||
|
||||
Relation.RefType refType() default Relation.RefType.aggregation;
|
||||
|
||||
public static enum RefType {
|
||||
aggregation,
|
||||
composite;
|
||||
|
||||
private RefType() {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
package org.code.modules.plugins.data;
|
||||
|
||||
|
||||
import com.luqj.util.LinkedMultiValueMap;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import org.code.modules.plugins.plugin.IIdentifierGenerator;
|
||||
import org.code.modules.plugins.plugin.IRow;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
|
||||
/**
|
||||
* 数据行
|
||||
* Created by chenzm on 2017/1/6.
|
||||
*/
|
||||
public class RowData extends LinkedMultiValueMap<String, Object> implements IRow<String, Object> {
|
||||
|
||||
private static final String IS_END_ROW = "$D_IS_END_ROW";
|
||||
|
||||
private transient IIdentifierGenerator identifierGenerator = DEFAULT_GENERATOR;
|
||||
|
||||
private boolean isLastRowForDataSet=false;
|
||||
|
||||
private String rowId;
|
||||
|
||||
private String sourceId;
|
||||
|
||||
/**
|
||||
* 默认的ID生成器
|
||||
*/
|
||||
private transient static final IIdentifierGenerator DEFAULT_GENERATOR = new IIdentifierGenerator() {
|
||||
@Override
|
||||
public String generate(IRow<String, Object> row) {
|
||||
return UUID.randomUUID().toString();
|
||||
}
|
||||
};
|
||||
|
||||
public RowData() {
|
||||
}
|
||||
public RowData(Map<String, List<Object>> row){
|
||||
this.putAll(row);
|
||||
}
|
||||
|
||||
public RowData(IIdentifierGenerator generator) {
|
||||
this.identifierGenerator = generator;
|
||||
}
|
||||
|
||||
public RowData(boolean isEndRow) {
|
||||
this.set(IS_END_ROW, isEndRow);
|
||||
}
|
||||
|
||||
public void reset(Map<String, List<Object>> row) {
|
||||
this.clear();
|
||||
this.putAll(row);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String rowId() {
|
||||
if (StringUtils.isBlank(rowId)) {
|
||||
if(identifierGenerator==null){
|
||||
this.rowId=StringUtils.uuid();
|
||||
}else{
|
||||
this.rowId=identifierGenerator.generate(this);
|
||||
}
|
||||
}
|
||||
return this.rowId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否结束行
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean isEndRow() {
|
||||
if(!this.containsKey(IS_END_ROW) || this.getFirst(IS_END_ROW) == null) {
|
||||
return false;
|
||||
}
|
||||
return (Boolean) this.getFirst(IS_END_ROW);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLastRowForDataSet() {
|
||||
return this.isLastRowForDataSet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSourceId() {
|
||||
|
||||
return this.sourceId;
|
||||
}
|
||||
|
||||
public void markLastRowForDataSet(){
|
||||
this.isLastRowForDataSet=true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIdentifierGenerator(IIdentifierGenerator generator) {
|
||||
this.identifierGenerator = generator;
|
||||
}
|
||||
|
||||
public void setEndRow(boolean endRow) {
|
||||
this.set(IS_END_ROW, endRow);
|
||||
}
|
||||
|
||||
public IIdentifierGenerator getIdentifierGenerator() {
|
||||
return identifierGenerator;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,210 @@
|
||||
package org.code.modules.plugins.function;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 内置函数枚举类型
|
||||
*
|
||||
* @author chenzm
|
||||
*/
|
||||
public enum FuncEnum {
|
||||
BAG("BAG", 0, "包函数对参数不进行任何的计算直接返回参数 (系统级函数,NULL-OBJECT模式)", "org.code.modules.plugins.function.method.BagFunc"),
|
||||
|
||||
REVERSE_LONG_TO_DATE("REVERSE_LONG_TO_DATE", 0, "数字转时间格式", "com.code.std.function.method.datetime.ReverseLongToDateFunc"),
|
||||
TO_DATE("CHAR_TO_DATE", 0, "字符串转时间格式", "com.code.std.function.method.datetime.ToDateFunc"),
|
||||
TO_CHAR("DATE_TO_CHAR", 0, "时间转字符串格式", "com.code.std.function.method.datetime.ToCharFunc"),
|
||||
SYS_TIME("SYS_TIME", 0, "获取系统时间", "com.code.std.function.method.datetime.SysTimeFunc"),
|
||||
MILLISECONDS("MILLISECONDS", 0, "获取毫秒数", "com.code.std.function.method.datetime.MilliSeconds"),
|
||||
DATE_ADD("DATE_ADD", 0, "时间添加函数", "com.code.std.function.method.date.AddDayFunc"),
|
||||
|
||||
|
||||
MAX("MAX", 0, "从一组数字中返回最大值", "com.code.std.function.method.mathematical.MaxFunc"),
|
||||
MIN("MIN", 0, "从一组数字中返回最小值", "com.code.std.function.method.mathematical.MinFunc"),
|
||||
AVG("AVG", 0, "从一组数字获取平均值", "com.code.std.function.method.mathematical.AvgFunc"),
|
||||
SUM("SUM", 0, "一组数字的总和", "com.code.std.function.method.mathematical.SumFunc"),
|
||||
CHAR_TO_NUMBER("CHAR_TO_NUMBER", 0, "文本转成数字", "com.code.std.function.method.mathematical.ToNumberFunc"),
|
||||
NUMBER_TO_CHAR("NUMBER_TO_CHAR", 0, "数字转成文本", "com.code.std.function.method.text.ToCharFunc"),
|
||||
POW("POW", 0, "求平方数", "com.code.std.function.method.mathematical.PowFunc"),
|
||||
|
||||
RAVG("RAVG", 1, "数据集间求平均值", "com.code.std.function.method.mathematical.dataset.RAvgFunc"),
|
||||
RMASS("RMASS", 1, "数据集间求众数", "com.code.std.function.method.mathematical.dataset.RMassFunc"),
|
||||
RMAX("RMAX", 1, "数据集间求最大值", "com.code.std.function.method.mathematical.dataset.RMaxFunc"),
|
||||
RMAX_LENGTH("RMAX_LENGTH", 1, "数据集间求最长值", "com.code.std.function.method.mathematical.dataset.RMaxLengthFunc"),
|
||||
RMAX_MIDVALUE("RMAX_MIDVALUE", 1, "数据集间求中位数", "com.code.std.function.method.mathematical.dataset.RMidValueFunc"),
|
||||
RMIN("RMIN", 1, "数据集间求最小值", "com.code.std.function.method.mathematical.dataset.RMinFunc"),
|
||||
RMIN_LENGTH("RMIN_LENGTH", 1, "数据集间求最短值", "com.code.std.function.method.mathematical.dataset.RMinLengthFunc"),
|
||||
RQTR3("RQTR3", 1, "数据集间求四分位数Q3", "com.code.std.function.method.mathematical.dataset.RQtr3Func"),
|
||||
RQTR("RQTR", 1, "数据集间求四分位数Q1", "com.code.std.function.method.mathematical.dataset.RQtrFunc"),
|
||||
RQTR_MINUS("RQTR_MINUS", 1, "数据集间求四分位数极差", "com.code.std.function.method.mathematical.dataset.RQtrMinusFunc"),
|
||||
RRANGE("RRANGE", 1, "数据集间求极差", "com.code.std.function.method.mathematical.dataset.RRangeFunc"),
|
||||
RSTDDEV("RSTDDEV", 1, "数据集间求标准差", "com.code.std.function.method.mathematical.dataset.RStdDevFunc"),
|
||||
RVALUERANGE("RVALUERANGE", 1, "数据集间求值分布", "com.code.std.function.method.mathematical.dataset.RValueRangeFunc"),
|
||||
RVARIANCE("RVARIANCE", 1, "数据集间求方差", "com.code.std.function.method.mathematical.dataset.RVarianceFunc"),
|
||||
RVALSTA("RVALSTA", 1, "值统计", "com.code.std.function.method.mathematical.dataset.RValStaFunc"),
|
||||
RSUM("RSUM", 1, "数据集间求和", "com.code.std.function.method.mathematical.dataset.RSumFunc"),
|
||||
|
||||
|
||||
TRUE("TRUE", 0, "返回常数true值", "com.code.std.function.method.logical.TrueFunc"),
|
||||
OR("OR", 0, "计算一组布尔参数的逻辑或", "com.code.std.function.method.logical.OrFunc"),
|
||||
AND("AND", 0, "计算一组布尔参数的逻辑 与", "com.code.std.function.method.logical.AndFunc"),
|
||||
IF("IF", 0, "返回两个值中的一个,根据条件", "com.code.std.function.method.logical.IfFunc"),
|
||||
EQ("EQ", 0, "两个数值参数间的逻辑比较是否相等", "com.code.std.function.method.logical.EqFunc"),
|
||||
GT("GT", 0, "两个数值参数间的逻辑比较是否大于", "com.code.std.function.method.logical.GtFunc"),
|
||||
GTE("GTE", 0, "两个数值参数间的逻辑比较是否大于等于", "com.code.std.function.method.logical.GteFunc"),
|
||||
LT("LT", 0, "两个数值参数间的逻辑比较是否小于", "com.code.std.function.method.logical.LtFunc"),
|
||||
LTE("LTE", 0, "两个数值参数间的逻辑比较是否小于等于", "com.code.std.function.method.logical.LteFunc"),
|
||||
NOT("NOT", 0, "计算逻辑NOT", "com.code.std.function.method.logical.NotFunc"),
|
||||
XOR("XOR", 0, "计算逻辑XOR", "com.code.std.function.method.logical.XorFunc"),
|
||||
MATCH("MATCH", 0, "逻辑匹配函数", "com.code.std.function.method.logical.MatchFunc"),
|
||||
|
||||
CHOOSE("CHOOSE", 0, "使用索引从值的列表返回一个值", "com.code.std.function.method.information.ChooseFunc"),
|
||||
ISBLANK("ISBLANK", 0, "如果参数值为空返回TRUE,否则返回FALSE", "com.code.std.function.method.information.IsBlankFunc"),
|
||||
ISNUMBER("ISNUMBER", 0, "如果参数值为数字返回TRUE,否则返回FALSE", "com.code.std.function.method.information.IsNumberFunc"),
|
||||
ISTEXT("ISTEXT", 0, "如果参数值为文本返回TRUE,否则返回FALSE", "com.code.std.function.method.information.IsTextFunc"),
|
||||
|
||||
TEXT("TEXT", 0, "返回转换为文本的值", "com.code.std.function.method.text.TextFunc"),
|
||||
TRIM("TRIM", 0, "返回文本去空后的值", "com.code.std.function.method.text.TrimFunc"),
|
||||
UPPER("UPPER", 0, "小写字母转换为大写字母", "com.code.std.function.method.text.UpperFunc"),
|
||||
LEN("LEN", 0, "返回文本的长度", "com.code.std.function.method.text.LenFunc"),
|
||||
LOWER("LOWER", 0, "大写字母转换为小写字母", "com.code.std.function.method.text.LowerFunc"),
|
||||
SUBSTRING("SUBSTRING", 0, "文本截取函数", "com.code.std.function.method.text.SubstringFunc"),
|
||||
REPLACE("REPLACE", 0, "文本替换函数", "com.code.std.function.method.text.ReplaceFunc"),
|
||||
EXACT("EXACT", 0, "比较两个字符串是否一致", "com.code.std.function.method.text.ExactFunc"),
|
||||
FIND("FIND", 0, "查找字符串的位置", "com.code.std.function.method.text.FindFunc"),
|
||||
CONCAT("CONCAT", 0, "字符串连接函数", "com.code.std.function.method.text.ConcatFunc"),
|
||||
CONCAT_MULTI("CONCAT_MULTI", 0, "字符串连接函数(可变长参数)", "com.code.std.function.method.text.ConcatFunc"),
|
||||
SPLITROW("SPLITROW", 0, "一行拆分成多行", "com.code.std.function.method.text.SplitIntoMultiRows"),
|
||||
JSONPARSE("JSONPARSE", 0, "JSON解析", "com.code.std.function.method.text.JsonParseFunc"),
|
||||
SPLIT("SPLIT", 0, "文本切分", "com.code.std.function.method.text.SplitFunc"),
|
||||
INCLUDE("INCLUDE", 0, "包含函数", "com.code.std.function.method.text.IncludeFunc"),
|
||||
|
||||
DECODE("DECODE", 0, "decode函数解析", "com.code.std.function.method.text.DecodeFunc"),
|
||||
TO_ARRAY("TO_ARRAY", 0, "字符串转数组", "com.code.std.function.method.text.ToArrayFunc"),
|
||||
|
||||
BIZ_IDCARD_GENDER("BIZ_IDCARD_GENDER", 0, "身份证查询性别函数", "com.code.std.function.method.biz.IdCardGenderFunc"),
|
||||
BIZ_IDCARD_BIRTH("BIZ_IDCARD_BIRTH", 0, "身份证查询日期函数", "com.code.std.function.method.biz.IdCardBirthDay"),
|
||||
BIZ_KEYPERSON_FILTER("BIZ_KEYPERSON_FILTER", 0, "前科人员筛选函数", "com.code.std.function.method.biz.KeyPersonFilterFunc"),
|
||||
BIZ_MERGE_KEYPERSON("BIZ_MERGE_KEYPERSON", 0, "前科人员合并函数", "com.code.std.function.method.biz.MergeKeyPersonFunc"),
|
||||
|
||||
DATA_COMPARISON("DATA_COMPARISON", 0, "数据比对", ""),
|
||||
REDIS_DELETE("REDIS_DELETE", 0, "redis数据删除", ""),
|
||||
REDIS_VALUES("REDIS_VALUES", 0, "redis取值", ""),
|
||||
QUERY_CACHE("QUERY_CACHE", 0, "redis缓存查询", ""),
|
||||
|
||||
|
||||
BERNOULLI_SAMPLER("BERNOULLI_SAMPLER", 0, "伯努利数据抽样", ""),
|
||||
POISSON_SAMPLER("POISSON_SAMPLER", 0, "泊松数据抽样", ""),
|
||||
RESERVOIR_SAMPLER("RESERVOIR_SAMPLER", 0, "水塘抽样", " "),
|
||||
|
||||
|
||||
TEMPLATE_FUNCTION_A("TEMPLATE_FUNCTION_A", 0, "空模板", "com.code.std.function.method.biz.TemplateFunctionA"),
|
||||
|
||||
REDUCE_BY_COUNT("REDUCE_BY_COUNT", 0, "reduce统计函数", "com.code.std.function.method.reduce.CountNumberFunc"),
|
||||
|
||||
PLATENO_FILTER("PLATENO_FILTER", 0, "过滤数据", "com.code.std.function.method.fatePlate.PlateNOFilterFunc"),
|
||||
PLATENO_TEST("PLATENO_TEST", 0, "车牌测试数据", "com.code.std.function.method.fatePlate.PlateNOTestFunc"),
|
||||
|
||||
//fakePlate
|
||||
STR_CONTAINS("STR_CONTAINS", 0, "判断是否包含字符串", "com.code.std.function.method.fatePlate.StrContainsFunc"),
|
||||
UTC_DATE_PARSE("UTC_DATE_PARSE", 0, "转换东八区时间", "com.code.std.function.method.fatePlate.UTCDateParseFunc"),
|
||||
DISTINCT_SORT_VEHICLE("DISTINCT_SORT_VEHICLE", 0, "去重并排序卡口", "com.code.std.function.method.fatePlate.DistinctSortVehicleFunc"),
|
||||
SPLIT_VEHICLE_TUPPLE("SPLIT_VEHICLE_TUPPLE", 0, "拆分卡口元组", "com.code.std.function.method.fatePlate.SplitVehicleTuppleFunc"),
|
||||
SUSPECT_FAKE("SUSPECT_FAKE", 0, "嫌疑车查找", "com.code.std.function.method.fatePlate.SuspectFakeFunc"),
|
||||
// MINUTES_DIFF("MINUTES_DIFF", 0, "时间差,返回分钟", "com.code.std.function.method.fatePlate.MinutesDiffFunc"),
|
||||
MINUTES_COMPARE("MINUTES_COMPARE", 0, "时间差(单位:分钟)和某一阈值的比较", "com.code.std.function.method.fatePlate.MinutesCompareFunc"),
|
||||
NUM_KEY_SORT("NUM_KEY_SORT", 0, "针对数字类型列排序", "com.code.std.function.method.fatePlate.NumKeySortFunc"),
|
||||
NUM_KEY_SORT_DISTINCT("NUM_KEY_SORT_DISTINCT", 0, "针对数字类型列排序,并去重", "com.code.std.function.method.fatePlate.NumKeySortDistinctFunc"),
|
||||
SPLIT_TUPPLE("SPLIT_TUPPLE", 0, "划分二元组", "com.code.std.function.method.fatePlate.SplitTuppleFunc"),
|
||||
// NUM_COMPARE("NUM_COMPARE", 0, "数值比较", "com.code.std.function.method.fatePlate.NumCompareFunc"),
|
||||
MILLIS_TO_STRING("MILLIS_TO_STRING", 0, "时间戳转字符串", "com.code.std.function.method.fatePlate.MillisToString"),
|
||||
STR_KEY_SORT("STR_KEY_SORT", 0, "针对字符串类型列排序", "com.code.std.function.method.sort.StrKeySortFunc"),
|
||||
STR_KEY_SORT_DISTINCT("STR_KEY_SORT_DISTINCT", 0, "针对字符串类型列排序,并去重", "com.code.std.function.method.sort.StrKeySortDistinctFunc"),
|
||||
DAYS_COMPARE("DAYS_COMPARE", 0, "时间差(单位:天数)和某一阈值比较", "com.code.std.function.method.date.DaysCompareFunc"),
|
||||
DAYS_DIFF("DAYS_DIFF", 0, "时间差,返回天数", "com.code.std.function.method.date.DaysDiffFunc"),
|
||||
HOURS_COMPARE("HOURS_COMPARE", 0, "时间差(单位:小时)和某一阈值比较", "com.code.std.function.method.date.HoursCompareFunc"),
|
||||
HOURS_DIFF("HOURS_DIFF", 0, "时间差,返回小时", "com.code.std.function.method.date.HoursDiffFunc"),
|
||||
SECONDS_COMPARE("SECONDS_COMPARE", 0, "时间差(单位:秒)和某一阈值比较", "com.code.std.function.method.date.SecondsCompareFunc"),
|
||||
SECONDS_DIFF("SECONDS_DIFF", 0, "时间差,返回秒", "com.code.std.function.method.date.SecondsDiffFunc"),
|
||||
MD5("MD5", 0, "MD5加密", "com.code.std.function.method.encrypt.MD5Func"),
|
||||
CEIL("CEIL", 0, "大于输入数的整数", "com.code.std.function.method.mathematical.CeilFunc"),
|
||||
// FLOOR("FLOOR", 0, "不小于输入数的整数", "com.code.std.function.method.mathematical.FloorFunc"),
|
||||
// ROUND("ROUND", 0, "四舍五入", "com.code.std.function.method.mathematical.RoundFunc"),
|
||||
SYS_GUID("SYS_GUID", 0, "生成唯一主键,不传参默认生成32位,传入指定数字生成指定位数的主键", "com.code.std.function.method.encrypt.SysGUIDFunc"),
|
||||
REDUCE_DISTINCT("REDUCE_DISTINCT",0,"数据去重","com.code.std.function.method.distinctSort.ReduceDistinctFunc"),
|
||||
REDUCE_STR_KEY_ASC_DISTINCT("REDUCE_STR_KEY_ASC_DISTINCT",0,"字符串排序并去重","com.code.std.function.method.distinctSort.ReduceStrKeyAscDistinctFunc"),
|
||||
REDUCE_NUM_KEY_ASC_DISTINCT("REDUCE_NUM_KEY_ASC_DISTINCT",0,"数字排序并去重","com.code.std.function.method.distinctSort.ReduceNumKeyAscDistinctFunc"),
|
||||
REDUCE_STR_KEY_ASC("REDUCE_STR_KEY_ASC",0,"字符串排序","com.code.std.function.method.distinctSort.ReduceStrKeyAscFunc"),
|
||||
REDUCE_NUM_KEY_ASC("REDUCE_NUM_KEY_ASC",0,"数字排序","com.code.std.function.method.distinctSort.ReduceNumKeyAscFunc"),
|
||||
LONG_LAT_DISTANCE("LONG_LAT_DISTANCE",0,"计算经纬度","com.code.std.function.method.mathematical.LongLatDistanceFunc"),
|
||||
CACHING_FAKE("CACHING_FAKE",0,"福州卡口对比函数","com.code.std.function.method.caching.CachingFakeFunc"),
|
||||
|
||||
//异常处理类
|
||||
TRY_CATCH("TRY_CATCH", 0, "异常处理类", "com.code.std.function.method.exception.TryCatchFunc"),
|
||||
|
||||
CACHING_APPLY("CACHING_APPLY", 0, "缓存迭代计算", "com.code.std.function.method.caching.CachingApply"),
|
||||
|
||||
DATE_WINDOW_EXPAND("DATE_WINDOW_EXPAND", 0, "时间戳函数", "com.code.std.function.method.reduce.DateWindowExpandFunc"),
|
||||
MERGE_VALUE("MERGE_VALUE", 0, "合并数据", "com.code.std.function.method.reduce.MergeValFunc"),
|
||||
|
||||
REDUCE_MAP("REDUCE_MAP", 0, "REDUCE_MAP函数", "com.code.std.function.method.reduce.ReduceMapFunc"),
|
||||
|
||||
FREQ_STA("FREQ_STA", 0, "今日频率统计与之前N天频率比较", "com.code.std.function.method.biz.FreqStaFunc");
|
||||
|
||||
String code;
|
||||
String name;
|
||||
int dataform;
|
||||
String clazz;
|
||||
|
||||
FuncEnum(String code, int dataform, String name, String clazz) {
|
||||
this.code = code;
|
||||
this.dataform = dataform;
|
||||
this.name = name;
|
||||
this.clazz = clazz;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getClazz() {
|
||||
return clazz;
|
||||
}
|
||||
|
||||
public void setClazz(String clazz) {
|
||||
this.clazz = clazz;
|
||||
}
|
||||
|
||||
public int getDataform() {
|
||||
return dataform;
|
||||
}
|
||||
|
||||
public void setDataform(int dataform) {
|
||||
this.dataform = dataform;
|
||||
}
|
||||
|
||||
|
||||
static Set<String> funcSet = new HashSet<String>(FuncEnum.values().length);
|
||||
|
||||
public static Set<String> funcSet() {
|
||||
if (funcSet.size() > 0) {
|
||||
return funcSet;
|
||||
}
|
||||
for (FuncEnum func : FuncEnum.values()) {
|
||||
funcSet.add(func.getCode());
|
||||
}
|
||||
return funcSet;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package org.code.modules.plugins.function;
|
||||
|
||||
/**
|
||||
* 表达式接口
|
||||
* @author chenzm
|
||||
*/
|
||||
public interface IExpression {
|
||||
/**
|
||||
* 执行表达式
|
||||
* @param context
|
||||
* @return
|
||||
*/
|
||||
public IParam execExpression(IExpressionContext context);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package org.code.modules.plugins.function;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 表达式上下文
|
||||
* @author chenzm
|
||||
*/
|
||||
public interface IExpressionContext {
|
||||
public Object getExpressionData(String key);
|
||||
|
||||
public void setExpressionData(String key, Object obj);
|
||||
|
||||
public void clear();
|
||||
|
||||
public Set<String> keySet();
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package org.code.modules.plugins.function;
|
||||
|
||||
public interface IExpressionParse {
|
||||
/**
|
||||
* 解析表达式
|
||||
* @param expression
|
||||
* @return
|
||||
*/
|
||||
public IExpression parseExpression(String expression);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package org.code.modules.plugins.function;
|
||||
|
||||
/**
|
||||
* 函数
|
||||
* @author chenzm
|
||||
*/
|
||||
public interface IFunc {
|
||||
/**
|
||||
* 公式
|
||||
* @param args
|
||||
* @return
|
||||
*/
|
||||
public IParam fx(IParam... args);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package org.code.modules.plugins.function;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
public interface IIteratorWrap<T> extends Iterator<T> {
|
||||
public void reset();
|
||||
|
||||
public void finish();
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package org.code.modules.plugins.function;
|
||||
|
||||
|
||||
/**
|
||||
* 参数接口
|
||||
* @author chenzm
|
||||
*/
|
||||
public interface IParam{
|
||||
public void setVal(Object val);
|
||||
|
||||
/*public Object getVal(String paramName);*/
|
||||
|
||||
public Object getVal();
|
||||
|
||||
public String getParamName();
|
||||
|
||||
public Class<?> getValType();
|
||||
|
||||
public int getPrecision();
|
||||
|
||||
public int getLength();
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package org.code.modules.plugins.function.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* 函数注解
|
||||
* Created by chenzm on 2016/12/27.
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.TYPE)
|
||||
public @interface FuncBean {
|
||||
/**
|
||||
* 函数英文名
|
||||
* @return
|
||||
*/
|
||||
String code();
|
||||
|
||||
/**
|
||||
* 函数中文名
|
||||
* @return
|
||||
*/
|
||||
String name() default "";
|
||||
|
||||
/**
|
||||
* 函数描述
|
||||
* @return
|
||||
*/
|
||||
String memo() ;
|
||||
|
||||
/**
|
||||
* 函数类全路径
|
||||
* @return
|
||||
*/
|
||||
String clazz() default "";
|
||||
|
||||
/**
|
||||
* 分类目录
|
||||
* @return
|
||||
*/
|
||||
String classifyDir();
|
||||
|
||||
/**
|
||||
* 函数类型
|
||||
* @return
|
||||
*/
|
||||
FuncTypeEnum funcType();
|
||||
|
||||
/**
|
||||
* 函数例子
|
||||
* @return
|
||||
*/
|
||||
FuncExample[] examples() default {};
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package org.code.modules.plugins.function.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* 函数例子
|
||||
* Created by chenzm on 2017/11/24.
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.METHOD)
|
||||
public @interface FuncExample {
|
||||
String code() default "";
|
||||
|
||||
String name() default "";
|
||||
|
||||
String memo();
|
||||
|
||||
String input() default "";
|
||||
|
||||
String result() default "";
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
package org.code.modules.plugins.function.annotation;
|
||||
|
||||
|
||||
import org.code.modules.plugins.types.TypeEnum;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* 函数方法
|
||||
* Created by chenzm on 2017/11/24.
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.METHOD)
|
||||
public @interface FuncMethod {
|
||||
String code() default "";
|
||||
|
||||
String name() default "";
|
||||
|
||||
FuncParam outputParam() default @FuncParam(name = "返回值为VOID方法", valType = TypeEnum.String);
|
||||
|
||||
FuncParam[] inputParams() default {};
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package org.code.modules.plugins.function.annotation;
|
||||
|
||||
|
||||
import org.code.modules.plugins.types.TypeEnum;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* 函数参数注解
|
||||
* Created by chenzm on 2016/12/27.
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.PARAMETER)
|
||||
public @interface FuncParam {
|
||||
/**
|
||||
* 参数英文名
|
||||
* @return
|
||||
*/
|
||||
String code() default "";
|
||||
|
||||
/**
|
||||
* 参数中文名
|
||||
* @return
|
||||
*/
|
||||
String name();
|
||||
|
||||
/**
|
||||
* 值类型
|
||||
* @return
|
||||
*/
|
||||
TypeEnum valType() default TypeEnum.String;
|
||||
|
||||
/**
|
||||
* 值精度
|
||||
* @return
|
||||
*/
|
||||
int precision() default 0;
|
||||
|
||||
/**
|
||||
* 值长度
|
||||
* @return
|
||||
*/
|
||||
int length() default 0;
|
||||
|
||||
/**
|
||||
* 默认值
|
||||
* @return
|
||||
*/
|
||||
String defVal() default "";
|
||||
|
||||
/**
|
||||
* 是否是Any
|
||||
* @return
|
||||
*/
|
||||
boolean isAny() default false;
|
||||
|
||||
/**
|
||||
* 是否不为空
|
||||
* @return
|
||||
*/
|
||||
boolean isNotNull() default false;
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
package org.code.modules.plugins.function.annotation;
|
||||
|
||||
/**
|
||||
* 函数类型枚举
|
||||
* Created by chenzm on 2017/11/23.
|
||||
*/
|
||||
public enum FuncTypeEnum {
|
||||
NORMAL("NORMAL", "普通函数", "每次函数执行都返回数据"),
|
||||
|
||||
AGGREGATION("AGGREGATION", "聚合函数", "按key汇集统计数据的结果"),
|
||||
|
||||
FLAT_MAP("FLAT_MAP", "FLAT MAP函数", "FLAT MAP函数");
|
||||
|
||||
private String code;
|
||||
|
||||
private String name;
|
||||
|
||||
private String memo;
|
||||
|
||||
FuncTypeEnum(String code, String name, String memo) {
|
||||
this.code = code;
|
||||
this.name = name;
|
||||
this.memo = memo;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getMemo() {
|
||||
return memo;
|
||||
}
|
||||
|
||||
public void setMemo(String memo) {
|
||||
this.memo = memo;
|
||||
}
|
||||
}
|
||||
Vendored
+25
@@ -0,0 +1,25 @@
|
||||
package org.code.modules.plugins.function.cache;
|
||||
|
||||
/**
|
||||
* Created by liwei on 2017/9/25.
|
||||
*/
|
||||
public class CachingTransException extends RuntimeException{
|
||||
public CachingTransException() {
|
||||
}
|
||||
|
||||
public CachingTransException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public CachingTransException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public CachingTransException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public CachingTransException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
}
|
||||
+112
@@ -0,0 +1,112 @@
|
||||
package org.code.modules.plugins.function.cache;
|
||||
|
||||
|
||||
|
||||
import com.luqj.util.Validator;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by liwei on 2017/9/19.
|
||||
*/
|
||||
|
||||
|
||||
public class FreqSeriesRolling<VAL,APPLY_VAL> implements IRollingCaching<VAL,Long,APPLY_VAL>{
|
||||
|
||||
private int windowsSize;
|
||||
|
||||
private IListCaching caching;
|
||||
|
||||
private IRollingDataFormat<VAL,Long> dataFormat;
|
||||
|
||||
public FreqSeriesRolling(int windowsSize){
|
||||
this.windowsSize = windowsSize;
|
||||
}
|
||||
|
||||
|
||||
public APPLY_VAL rollingAfter(String key,VAL val, IRollingApply<VAL,Long, APPLY_VAL> apply, boolean fullApply) throws CachingTransException{
|
||||
ICacheContainer.ICachingTransaction trans = null;
|
||||
try{
|
||||
APPLY_VAL applyVal = null;
|
||||
trans = caching.createTrans();
|
||||
trans.begin(key);
|
||||
List<String> queues = caching.getVal(new IListCaching.ListCacheKey(key),trans);
|
||||
if(!fullApply || (fullApply && !Validator.ltLength(queues,windowsSize))){
|
||||
Map<VAL,Long> v = new LinkedHashMap<>();
|
||||
int i = 0;
|
||||
for (String vk : queues){
|
||||
v.put(dataFormat.toVal(vk),dataFormat.toIDX(i));
|
||||
i++;
|
||||
}
|
||||
applyVal = apply.apply(key,v);
|
||||
}
|
||||
if(queues.size() >= windowsSize){
|
||||
caching.delFirst(key,false,trans);
|
||||
}
|
||||
List<String> v = new ArrayList<>();
|
||||
v.add(dataFormat.fromVal(val));
|
||||
caching.set(new IListCaching.ListCacheKey(key, IListCaching.ListCacheKey.ListCacheKeyType.RIGHT),v,trans);
|
||||
trans.commit();
|
||||
return applyVal;
|
||||
}finally {
|
||||
trans.end();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public APPLY_VAL rollingBefore(String key, VAL val, IRollingApply<VAL, Long, APPLY_VAL> apply, boolean fullApply) throws CachingTransException{
|
||||
ICacheContainer.ICachingTransaction trans = null;
|
||||
try{
|
||||
APPLY_VAL applyVal = null;
|
||||
trans = caching.createTrans();
|
||||
trans.begin(key);
|
||||
List<String> queues = caching.getVal(new IListCaching.ListCacheKey(key),trans);
|
||||
|
||||
if(!fullApply || (fullApply && !Validator.ltLength(queues,windowsSize))){
|
||||
|
||||
queues.remove(0);
|
||||
|
||||
queues.add(dataFormat.fromVal(val));
|
||||
|
||||
Map<VAL,Long> v = new LinkedHashMap<>();
|
||||
int i = 0;
|
||||
for (String vk : queues){
|
||||
v.put(dataFormat.toVal(vk),dataFormat.toIDX(i));
|
||||
i++;
|
||||
}
|
||||
applyVal = apply.apply(key,v);
|
||||
}
|
||||
|
||||
if(queues.size() >= windowsSize){
|
||||
caching.delFirst(key,false);
|
||||
}
|
||||
List<String> v = new ArrayList<>();
|
||||
v.add(dataFormat.fromVal(val));
|
||||
caching.set(new IListCaching.ListCacheKey(key),v);
|
||||
trans.commit();
|
||||
return applyVal;
|
||||
}finally {
|
||||
trans.end();
|
||||
}
|
||||
}
|
||||
|
||||
public IListCaching getCaching() {
|
||||
return caching;
|
||||
}
|
||||
|
||||
public void setCaching(IListCaching caching) {
|
||||
this.caching = caching;
|
||||
}
|
||||
|
||||
public IRollingDataFormat<VAL, Long> getDataFormat() {
|
||||
return dataFormat;
|
||||
}
|
||||
|
||||
public void setDataFormat(IRollingDataFormat<VAL, Long> dataFormat) {
|
||||
this.dataFormat = dataFormat;
|
||||
}
|
||||
|
||||
}
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
package org.code.modules.plugins.function.cache;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Created by liwei on 2017/9/11.
|
||||
*/
|
||||
public interface ICacheContainer<CONN,KEY,VAL> {
|
||||
|
||||
void init();
|
||||
|
||||
void setCache(CONN cnn, KEY key, VAL val) throws Throwable;
|
||||
|
||||
void delCache(CONN cnn, KEY s) throws Throwable;
|
||||
|
||||
VAL getCache(CONN cnn, KEY key) throws Throwable;
|
||||
|
||||
long incrBy(CONN cnn, KEY key, long v)throws Throwable;
|
||||
|
||||
Set<KEY> getAllKey(CONN cnn)throws Throwable;
|
||||
|
||||
Map<KEY,VAL> getBatchCache(CONN cnn, Collection<KEY> key) throws Throwable;
|
||||
|
||||
void batchSet(CONN cnn, Map<KEY, VAL> val);
|
||||
|
||||
ICachingTransaction<KEY> createTrans(boolean hasTrans);
|
||||
|
||||
|
||||
boolean isEmpty(VAL val);
|
||||
|
||||
|
||||
void flushDB();
|
||||
|
||||
void close();
|
||||
|
||||
|
||||
static enum EnumConnType{
|
||||
KEEP_ALIVE,
|
||||
SHORT_CONN
|
||||
}
|
||||
|
||||
|
||||
static interface ICachingTransaction<KEY>{
|
||||
void begin(KEY key);
|
||||
boolean commit();
|
||||
void end();
|
||||
boolean hasLock();
|
||||
|
||||
}
|
||||
|
||||
|
||||
static interface ICacheContainerConnController<CONN>{
|
||||
|
||||
void init(Map<String, String> values);
|
||||
|
||||
CONN getConn();
|
||||
|
||||
void release(CONN conn);
|
||||
|
||||
void destroy();
|
||||
|
||||
}
|
||||
|
||||
EnumConnType getConnType();
|
||||
|
||||
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
package org.code.modules.plugins.function.cache;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Created by liwei on 2017/9/11.
|
||||
*/
|
||||
public interface ICaching<KEY,VAL>{
|
||||
|
||||
String info();
|
||||
|
||||
void init();
|
||||
|
||||
boolean isLazyLoading();
|
||||
|
||||
VAL getVal(KEY key);
|
||||
|
||||
Set<KEY> getAllKey();
|
||||
|
||||
VAL getVal(KEY key, ICacheContainer.ICachingTransaction trans);
|
||||
|
||||
Map<KEY,VAL> getBatchVal(Collection<KEY> key);
|
||||
|
||||
Map<KEY, VAL> getBatchVal(Collection<KEY> val, ICacheContainer.ICachingTransaction trans);
|
||||
|
||||
void set(KEY key, VAL val);
|
||||
|
||||
void set(KEY key, VAL val, ICacheContainer.ICachingTransaction trans);
|
||||
|
||||
void del(KEY key);
|
||||
|
||||
void del(KEY key, ICacheContainer.ICachingTransaction trans);
|
||||
|
||||
void delCacheOnly(KEY key);
|
||||
|
||||
void delCacheOnly(KEY key, ICacheContainer.ICachingTransaction trans);
|
||||
|
||||
void batchSet(Map<KEY, VAL> val, Object... obj);
|
||||
|
||||
Map<String, Object> getParams();
|
||||
|
||||
void setParams(Map<String, Object> params);
|
||||
|
||||
void close();
|
||||
|
||||
public ICacheContainer.ICachingTransaction createTrans();
|
||||
|
||||
|
||||
}
|
||||
+108
@@ -0,0 +1,108 @@
|
||||
package org.code.modules.plugins.function.cache;
|
||||
|
||||
|
||||
import com.luqj.util.assertion.Assert;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by liwei on 2017/9/13.
|
||||
*/
|
||||
public interface IListCaching extends ICaching<IListCaching.ListCacheKey,List<String>> {
|
||||
|
||||
void delFirst(String key, boolean delDB);
|
||||
|
||||
void delFirst(String key, boolean delDB, ICacheContainer.ICachingTransaction trans);
|
||||
|
||||
void delLast(String key, boolean delDB);
|
||||
|
||||
void delLast(String key, boolean delDB, ICacheContainer.ICachingTransaction trans);
|
||||
|
||||
|
||||
public static class ListCacheKey{
|
||||
|
||||
private String key;
|
||||
|
||||
private int count;
|
||||
|
||||
//通过值操作数据时使用该字段
|
||||
private List<String> fields = new ArrayList<>();
|
||||
|
||||
private ListCacheKeyType type = ListCacheKeyType.ALL;
|
||||
|
||||
|
||||
public ListCacheKey(String key) {
|
||||
Assert.notNull(key,"key不允许为空!");
|
||||
this.key = key;
|
||||
this.count = count;
|
||||
for (String field : fields){
|
||||
this.fields.add(field);
|
||||
}
|
||||
}
|
||||
public ListCacheKey(String key,ListCacheKeyType type) {
|
||||
Assert.notNull(key,"key不允许为空!");
|
||||
this.key = key;
|
||||
this.type = type;
|
||||
this.count = count;
|
||||
for (String field : fields){
|
||||
this.fields.add(field);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public ListCacheKey(String key, ListCacheKeyType type, int count, String...fields) {
|
||||
Assert.notNull(key,"key不允许为空!");
|
||||
this.key = key;
|
||||
this.type = type;
|
||||
this.count = count;
|
||||
for (String field : fields){
|
||||
this.fields.add(field);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public int getCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
public ListCacheKeyType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(ListCacheKeyType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public boolean existFields(String field){
|
||||
return fields.contains(field);
|
||||
}
|
||||
|
||||
public boolean hasFiled(){
|
||||
return fields.size() > 0;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public List<String> getFields() {
|
||||
return fields;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static enum ListCacheKeyType{
|
||||
ALL,
|
||||
RIGHT,
|
||||
LEFT,
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
package org.code.modules.plugins.function.cache;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by liwei on 2017/9/13.
|
||||
*/
|
||||
public interface IRollingCaching<VAL,IDX,APPLY_VAL>{
|
||||
|
||||
|
||||
|
||||
|
||||
static interface IRollingApply<VAL,IDX,APPLY_VAL>{
|
||||
|
||||
APPLY_VAL apply(String key, Map<VAL, IDX> val);
|
||||
|
||||
}
|
||||
|
||||
|
||||
static interface IRollingDataFormat<VAL,IDX>{
|
||||
|
||||
String fromVal(VAL val);
|
||||
|
||||
VAL toVal(String val);
|
||||
|
||||
double fromIdx(IDX idx);
|
||||
|
||||
IDX toIDX(double idx);
|
||||
};
|
||||
}
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
package org.code.modules.plugins.function.expression;
|
||||
|
||||
import org.code.modules.plugins.function.IExpression;
|
||||
import org.code.modules.plugins.function.IExpressionContext;
|
||||
import org.code.modules.plugins.function.IFunc;
|
||||
import org.code.modules.plugins.function.IParam;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* 抽象函数表达式 (函数加参数才能具体表达某一件事情)
|
||||
* @author chenzm
|
||||
*/
|
||||
public abstract class AbstractFormulaExpression implements IExpression {
|
||||
protected IFunc func;
|
||||
|
||||
protected IParam[] args = null;
|
||||
|
||||
public AbstractFormulaExpression(IFunc f, IParam ...args) {
|
||||
this.func = f;
|
||||
this.args = args;
|
||||
}
|
||||
|
||||
public static FormulaExpression createFuncExpression(Class<? extends IFunc> clazz, IParam ...args) {
|
||||
try {
|
||||
return new FormulaExpression(clazz.newInstance(), args);
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException("创建函数表达式失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IParam execExpression(IExpressionContext context) {
|
||||
for(IParam value : this.args) {
|
||||
//有参数名称就会去表达式上下文取值然后设置到参数对象里面-字段参数
|
||||
if(StringUtils.isNotBlank(value.getParamName())) {
|
||||
value.setVal(context.getExpressionData(value.getParamName()));
|
||||
}
|
||||
}
|
||||
return this.func.fx(args);
|
||||
}
|
||||
|
||||
public abstract void addParam(IParam value);
|
||||
|
||||
protected IParam[] grow(IParam[] buf, int newCapacity) {
|
||||
return Arrays.copyOf(buf, newCapacity);
|
||||
}
|
||||
|
||||
public IFunc getFunc() {
|
||||
return func;
|
||||
}
|
||||
|
||||
public void setFunc(IFunc func) {
|
||||
this.func = func;
|
||||
}
|
||||
|
||||
public IParam[] getArgs() {
|
||||
return args;
|
||||
}
|
||||
|
||||
public void setArgs(IParam[] args) {
|
||||
this.args = args;
|
||||
}
|
||||
}
|
||||
+99
@@ -0,0 +1,99 @@
|
||||
package org.code.modules.plugins.function.expression;
|
||||
|
||||
import org.code.modules.plugins.function.IExpression;
|
||||
import org.code.modules.plugins.function.IExpressionContext;
|
||||
import org.code.modules.plugins.function.IFunc;
|
||||
import org.code.modules.plugins.function.IParam;
|
||||
import org.code.modules.plugins.function.method.AbstractTryCatchFunc;
|
||||
import com.luqj.util.assertion.Assert;
|
||||
import com.luqj.util.log.LogUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 组合表达式(组合模式)
|
||||
*
|
||||
* @author chenzm
|
||||
*/
|
||||
public class CombinationExpression extends AbstractFormulaExpression implements IExpression {
|
||||
|
||||
protected List<IExpression> exps = new ArrayList<IExpression>();
|
||||
|
||||
private List<Object> buf = new ArrayList<Object>();
|
||||
|
||||
//位置信息格式:参数的起始位置
|
||||
private int[] expPosInfo = new int[0];
|
||||
|
||||
public CombinationExpression(IFunc f, IParam... args) {
|
||||
super(f, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IParam execExpression(IExpressionContext context) {
|
||||
try {
|
||||
if (super.args.length == 0) {
|
||||
List<IParam> argList = new ArrayList<IParam>();
|
||||
int pos = 0;
|
||||
for (Object obj : buf) {
|
||||
if (obj instanceof IParam) {
|
||||
argList.add((IParam) obj);
|
||||
} else {
|
||||
this.expPosInfo = Arrays.copyOf(this.expPosInfo, this.expPosInfo.length + 1);
|
||||
this.expPosInfo[exps.size()] = pos;
|
||||
exps.add((IExpression) obj);
|
||||
argList.add(((IExpression) obj).execExpression(context));
|
||||
}
|
||||
pos++;
|
||||
}
|
||||
super.args = argList.toArray(new IParam[argList.size()]);
|
||||
} else {
|
||||
int pos = 0;
|
||||
for (IExpression exp : exps) {
|
||||
super.args[expPosInfo[pos]] = exp.execExpression(context);
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
if (!isTryCatch()) {
|
||||
throw e;
|
||||
}
|
||||
|
||||
IParam errorParam = AbstractTryCatchFunc.createExceptionParam(
|
||||
LogUtil.exceptionMsg(String.format("%s执行错误", this.func.getClass().getName()), e)
|
||||
);
|
||||
Assert.logic(buf.size() > 0, String.format("异常消息处理类[%s]参数至少要有一个", this.func.getClass().getName()));
|
||||
|
||||
IParam[] errorParams = null;
|
||||
if (buf.size() == 1) {
|
||||
errorParams = new IParam[]{errorParam};
|
||||
} else {
|
||||
Object errorHandler = buf.get(1);
|
||||
if (buf.get(1) instanceof IParam)
|
||||
errorParams = new IParam[]{errorParam, (IParam) errorHandler};
|
||||
else
|
||||
errorParams = new IParam[]{errorParam, ((IExpression) errorHandler).execExpression(context)};
|
||||
}
|
||||
return super.func.fx(errorParams);
|
||||
}
|
||||
return super.execExpression(context);
|
||||
}
|
||||
|
||||
private boolean isTryCatch() {
|
||||
return AbstractTryCatchFunc.class.isAssignableFrom(this.func.getClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addParam(IParam value) {
|
||||
this.buf.add(value);
|
||||
}
|
||||
|
||||
public void addExpression(IExpression expression) {
|
||||
this.buf.add(expression);
|
||||
}
|
||||
|
||||
public void addParamOrExp(Object obj) {
|
||||
this.buf.add(obj);
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
package org.code.modules.plugins.function.expression;
|
||||
|
||||
import org.code.modules.plugins.function.IExpressionContext;
|
||||
import net.sf.json.JSONObject;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 默认的表达式上下文
|
||||
* @author chenzm
|
||||
*/
|
||||
public class DefaultExpressionContext implements IExpressionContext{
|
||||
|
||||
private Map<String, Object> data = new HashMap<String, Object>();
|
||||
|
||||
@Override
|
||||
public Object getExpressionData(String key) {
|
||||
return this.data.get(StringUtils.upperCase(key));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setExpressionData(String key, Object val) {
|
||||
this.data.put(StringUtils.upperCase(key), val);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
data.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> keySet() {
|
||||
return data.keySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return JSONObject.fromObject(data).toString();
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package org.code.modules.plugins.function.expression;
|
||||
|
||||
import org.code.modules.plugins.function.IExpression;
|
||||
import org.code.modules.plugins.function.IFunc;
|
||||
import org.code.modules.plugins.function.IParam;
|
||||
|
||||
/**
|
||||
* 基础的算式表达式
|
||||
* @author chenzm
|
||||
*/
|
||||
public class FormulaExpression extends AbstractFormulaExpression implements IExpression {
|
||||
|
||||
public FormulaExpression(IFunc f, IParam ...args) {
|
||||
super(f, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addParam(IParam value) {
|
||||
if(this.args == null) {
|
||||
this.args = new IParam[1];
|
||||
this.args[0] = value;
|
||||
}else {
|
||||
int len = this.args.length;
|
||||
this.args = grow(this.args, len + 1);
|
||||
this.args[len] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package org.code.modules.plugins.function.method;
|
||||
|
||||
import org.code.modules.plugins.function.IFunc;
|
||||
import org.code.modules.plugins.function.IParam;
|
||||
import org.code.modules.plugins.function.param.StandTypeParam;
|
||||
import org.code.modules.plugins.types.TypeEnum;
|
||||
|
||||
/**
|
||||
* 抽象公式函数
|
||||
* @author chenzm
|
||||
*/
|
||||
public abstract class AbstractFunc implements IFunc {
|
||||
|
||||
protected boolean isReset = true;
|
||||
|
||||
@Override
|
||||
public IParam fx(IParam... args) {
|
||||
if(args.length == 0) {
|
||||
return getDefVal();
|
||||
}
|
||||
return _fx(args);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 默认返回值
|
||||
* @return
|
||||
*/
|
||||
protected abstract IParam getDefVal();
|
||||
|
||||
/**
|
||||
* 公式
|
||||
* @param args
|
||||
* @return
|
||||
*/
|
||||
public abstract IParam _fx(IParam[] args);
|
||||
|
||||
/**
|
||||
* 是否重置
|
||||
* @return
|
||||
*/
|
||||
public boolean isReset() {
|
||||
return this.isReset;
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭重置
|
||||
*/
|
||||
public void disableReset() {
|
||||
this.isReset = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 开启重置
|
||||
*/
|
||||
public void enableReset() {
|
||||
this.isReset = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取兼容性最高的类型
|
||||
* @param args
|
||||
* @return
|
||||
*/
|
||||
protected StandTypeParam initStandTypeParam(IParam ...args) {
|
||||
TypeEnum type = null;
|
||||
for(int i = 0; i < args.length; i++) {
|
||||
if(args[i].getValType() == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(type == null) {
|
||||
type = TypeEnum.valueOf(args[i].getValType().getSimpleName());
|
||||
}else {
|
||||
TypeEnum t = TypeEnum.valueOf(args[i].getValType().getSimpleName());
|
||||
if(t.getPriority() > type.getPriority()) {
|
||||
type = t;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(type == null) return null;
|
||||
|
||||
return StandTypeParam.createParamByType(type);
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package org.code.modules.plugins.function.method;
|
||||
|
||||
import org.code.modules.plugins.function.IFunc;
|
||||
import org.code.modules.plugins.function.IParam;
|
||||
import org.code.modules.plugins.function.param.StandTypeParam;
|
||||
|
||||
/**
|
||||
* 抽象逻辑函数模板
|
||||
* @author chenzm
|
||||
*/
|
||||
public abstract class AbstractLogicalFunc extends AbstractFunc implements IFunc{
|
||||
|
||||
private static final IParam _true = StandTypeParam.createConstantParam(true);
|
||||
|
||||
private static final IParam _false = StandTypeParam.createConstantParam(false);
|
||||
|
||||
protected StandTypeParam result = null;
|
||||
|
||||
@Override
|
||||
protected IParam getDefVal() {
|
||||
return _true;
|
||||
}
|
||||
|
||||
protected IParam _true() {
|
||||
return _true;
|
||||
}
|
||||
|
||||
protected IParam _false() {
|
||||
return _false;
|
||||
}
|
||||
}
|
||||
+192
@@ -0,0 +1,192 @@
|
||||
package org.code.modules.plugins.function.method;
|
||||
|
||||
import com.luqj.util.ArithmeticEnum;
|
||||
import org.code.modules.plugins.function.IFunc;
|
||||
import org.code.modules.plugins.function.IParam;
|
||||
import org.code.modules.plugins.function.param.ParamFormat;
|
||||
import org.code.modules.plugins.function.param.StandTypeParam;
|
||||
import org.code.modules.plugins.types.TypeEnum;
|
||||
|
||||
/**
|
||||
* 抽象数学公式函数模板
|
||||
* @author chenzm
|
||||
*/
|
||||
public abstract class AbstractMathFunc extends AbstractFunc implements IFunc {
|
||||
|
||||
private static final IParam zero = StandTypeParam.createConstantParam(0);
|
||||
|
||||
@Override
|
||||
protected IParam getDefVal() {
|
||||
return zero;
|
||||
}
|
||||
|
||||
protected void formulaOp(ArithmeticEnum op, IParam arg0, IParam arg1, StandTypeParam result) {
|
||||
switch(op) {
|
||||
case addition:
|
||||
switch(result.getTypeEnum()) {
|
||||
case Short:
|
||||
result.setVal(ParamFormat.format(arg0).shortValue() + ParamFormat.format(arg1).shortValue());
|
||||
break;
|
||||
case Integer:
|
||||
result.setVal(ParamFormat.format(arg0).intValue() + ParamFormat.format(arg1).intValue());
|
||||
break;
|
||||
case Long:
|
||||
result.setVal(ParamFormat.format(arg0).longValue() + ParamFormat.format(arg1).longValue());
|
||||
break;
|
||||
case Float:
|
||||
result.setVal(ParamFormat.format(arg0).floatValue() + ParamFormat.format(arg1).floatValue());
|
||||
break;
|
||||
default:
|
||||
result.setVal(ParamFormat.format(arg0).doubleValue() + ParamFormat.format(arg1).doubleValue());
|
||||
}
|
||||
break;
|
||||
|
||||
case subtract:
|
||||
switch(result.getTypeEnum()) {
|
||||
case Short:
|
||||
result.setVal(ParamFormat.format(arg0).shortValue() - ParamFormat.format(arg1).shortValue());
|
||||
break;
|
||||
case Integer:
|
||||
result.setVal(ParamFormat.format(arg0).intValue() - ParamFormat.format(arg1).intValue());
|
||||
break;
|
||||
case Long:
|
||||
result.setVal(ParamFormat.format(arg0).longValue() - ParamFormat.format(arg1).longValue());
|
||||
break;
|
||||
case Float:
|
||||
result.setVal(ParamFormat.format(arg0).floatValue() - ParamFormat.format(arg1).floatValue());
|
||||
break;
|
||||
default:
|
||||
result.setVal(ParamFormat.format(arg0).doubleValue() - ParamFormat.format(arg1).doubleValue());
|
||||
}
|
||||
break;
|
||||
|
||||
case multiply:
|
||||
switch(result.getTypeEnum()) {
|
||||
case Short:
|
||||
result.setVal(ParamFormat.format(arg0).shortValue() * ParamFormat.format(arg1).shortValue());
|
||||
break;
|
||||
case Integer:
|
||||
result.setVal(ParamFormat.format(arg0).intValue() * ParamFormat.format(arg1).intValue());
|
||||
break;
|
||||
case Long:
|
||||
result.setVal(ParamFormat.format(arg0).longValue() * ParamFormat.format(arg1).longValue());
|
||||
break;
|
||||
case Float:
|
||||
result.setVal(ParamFormat.format(arg0).floatValue() * ParamFormat.format(arg1).floatValue());
|
||||
break;
|
||||
default:
|
||||
result.setVal(ParamFormat.format(arg0).doubleValue() * ParamFormat.format(arg1).doubleValue());
|
||||
}
|
||||
break;
|
||||
|
||||
case division:
|
||||
switch(result.getTypeEnum()) {
|
||||
case Short:
|
||||
result.setVal(ParamFormat.format(arg0).shortValue() / ParamFormat.format(arg1).shortValue());
|
||||
break;
|
||||
case Integer:
|
||||
result.setVal(ParamFormat.format(arg0).intValue() / ParamFormat.format(arg1).intValue());
|
||||
break;
|
||||
case Long:
|
||||
result.setVal(ParamFormat.format(arg0).longValue() / ParamFormat.format(arg1).longValue());
|
||||
break;
|
||||
case Float:
|
||||
result.setVal(ParamFormat.format(arg0).floatValue() / ParamFormat.format(arg1).floatValue());
|
||||
break;
|
||||
default:
|
||||
result.setVal(ParamFormat.format(arg0).doubleValue() / ParamFormat.format(arg1).doubleValue());
|
||||
}
|
||||
break;
|
||||
|
||||
case lt:
|
||||
switch(result.getTypeEnum()) {
|
||||
case Short:
|
||||
result.setVal(ParamFormat.format(arg0).shortValue() < ParamFormat.format(arg1).shortValue() ? 1 : 0);
|
||||
break;
|
||||
case Integer:
|
||||
result.setVal(ParamFormat.format(arg0).intValue() < ParamFormat.format(arg1).intValue() ? 1 : 0);
|
||||
break;
|
||||
case Long:
|
||||
result.setVal(ParamFormat.format(arg0).longValue() < ParamFormat.format(arg1).longValue() ? 1 : 0);
|
||||
break;
|
||||
case Float:
|
||||
result.setVal(ParamFormat.format(arg0).floatValue() < ParamFormat.format(arg1).floatValue() ? 1 : 0);
|
||||
break;
|
||||
case String:
|
||||
result.setVal(ComparatorFactory.getInstance().getComparator(String.class, TypeEnum.String).compare(ParamFormat.obj2Str(arg0), ParamFormat.obj2Str(arg1)) < 0 ? 1 : 0);
|
||||
break;
|
||||
default:
|
||||
result.setVal(ParamFormat.format(arg0).doubleValue() < ParamFormat.format(arg1).doubleValue() ? 1 : 0);
|
||||
}
|
||||
break;
|
||||
|
||||
case lte:
|
||||
switch(result.getTypeEnum()) {
|
||||
case Short:
|
||||
result.setVal(ParamFormat.format(arg0).shortValue() <= ParamFormat.format(arg1).shortValue() ? 1 : 0);
|
||||
break;
|
||||
case Integer:
|
||||
result.setVal(ParamFormat.format(arg0).intValue() <= ParamFormat.format(arg1).intValue() ? 1 : 0);
|
||||
break;
|
||||
case Long:
|
||||
result.setVal(ParamFormat.format(arg0).longValue() <= ParamFormat.format(arg1).longValue() ? 1 : 0);
|
||||
break;
|
||||
case Float:
|
||||
result.setVal(ParamFormat.format(arg0).floatValue() <= ParamFormat.format(arg1).floatValue() ? 1 : 0);
|
||||
break;
|
||||
case String:
|
||||
result.setVal(ComparatorFactory.getInstance().getComparator(String.class, TypeEnum.String).compare(ParamFormat.obj2Str(arg0), ParamFormat.obj2Str(arg1)) <= 0 ? 1 : 0);
|
||||
break;
|
||||
default:
|
||||
result.setVal(ParamFormat.format(arg0).doubleValue() <= ParamFormat.format(arg1).doubleValue() ? 1 : 0);
|
||||
}
|
||||
break;
|
||||
|
||||
case gt:
|
||||
switch(result.getTypeEnum()) {
|
||||
case Short:
|
||||
result.setVal(ParamFormat.format(arg0).shortValue() > ParamFormat.format(arg1).shortValue() ? 1 : 0);
|
||||
break;
|
||||
case Integer:
|
||||
result.setVal(ParamFormat.format(arg0).intValue() > ParamFormat.format(arg1).intValue() ? 1 : 0);
|
||||
break;
|
||||
case Long:
|
||||
result.setVal(ParamFormat.format(arg0).longValue() > ParamFormat.format(arg1).longValue() ? 1 : 0);
|
||||
break;
|
||||
case Float:
|
||||
result.setVal(ParamFormat.format(arg0).floatValue() > ParamFormat.format(arg1).floatValue() ? 1 : 0);
|
||||
break;
|
||||
case String:
|
||||
result.setVal(ComparatorFactory.getInstance().getComparator(String.class, TypeEnum.String).compare(ParamFormat.obj2Str(arg0), ParamFormat.obj2Str(arg1)) > 0 ? 1 : 0);
|
||||
break;
|
||||
default:
|
||||
result.setVal(ParamFormat.format(arg0).doubleValue() > ParamFormat.format(arg1).doubleValue() ? 1 : 0);
|
||||
}
|
||||
break;
|
||||
|
||||
case gte:
|
||||
switch(result.getTypeEnum()) {
|
||||
case Short:
|
||||
result.setVal(ParamFormat.format(arg0).shortValue() >= ParamFormat.format(arg1).shortValue() ? 1 : 0);
|
||||
break;
|
||||
case Integer:
|
||||
result.setVal(ParamFormat.format(arg0).intValue() >= ParamFormat.format(arg1).intValue() ? 1 : 0);
|
||||
break;
|
||||
case Long:
|
||||
result.setVal(ParamFormat.format(arg0).longValue() >= ParamFormat.format(arg1).longValue() ? 1 : 0);
|
||||
break;
|
||||
case Float:
|
||||
result.setVal(ParamFormat.format(arg0).floatValue() >= ParamFormat.format(arg1).floatValue() ? 1 : 0);
|
||||
break;
|
||||
case String:
|
||||
result.setVal(ComparatorFactory.getInstance().getComparator(String.class, TypeEnum.String).compare(ParamFormat.obj2Str(arg0), ParamFormat.obj2Str(arg1)) >= 0 ? 1 : 0);
|
||||
break;
|
||||
default:
|
||||
result.setVal(ParamFormat.format(arg0).doubleValue() >= ParamFormat.format(arg1).doubleValue() ? 1 : 0);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("暂不支持运算符号:" + op.getSymbol());
|
||||
}
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package org.code.modules.plugins.function.method;
|
||||
|
||||
import org.code.modules.plugins.function.IFunc;
|
||||
import org.code.modules.plugins.function.IParam;
|
||||
import org.code.modules.plugins.function.param.StandTypeParam;
|
||||
|
||||
public abstract class AbstractTextFunc extends AbstractFunc implements IFunc{
|
||||
|
||||
protected static final IParam _nullChr = StandTypeParam.createConstantParam("");
|
||||
|
||||
@Override
|
||||
protected IParam getDefVal() {
|
||||
return _nullChr;
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
package org.code.modules.plugins.function.method;
|
||||
|
||||
import com.luqj.util.StringUtils;
|
||||
import org.code.modules.plugins.function.IFunc;
|
||||
import org.code.modules.plugins.function.IParam;
|
||||
import org.code.modules.plugins.function.param.StandTypeParam;
|
||||
import org.code.modules.plugins.types.StringType;
|
||||
|
||||
public abstract class AbstractTryCatchFunc implements IFunc {
|
||||
public static final String EXCEPTION_MESSAGE = "$DRAGON_EXCEPTION_MESSAGE";
|
||||
|
||||
public static IParam createExceptionParam(String errorMsg) {
|
||||
StandTypeParam errorParam = StandTypeParam.createFieldParam(EXCEPTION_MESSAGE, StringType.BASE);
|
||||
errorParam.setVal(errorMsg);
|
||||
return errorParam;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否发生错误
|
||||
*
|
||||
* @param param
|
||||
* @return
|
||||
*/
|
||||
protected boolean isError(IParam param) {
|
||||
if (param != null
|
||||
&& StringUtils.isNotBlank(param.getParamName())
|
||||
&& param.getParamName().equals(EXCEPTION_MESSAGE)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package org.code.modules.plugins.function.method;
|
||||
|
||||
import org.code.modules.plugins.function.IFunc;
|
||||
import org.code.modules.plugins.function.IParam;
|
||||
|
||||
/**
|
||||
* 包函数 eg (3) = 3,(6) = 6
|
||||
* Created by chenzm on 2017/2/18.
|
||||
*/
|
||||
public class BagFunc implements IFunc{
|
||||
@Override
|
||||
public IParam fx(IParam... args) {
|
||||
if(args.length == 0)
|
||||
return null;
|
||||
return args[0];
|
||||
}
|
||||
}
|
||||
+106
@@ -0,0 +1,106 @@
|
||||
package org.code.modules.plugins.function.method;
|
||||
|
||||
import org.code.modules.plugins.types.TypeEnum;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ComparatorFactory {
|
||||
private static ComparatorFactory factory = null;
|
||||
|
||||
private Map<TypeEnum, Comparator<?>> comparatorMap;
|
||||
|
||||
public ComparatorFactory() {
|
||||
comparatorMap = new HashMap<TypeEnum, Comparator<?>>();
|
||||
comparatorMap.put(TypeEnum.Short, new Comparator<Short>(){
|
||||
@Override
|
||||
public int compare(Short o1, Short o2) {
|
||||
return o1.compareTo(o2);
|
||||
}
|
||||
});
|
||||
comparatorMap.put(TypeEnum.Integer, new Comparator<Integer>(){
|
||||
@Override
|
||||
public int compare(Integer o1, Integer o2) {
|
||||
return o1.compareTo(o2);
|
||||
}
|
||||
});
|
||||
comparatorMap.put(TypeEnum.Long, new Comparator<Long>(){
|
||||
@Override
|
||||
public int compare(Long o1, Long o2) {
|
||||
return o1.compareTo(o2);
|
||||
}
|
||||
});
|
||||
comparatorMap.put(TypeEnum.Float, new Comparator<Float>(){
|
||||
@Override
|
||||
public int compare(Float o1, Float o2) {
|
||||
return o1.compareTo(o2);
|
||||
}
|
||||
});
|
||||
comparatorMap.put(TypeEnum.Double, new Comparator<Double>(){
|
||||
@Override
|
||||
public int compare(Double o1, Double o2) {
|
||||
return o1.compareTo(o2);
|
||||
}
|
||||
});
|
||||
comparatorMap.put(TypeEnum.BigInteger, new Comparator<BigInteger>(){
|
||||
@Override
|
||||
public int compare(BigInteger o1, BigInteger o2) {
|
||||
return o1.compareTo(o2);
|
||||
}
|
||||
});
|
||||
comparatorMap.put(TypeEnum.BigDecimal, new Comparator<BigDecimal>(){
|
||||
@Override
|
||||
public int compare(BigDecimal o1, BigDecimal o2) {
|
||||
return o1.compareTo(o2);
|
||||
}
|
||||
});
|
||||
comparatorMap.put(TypeEnum.Boolean, new Comparator<Boolean>(){
|
||||
@Override
|
||||
public int compare(Boolean o1, Boolean o2) {
|
||||
return o1.compareTo(o2);
|
||||
}
|
||||
});
|
||||
comparatorMap.put(TypeEnum.String, new Comparator<String>(){
|
||||
@Override
|
||||
public int compare(String o1, String o2) {
|
||||
return o1.compareTo(o2);
|
||||
}
|
||||
});
|
||||
comparatorMap.put(TypeEnum.Date, new Comparator<Object>(){
|
||||
@Override
|
||||
public int compare(Object o1, Object o2) {
|
||||
if(o1 instanceof java.sql.Date) {
|
||||
return ((java.sql.Date)o1).compareTo((java.sql.Date)o2);
|
||||
}
|
||||
return ((java.util.Date)o1).compareTo((java.util.Date)o2);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static ComparatorFactory getInstance() {
|
||||
if(factory == null) {
|
||||
synchronized (ComparatorFactory.class) {
|
||||
if(factory == null)
|
||||
factory = new ComparatorFactory();
|
||||
}
|
||||
}
|
||||
return factory;
|
||||
}
|
||||
|
||||
public Comparator<?> getComparator(TypeEnum type) {
|
||||
if(!this.comparatorMap.containsKey(type)) {
|
||||
throw new IllegalArgumentException("没有找到" +type.toString() + "类型的比较器");
|
||||
}
|
||||
return this.comparatorMap.get(type);
|
||||
}
|
||||
|
||||
public <T> Comparator<T> getComparator(Class<T> clazz, TypeEnum type) {
|
||||
if(!this.comparatorMap.containsKey(type)) {
|
||||
throw new IllegalArgumentException("没有找到" +type.toString() + "类型的比较器");
|
||||
}
|
||||
return (Comparator<T>)this.comparatorMap.get(type);
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package org.code.modules.plugins.function.method.datetime;
|
||||
|
||||
import org.code.modules.plugins.function.IFunc;
|
||||
import org.code.modules.plugins.function.IParam;
|
||||
|
||||
public abstract class AbstractDateFunc implements IFunc{
|
||||
|
||||
@Override
|
||||
public IParam fx(IParam... args) {
|
||||
return format(args);
|
||||
}
|
||||
|
||||
public abstract IParam format(IParam[] args);
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
package org.code.modules.plugins.function.method.datetime;
|
||||
|
||||
import org.code.modules.plugins.function.IFunc;
|
||||
import org.code.modules.plugins.function.IParam;
|
||||
import org.code.modules.plugins.function.param.ParamFormat;
|
||||
import org.code.modules.plugins.function.param.StandTypeParam;
|
||||
import org.code.modules.plugins.types.TypeEnum;
|
||||
import com.luqj.util.assertion.Assert;
|
||||
|
||||
import java.util.Calendar;
|
||||
|
||||
/**
|
||||
* 毫秒数
|
||||
* Created by chenzm on 2017/9/18.
|
||||
*/
|
||||
public class MilliSeconds extends AbstractDateFunc implements IFunc {
|
||||
private Calendar calendar = null;
|
||||
|
||||
private StandTypeParam sysMillis = StandTypeParam.createParamByType(TypeEnum.Long);
|
||||
|
||||
@Override
|
||||
public IParam format(IParam[] args) {
|
||||
Assert.logic(args.length == 2, "参数长度不匹配");
|
||||
if (calendar == null) {
|
||||
calendar = Calendar.getInstance();
|
||||
}
|
||||
calendar.setTimeInMillis(System.currentTimeMillis());
|
||||
|
||||
int val = ParamFormat.format(args[0]).intValue();
|
||||
String unit = ParamFormat.obj2Str(args[1]);
|
||||
Assert.hasText(unit, "单位不能为空");
|
||||
unit = unit.toUpperCase();
|
||||
|
||||
if ("YEAR".equals(unit)) {
|
||||
calendar.add(Calendar.YEAR, val);
|
||||
} else if ("MONTH".equals(unit)) {
|
||||
calendar.add(Calendar.MONTH, val);
|
||||
} else if ("DAY_OF_YEAR".equals(unit)) {
|
||||
calendar.add(Calendar.DAY_OF_YEAR, val);
|
||||
} else {
|
||||
throw new IllegalArgumentException("赞不支持时间单位[" + unit + "]");
|
||||
}
|
||||
sysMillis.setVal(calendar.getTimeInMillis());
|
||||
return sysMillis;
|
||||
}
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
package org.code.modules.plugins.function.method.datetime;
|
||||
|
||||
import org.code.modules.plugins.function.IFunc;
|
||||
import org.code.modules.plugins.function.IParam;
|
||||
import org.code.modules.plugins.function.param.ParamFormat;
|
||||
import org.code.modules.plugins.function.param.StandTypeParam;
|
||||
import org.code.modules.plugins.types.TypeEnum;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 字符串转成时间格式转换函数
|
||||
*/
|
||||
public class ReverseLongToDateFunc extends AbstractDateFunc implements IFunc {
|
||||
|
||||
private StandTypeParam date = StandTypeParam.createParamByType(TypeEnum.Date);
|
||||
|
||||
/**
|
||||
* 时间类型
|
||||
*/
|
||||
enum DateEnum {
|
||||
NORMAL_DATE("0"),
|
||||
SQL_DATE("1"),
|
||||
SQL_TIMESTAMP("2"),
|
||||
SQL_TIME("3");
|
||||
|
||||
private String code;
|
||||
|
||||
public boolean isEq(String code) {
|
||||
if (this.code.equals(code)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
DateEnum(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IParam format(IParam[] args) {
|
||||
if (ParamFormat.argIsNull(args[0])) {
|
||||
return null;
|
||||
}
|
||||
String dateType = args.length > 1 && !ParamFormat.argIsNull(args[1]) ? ParamFormat.obj2Str(args[1]) : "1";
|
||||
Long time=Long.MAX_VALUE-Long.valueOf(args[0].getVal().toString());
|
||||
if (DateEnum.SQL_DATE.isEq(dateType)) {
|
||||
date.setVal(new java.sql.Date(time));
|
||||
} else if (DateEnum.NORMAL_DATE.isEq(dateType)) {
|
||||
date.setVal(new Date(time));
|
||||
} else if (DateEnum.SQL_TIMESTAMP.isEq(dateType)) {
|
||||
date.setVal(new java.sql.Timestamp(time));
|
||||
} else if (DateEnum.SQL_TIME.isEq(dateType)) {
|
||||
date.setVal(new java.sql.Time(time));
|
||||
}
|
||||
return date;
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package org.code.modules.plugins.function.method.datetime;
|
||||
|
||||
import org.code.modules.plugins.function.IFunc;
|
||||
import org.code.modules.plugins.function.IParam;
|
||||
import org.code.modules.plugins.function.param.ParamFormat;
|
||||
import org.code.modules.plugins.function.param.StandTypeParam;
|
||||
import org.code.modules.plugins.types.TypeEnum;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 系统时间函数
|
||||
* Created by chenzm on 2017/9/18.
|
||||
*/
|
||||
public class SysTimeFunc extends AbstractDateFunc implements IFunc {
|
||||
private StandTypeParam param = StandTypeParam.createParamByType(TypeEnum.String);
|
||||
|
||||
@Override
|
||||
public IParam format(IParam[] args) {
|
||||
long milliSeconds = ParamFormat.format(args[0]).longValue();
|
||||
String outFmt = ParamFormat.obj2Str(args[1]);
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(outFmt);
|
||||
param.setVal(sdf.format(new Date(milliSeconds)));
|
||||
return param;
|
||||
}
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
package org.code.modules.plugins.function.method.datetime;
|
||||
|
||||
import com.luqj.util.date.DateUtils;
|
||||
import com.luqj.util.assertion.Assert;
|
||||
import org.code.modules.plugins.function.IFunc;
|
||||
import org.code.modules.plugins.function.IParam;
|
||||
import org.code.modules.plugins.function.param.ParamFormat;
|
||||
import org.code.modules.plugins.function.param.StandTypeParam;
|
||||
import org.code.modules.plugins.types.TypeEnum;
|
||||
|
||||
import java.text.ParseException;
|
||||
|
||||
/**
|
||||
* 时间格式转成字符串日期
|
||||
* Created by chenzm on 2017/3/1.
|
||||
*/
|
||||
public class ToCharFunc extends AbstractDateFunc implements IFunc {
|
||||
private StandTypeParam dateStr = StandTypeParam.createParamByType(TypeEnum.String);
|
||||
|
||||
@Override
|
||||
public IParam format(IParam[] args) {
|
||||
if (ParamFormat.argIsNull(args[0])) {
|
||||
if (args.length > 2) {
|
||||
return args[2];
|
||||
}
|
||||
dateStr.setVal(null);
|
||||
return dateStr;
|
||||
}
|
||||
if (ParamFormat.isDate(args[0])) {
|
||||
Assert.logic(!ParamFormat.argIsNull(args[1]), "输出的时间格式必须填写");
|
||||
if ("oracle.sql.timestamp".equalsIgnoreCase(args[0].getVal().getClass().getName())) {
|
||||
java.util.Date dateVal = null;
|
||||
try {
|
||||
dateVal = DateUtils.getDate(args[0].getVal().toString(), "yyyy-MM-dd HH:mm:ss");
|
||||
} catch (ParseException e) {
|
||||
throw new IllegalStateException("", e);
|
||||
}
|
||||
dateStr.setVal(DateUtils.getDateFormat(dateVal, ParamFormat.obj2Str(args[1])));
|
||||
} else {
|
||||
dateStr.setVal(DateUtils.getDateFormat((java.util.Date) args[0].getVal(), ParamFormat.obj2Str(args[1])));
|
||||
}
|
||||
} else {
|
||||
dateStr.setVal(args[0].getVal().toString());
|
||||
}
|
||||
return dateStr;
|
||||
}
|
||||
}
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
package org.code.modules.plugins.function.method.datetime;
|
||||
|
||||
import com.luqj.util.date.DateUtils;
|
||||
import org.code.modules.plugins.function.IFunc;
|
||||
import org.code.modules.plugins.function.IParam;
|
||||
import org.code.modules.plugins.function.param.ParamFormat;
|
||||
import org.code.modules.plugins.function.param.StandTypeParam;
|
||||
import org.code.modules.plugins.types.TypeEnum;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 字符串转成时间格式转换函数
|
||||
*/
|
||||
public class ToDateFunc extends AbstractDateFunc implements IFunc{
|
||||
|
||||
private StandTypeParam date = StandTypeParam.createParamByType(TypeEnum.Date);
|
||||
|
||||
/**
|
||||
* 时间类型
|
||||
*/
|
||||
enum DateEnum{
|
||||
NORMAL_DATE("0"),
|
||||
SQL_DATE("1"),
|
||||
SQL_TIMESTAMP("2") ,
|
||||
SQL_TIME("3");
|
||||
|
||||
private String code;
|
||||
|
||||
public boolean isEq(String code) {
|
||||
if(this.code.equals(code)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
DateEnum(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IParam format(IParam[] args) {
|
||||
if(ParamFormat.argIsNull(args[0])){
|
||||
date.setVal(null);
|
||||
return date;
|
||||
}
|
||||
if(ParamFormat.argIsNull(args[1])){
|
||||
throw new IllegalArgumentException("字符串的时间格式必须填写");
|
||||
}
|
||||
String dateType = args.length > 2 && !ParamFormat.argIsNull(args[2]) ? ParamFormat.obj2Str(args[2]) : "1";
|
||||
Date val = null;
|
||||
try {
|
||||
val = DateUtils.getDate(ParamFormat.obj2Str(args[0]), ParamFormat.obj2Str(args[1]));
|
||||
} catch (ParseException e) {
|
||||
throw new IllegalArgumentException("SQL时间转换异常", e);
|
||||
}
|
||||
if(val == null) {
|
||||
date.setVal(null);
|
||||
return date;
|
||||
}
|
||||
if(DateEnum.SQL_DATE.isEq(dateType)){
|
||||
date.setVal(new java.sql.Date(val.getTime()));
|
||||
} else if(DateEnum.NORMAL_DATE.isEq(dateType)){
|
||||
date.setVal(val);
|
||||
}else if(DateEnum.SQL_TIMESTAMP.isEq(dateType)) {
|
||||
date.setVal(new java.sql.Timestamp(val.getTime()));
|
||||
}else if(DateEnum.SQL_TIME.isEq(dateType)){
|
||||
date.setVal(new java.sql.Time(val.getTime()));
|
||||
}
|
||||
return date;
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package org.code.modules.plugins.function.method.exception;
|
||||
|
||||
import org.code.modules.plugins.function.IFunc;
|
||||
import org.code.modules.plugins.function.IParam;
|
||||
import org.code.modules.plugins.function.method.AbstractTryCatchFunc;
|
||||
import org.code.modules.plugins.function.param.StandTypeParam;
|
||||
import org.code.modules.plugins.types.TypeEnum;
|
||||
|
||||
public class TryCatchFunc extends AbstractTryCatchFunc implements IFunc {
|
||||
|
||||
private IParam result = StandTypeParam.createParamByType(TypeEnum.Boolean);
|
||||
|
||||
@Override
|
||||
public IParam fx(IParam... args) {
|
||||
boolean isError = isError(args[0]);
|
||||
if(!isError) {
|
||||
return args[0];
|
||||
}
|
||||
if(args.length == 1) {
|
||||
result.setVal(false);
|
||||
}else {
|
||||
return args[1];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
package org.code.modules.plugins.function.method.information;
|
||||
|
||||
import org.code.modules.plugins.function.IFunc;
|
||||
import org.code.modules.plugins.function.IParam;
|
||||
import org.code.modules.plugins.function.method.AbstractLogicalFunc;
|
||||
import org.code.modules.plugins.function.param.ParamFormat;
|
||||
|
||||
/**
|
||||
* 选择函数
|
||||
* @author chenzm
|
||||
*/
|
||||
public class ChooseFunc extends AbstractLogicalFunc implements IFunc{
|
||||
|
||||
@Override
|
||||
public IParam _fx(IParam[] args) {
|
||||
if(ParamFormat.argIsNull(args[0])) {
|
||||
return null;
|
||||
}
|
||||
int index = ParamFormat.format(args[0]).intValue();
|
||||
if(index >= args.length || index <= 0 ) {
|
||||
throw new IllegalStateException("ChooseFunc索引越界 index:" + index + " 参数个数:" + args.length);
|
||||
}
|
||||
return args[index];
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package org.code.modules.plugins.function.method.information;
|
||||
|
||||
import org.code.modules.plugins.function.IFunc;
|
||||
import org.code.modules.plugins.function.IParam;
|
||||
import org.code.modules.plugins.function.method.AbstractLogicalFunc;
|
||||
import com.luqj.util.StringUtils;
|
||||
|
||||
public class IsBlankFunc extends AbstractLogicalFunc implements IFunc{
|
||||
|
||||
@Override
|
||||
public IParam _fx(IParam[] args) {
|
||||
if(args.length == 0 ) {
|
||||
throw new IllegalStateException("IsBlankFunc函数参数只能一个");
|
||||
}
|
||||
if(args[0].getVal() == null ) {
|
||||
return _true();
|
||||
}else if(args[0].getValType() == String.class &&
|
||||
StringUtils.isBlank((String)args[0].getVal())) {
|
||||
return _true();
|
||||
}
|
||||
return _false();
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package org.code.modules.plugins.function.method.information;
|
||||
|
||||
import org.code.modules.plugins.function.IFunc;
|
||||
import org.code.modules.plugins.function.IParam;
|
||||
import org.code.modules.plugins.function.method.AbstractLogicalFunc;
|
||||
import org.code.modules.plugins.function.param.ParamFormat;
|
||||
|
||||
public class IsNumberFunc extends AbstractLogicalFunc implements IFunc{
|
||||
|
||||
@Override
|
||||
public IParam _fx(IParam[] args) {
|
||||
if(args.length == 0 ) {
|
||||
throw new IllegalStateException("IsNumberFunc函数参数只能一个");
|
||||
}
|
||||
|
||||
if(args[0].getVal() != null && ParamFormat.isNumber(args[0])) {
|
||||
return _true();
|
||||
}
|
||||
return _false();
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package org.code.modules.plugins.function.method.information;
|
||||
|
||||
import org.code.modules.plugins.function.IFunc;
|
||||
import org.code.modules.plugins.function.IParam;
|
||||
import org.code.modules.plugins.function.method.AbstractLogicalFunc;
|
||||
|
||||
public class IsTextFunc extends AbstractLogicalFunc implements IFunc{
|
||||
|
||||
@Override
|
||||
public IParam _fx(IParam[] args) {
|
||||
if(args.length == 0 ) {
|
||||
throw new IllegalStateException("IsTextFunc函数参数只能一个");
|
||||
}
|
||||
if(args[0].getVal() != null && args[0].getValType() == String.class) {
|
||||
return _true();
|
||||
}
|
||||
return _false();
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package org.code.modules.plugins.function.method.logical;
|
||||
|
||||
import org.code.modules.plugins.function.IFunc;
|
||||
import org.code.modules.plugins.function.IParam;
|
||||
import org.code.modules.plugins.function.method.AbstractLogicalFunc;
|
||||
import org.code.modules.plugins.function.param.ParamFormat;
|
||||
|
||||
public class AndFunc extends AbstractLogicalFunc implements IFunc{
|
||||
|
||||
@Override
|
||||
public IParam _fx(IParam[] args) {
|
||||
for(IParam arg : args) {
|
||||
if(ParamFormat.format(arg).intValue() == 0) {
|
||||
return _false();
|
||||
}
|
||||
}
|
||||
return _true();
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package org.code.modules.plugins.function.method.logical;
|
||||
|
||||
import org.code.modules.plugins.function.IFunc;
|
||||
import org.code.modules.plugins.function.IParam;
|
||||
import org.code.modules.plugins.function.method.AbstractLogicalFunc;
|
||||
import org.code.modules.plugins.function.param.ParamFormat;
|
||||
|
||||
/**
|
||||
* @author chenqg
|
||||
* @date 2018/6/28 19:02
|
||||
* @Description: TODO
|
||||
*/
|
||||
public class EqFunc extends AbstractLogicalFunc implements IFunc {
|
||||
@Override
|
||||
public IParam _fx(IParam[] args) {
|
||||
if (args.length != 2) {
|
||||
throw new IllegalArgumentException("EqFunc函数的参数必须是两个");
|
||||
}
|
||||
if (ParamFormat.isEqual(args[0], args[1])) {
|
||||
return _true();
|
||||
}
|
||||
return _false();
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
package org.code.modules.plugins.function.method.logical;
|
||||
|
||||
import org.code.modules.plugins.function.IFunc;
|
||||
import org.code.modules.plugins.function.IParam;
|
||||
import org.code.modules.plugins.function.method.AbstractLogicalFunc;
|
||||
import org.code.modules.plugins.function.param.ParamFormat;
|
||||
|
||||
public class GtFunc extends AbstractLogicalFunc implements IFunc{
|
||||
|
||||
@Override
|
||||
public IParam _fx(IParam[] args) {
|
||||
if(args.length != 2) {
|
||||
throw new IllegalArgumentException("GtFunc函数的参数必须是两个");
|
||||
}
|
||||
if(ParamFormat.format(args[0]).doubleValue() > ParamFormat.format(args[1]).doubleValue()) {
|
||||
return _true();
|
||||
}
|
||||
return _false();
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
package org.code.modules.plugins.function.method.logical;
|
||||
|
||||
import org.code.modules.plugins.function.IFunc;
|
||||
import org.code.modules.plugins.function.IParam;
|
||||
import org.code.modules.plugins.function.method.AbstractLogicalFunc;
|
||||
import org.code.modules.plugins.function.param.ParamFormat;
|
||||
|
||||
public class GteFunc extends AbstractLogicalFunc implements IFunc{
|
||||
|
||||
@Override
|
||||
public IParam _fx(IParam[] args) {
|
||||
if(args.length != 2) {
|
||||
throw new IllegalArgumentException("GteFunc函数的参数必须是两个");
|
||||
}
|
||||
if(ParamFormat.format(args[0]).doubleValue() >= ParamFormat.format(args[1]).doubleValue()) {
|
||||
return _true();
|
||||
}
|
||||
return _false();
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
package org.code.modules.plugins.function.method.logical;
|
||||
|
||||
import org.code.modules.plugins.function.IFunc;
|
||||
import org.code.modules.plugins.function.IParam;
|
||||
import org.code.modules.plugins.function.method.AbstractLogicalFunc;
|
||||
import org.code.modules.plugins.function.param.ParamFormat;
|
||||
|
||||
public class IfFunc extends AbstractLogicalFunc implements IFunc{
|
||||
|
||||
@Override
|
||||
public IParam _fx(IParam[] args) {
|
||||
if(args.length <= 1) {
|
||||
throw new IllegalArgumentException("IfFunc函数的参数必须大于一个");
|
||||
}
|
||||
if(ParamFormat.format(args[0]).intValue() != 0){
|
||||
return args[1];
|
||||
}
|
||||
return args[2];
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
package org.code.modules.plugins.function.method.logical;
|
||||
|
||||
import org.code.modules.plugins.function.IFunc;
|
||||
import org.code.modules.plugins.function.IParam;
|
||||
import org.code.modules.plugins.function.method.AbstractLogicalFunc;
|
||||
import org.code.modules.plugins.function.param.ParamFormat;
|
||||
|
||||
public class LtFunc extends AbstractLogicalFunc implements IFunc{
|
||||
|
||||
@Override
|
||||
public IParam _fx(IParam[] args) {
|
||||
if(args.length != 2) {
|
||||
throw new IllegalArgumentException("LtFunc函数的参数必须是两个");
|
||||
}
|
||||
if(ParamFormat.format(args[0]).doubleValue() < ParamFormat.format(args[1]).doubleValue()) {
|
||||
return _true();
|
||||
}
|
||||
return _false();
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
package org.code.modules.plugins.function.method.logical;
|
||||
|
||||
import org.code.modules.plugins.function.IFunc;
|
||||
import org.code.modules.plugins.function.IParam;
|
||||
import org.code.modules.plugins.function.method.AbstractLogicalFunc;
|
||||
import org.code.modules.plugins.function.param.ParamFormat;
|
||||
|
||||
public class LteFunc extends AbstractLogicalFunc implements IFunc{
|
||||
|
||||
@Override
|
||||
public IParam _fx(IParam[] args) {
|
||||
if(args.length != 2) {
|
||||
throw new IllegalArgumentException("LteFunc函数的参数必须是两个");
|
||||
}
|
||||
if(ParamFormat.format(args[0]).doubleValue() <= ParamFormat.format(args[1]).doubleValue()) {
|
||||
return _true();
|
||||
}
|
||||
return _false();
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package org.code.modules.plugins.function.method.logical;
|
||||
|
||||
import org.code.modules.plugins.function.IFunc;
|
||||
import org.code.modules.plugins.function.IParam;
|
||||
import org.code.modules.plugins.function.method.AbstractLogicalFunc;
|
||||
import org.code.modules.plugins.function.param.ParamFormat;
|
||||
import org.code.modules.plugins.function.param.StandTypeParam;
|
||||
|
||||
/**
|
||||
* 逻辑匹配函数
|
||||
* Created by chenzm on 2017/9/18.
|
||||
*/
|
||||
public class MatchFunc extends AbstractLogicalFunc implements IFunc {
|
||||
|
||||
@Override
|
||||
public IParam _fx(IParam[] args) {
|
||||
int length = args.length / 2 * 2;
|
||||
for(int i = 0; i < length; ) {
|
||||
if(ParamFormat.toBoolean(args[i])) {
|
||||
return args[i + 1];
|
||||
}
|
||||
i = i + 2;
|
||||
}
|
||||
return StandTypeParam.createConstantParam("");
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package org.code.modules.plugins.function.method.logical;
|
||||
|
||||
import org.code.modules.plugins.function.IFunc;
|
||||
import org.code.modules.plugins.function.IParam;
|
||||
import org.code.modules.plugins.function.method.AbstractLogicalFunc;
|
||||
import org.code.modules.plugins.function.param.ParamFormat;
|
||||
|
||||
public class NotFunc extends AbstractLogicalFunc implements IFunc{
|
||||
|
||||
@Override
|
||||
public IParam _fx(IParam[] args) {
|
||||
if(args.length != 1) {
|
||||
throw new IllegalArgumentException("NotFunc函数的参数只能有一个");
|
||||
}
|
||||
return ParamFormat.format(args[0]).intValue() == 0 ? _true() : _false();
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package org.code.modules.plugins.function.method.logical;
|
||||
|
||||
import org.code.modules.plugins.function.IFunc;
|
||||
import org.code.modules.plugins.function.IParam;
|
||||
import org.code.modules.plugins.function.method.AbstractLogicalFunc;
|
||||
import org.code.modules.plugins.function.param.ParamFormat;
|
||||
|
||||
public class OrFunc extends AbstractLogicalFunc implements IFunc{
|
||||
|
||||
@Override
|
||||
public IParam _fx(IParam[] args) {
|
||||
for(IParam arg : args) {
|
||||
if(ParamFormat.format(arg).intValue() != 0) {
|
||||
return _true();
|
||||
}
|
||||
}
|
||||
return _false();
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package org.code.modules.plugins.function.method.logical;
|
||||
|
||||
import org.code.modules.plugins.function.IFunc;
|
||||
import org.code.modules.plugins.function.IParam;
|
||||
import org.code.modules.plugins.function.method.AbstractLogicalFunc;
|
||||
|
||||
public class TrueFunc extends AbstractLogicalFunc implements IFunc{
|
||||
|
||||
@Override
|
||||
public IParam _fx(IParam[] args) {
|
||||
if(args.length != 0) {
|
||||
throw new IllegalArgumentException("TrueFunc函数的不能有参数");
|
||||
}
|
||||
return _true();
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package org.code.modules.plugins.function.method.logical;
|
||||
|
||||
import org.code.modules.plugins.function.IFunc;
|
||||
import org.code.modules.plugins.function.IParam;
|
||||
import org.code.modules.plugins.function.method.AbstractLogicalFunc;
|
||||
import org.code.modules.plugins.function.param.ParamFormat;
|
||||
|
||||
public class XorFunc extends AbstractLogicalFunc implements IFunc{
|
||||
@Override
|
||||
public IParam _fx(IParam[] args) {
|
||||
int t = ParamFormat.format(args[0]).intValue();
|
||||
for(int i = 1; i < args.length; i ++) {
|
||||
if( t != ParamFormat.format(args[i]).intValue()) {//不同true
|
||||
t = 1;
|
||||
}else {
|
||||
t = 0;
|
||||
}
|
||||
}
|
||||
return t != 0 ? _true() : _false();
|
||||
}
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
package org.code.modules.plugins.function.method.mathematical;
|
||||
|
||||
|
||||
import com.luqj.util.NumFormat;
|
||||
import org.code.modules.plugins.function.IFunc;
|
||||
import org.code.modules.plugins.function.IParam;
|
||||
import org.code.modules.plugins.function.method.AbstractMathFunc;
|
||||
import org.code.modules.plugins.function.param.StandTypeParam;
|
||||
|
||||
/**
|
||||
* 平均值函数
|
||||
* @author chenzm
|
||||
*/
|
||||
public class AvgFunc extends AbstractMathFunc implements IFunc{
|
||||
|
||||
final Double INIT_VALUE = Double.valueOf(0);
|
||||
|
||||
private StandTypeParam avg = StandTypeParam.createConstantParam(INIT_VALUE);
|
||||
|
||||
@Override
|
||||
public IParam _fx(IParam[] args) {
|
||||
|
||||
if(isReset()) {
|
||||
avg.setVal(INIT_VALUE);
|
||||
}
|
||||
|
||||
Double t = (Double)avg.getVal();
|
||||
for(IParam arg : args) {
|
||||
t += NumFormat.$Double(arg.getVal());
|
||||
}
|
||||
avg.setVal(t * 1.0f / args.length);
|
||||
return avg;
|
||||
}
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
package org.code.modules.plugins.function.method.mathematical;
|
||||
|
||||
import com.luqj.util.ArithmeticEnum;;
|
||||
import com.luqj.util.assertion.Assert;
|
||||
import org.code.modules.plugins.function.IFunc;
|
||||
import org.code.modules.plugins.function.IParam;
|
||||
import org.code.modules.plugins.function.method.AbstractMathFunc;
|
||||
import org.code.modules.plugins.function.param.ParamFormat;
|
||||
import org.code.modules.plugins.function.param.StandTypeParam;
|
||||
|
||||
/**
|
||||
* 数学算式函数(加减乘除)
|
||||
*
|
||||
* @author chenzm
|
||||
*/
|
||||
public class MathFormulaFunc extends AbstractMathFunc implements IFunc {
|
||||
|
||||
protected ArithmeticEnum op;
|
||||
|
||||
private StandTypeParam result = null;
|
||||
|
||||
public MathFormulaFunc(ArithmeticEnum op) {
|
||||
this.op = op;
|
||||
}
|
||||
|
||||
public MathFormulaFunc() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public IParam _fx(IParam[] args) {
|
||||
if (args.length < 2 || args.length > 3) {
|
||||
throw new IllegalArgumentException(op.getDesc() + "函数的参数最多是三个");
|
||||
}
|
||||
if (result == null) {
|
||||
if (this.op == null) {
|
||||
Assert.logic(args.length == 3, "函数的参数必须是三个");
|
||||
this.op = ArithmeticEnum.getArithmeticEnum(ParamFormat.obj2Str(args[2]));
|
||||
Assert.logic(this.op != null, "暂不支持" + ParamFormat.obj2Str(args[2]) + "操作符号");
|
||||
}
|
||||
this.result = super.initStandTypeParam(args);
|
||||
}
|
||||
formulaOp(op, args[0], args[1], result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package org.code.modules.plugins.function.method.mathematical;
|
||||
|
||||
import com.luqj.util.NumFormat;
|
||||
import org.code.modules.plugins.function.IFunc;
|
||||
import org.code.modules.plugins.function.IParam;
|
||||
import org.code.modules.plugins.function.method.AbstractMathFunc;
|
||||
import org.code.modules.plugins.function.param.StandTypeParam;
|
||||
|
||||
public class MaxFunc extends AbstractMathFunc implements IFunc{
|
||||
|
||||
final double INIT_VALUE = Integer.MIN_VALUE * 1.0d;
|
||||
|
||||
private StandTypeParam max = StandTypeParam.createConstantParam(INIT_VALUE);
|
||||
|
||||
@Override
|
||||
public IParam _fx(IParam[] args) {
|
||||
if(isReset()) {
|
||||
max.setVal(INIT_VALUE);
|
||||
}
|
||||
|
||||
Double t = (Double)max.getVal();
|
||||
for(IParam arg : args) {
|
||||
Double val = NumFormat.$Double(arg.getVal());
|
||||
if(t.compareTo(val) < 0) {
|
||||
t = val;
|
||||
}
|
||||
}
|
||||
max.setVal(t);
|
||||
return max;
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package org.code.modules.plugins.function.method.mathematical;
|
||||
|
||||
import com.luqj.util.NumFormat;
|
||||
import org.code.modules.plugins.function.IFunc;
|
||||
import org.code.modules.plugins.function.IParam;
|
||||
import org.code.modules.plugins.function.method.AbstractMathFunc;
|
||||
import org.code.modules.plugins.function.param.StandTypeParam;
|
||||
|
||||
public class MinFunc extends AbstractMathFunc implements IFunc{
|
||||
|
||||
final double INIT_VALUE = Integer.MAX_VALUE * 1.0;
|
||||
|
||||
private StandTypeParam min = StandTypeParam.createConstantParam(INIT_VALUE);
|
||||
|
||||
@Override
|
||||
public IParam _fx(IParam[] args) {
|
||||
if(isReset()) {
|
||||
min.setVal(INIT_VALUE);
|
||||
}
|
||||
|
||||
Double t = (Double)min.getVal();
|
||||
for(IParam arg : args) {
|
||||
Double val = NumFormat.$Double(arg.getVal());
|
||||
if(t.compareTo(val) > 0) {
|
||||
t = val;
|
||||
}
|
||||
}
|
||||
min.setVal(t);
|
||||
return min;
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package org.code.modules.plugins.function.method.mathematical;
|
||||
|
||||
import org.code.modules.plugins.function.IFunc;
|
||||
import org.code.modules.plugins.function.IParam;
|
||||
import org.code.modules.plugins.function.method.AbstractMathFunc;
|
||||
import org.code.modules.plugins.function.param.ParamFormat;
|
||||
import org.code.modules.plugins.function.param.StandTypeParam;
|
||||
import org.code.modules.plugins.types.TypeEnum;
|
||||
|
||||
/**
|
||||
* Created by chenzm on 2017/2/22.
|
||||
*/
|
||||
public class PowFunc extends AbstractMathFunc implements IFunc {
|
||||
|
||||
private StandTypeParam min = StandTypeParam.createParamByType(TypeEnum.Double);
|
||||
|
||||
@Override
|
||||
public IParam _fx(IParam[] args) {
|
||||
if(args.length != 2){
|
||||
throw new IllegalArgumentException("参数必须是一个");
|
||||
}
|
||||
if(ParamFormat.argIsNull(args[0])) {
|
||||
return null;
|
||||
}
|
||||
min.setVal(Math.pow(ParamFormat.format(args[0]).doubleValue(), ParamFormat.format(args[1]).intValue()));
|
||||
return min;
|
||||
}
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
package org.code.modules.plugins.function.method.mathematical;
|
||||
|
||||
import com.luqj.util.NumFormat;
|
||||
import org.code.modules.plugins.function.IFunc;
|
||||
import org.code.modules.plugins.function.IParam;
|
||||
import org.code.modules.plugins.function.method.AbstractMathFunc;
|
||||
import org.code.modules.plugins.function.param.StandTypeParam;
|
||||
|
||||
/**
|
||||
* 求和函数
|
||||
* @author chenzm
|
||||
*/
|
||||
public class SumFunc extends AbstractMathFunc implements IFunc{
|
||||
|
||||
final Double INIT_VALUE = Double.valueOf(0);
|
||||
|
||||
private StandTypeParam sum = StandTypeParam.createConstantParam(INIT_VALUE);
|
||||
|
||||
@Override
|
||||
public IParam _fx(IParam[] args) {
|
||||
|
||||
if(isReset()) {
|
||||
sum.setVal(INIT_VALUE);
|
||||
}
|
||||
|
||||
Double t = (Double)sum.getVal();
|
||||
for(IParam arg : args) {
|
||||
t += NumFormat.$Double(arg.getVal());
|
||||
}
|
||||
sum.setVal(t);
|
||||
return sum;
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package org.code.modules.plugins.function.method.mathematical.dataset;
|
||||
|
||||
import org.code.modules.plugins.function.IFunc;
|
||||
import org.code.modules.plugins.function.IParam;
|
||||
import org.code.modules.plugins.function.method.AbstractMathFunc;
|
||||
import org.code.modules.plugins.function.param.StandTypeParam;
|
||||
import com.luqj.util.NumFormat;
|
||||
|
||||
/**
|
||||
* 平均值函数
|
||||
* Created by lucheng on 2017/8/29.
|
||||
*/
|
||||
public class RAvgFunc extends AbstractMathFunc implements IFunc {
|
||||
|
||||
final Double INIT_VALUE = Double.valueOf(0);
|
||||
|
||||
private StandTypeParam avg = StandTypeParam.createConstantParam(INIT_VALUE);
|
||||
|
||||
private Integer count = 0;
|
||||
|
||||
private Double sum = Double.valueOf(0);
|
||||
|
||||
@Override
|
||||
public IParam _fx(IParam[] args) {
|
||||
count++;
|
||||
for (IParam arg : args) {
|
||||
sum += NumFormat.$Double(arg.getVal());
|
||||
}
|
||||
double value = (double) Math.round(sum * 100 / count) / 100;
|
||||
avg.setVal(value);
|
||||
return avg;
|
||||
}
|
||||
|
||||
public Double getAvgValue() {
|
||||
return (Double) avg.getVal();
|
||||
}
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
package org.code.modules.plugins.function.method.mathematical.dataset;
|
||||
|
||||
|
||||
import com.luqj.util.MapSortUtil;
|
||||
import com.luqj.util.NumFormat;
|
||||
import org.code.modules.plugins.function.IFunc;
|
||||
import org.code.modules.plugins.function.IParam;
|
||||
import org.code.modules.plugins.function.method.AbstractMathFunc;
|
||||
import org.code.modules.plugins.function.param.StandTypeParam;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 众数函数
|
||||
* Created by lucheng on 2017/8/29.
|
||||
*/
|
||||
public class RMassFunc extends AbstractMathFunc implements IFunc {
|
||||
|
||||
private Map<Double, Integer> valMap = new HashMap<Double, Integer>();
|
||||
|
||||
private StandTypeParam mass = StandTypeParam.createConstantParam(new Double("0"));
|
||||
|
||||
@Override
|
||||
public IParam _fx(IParam[] args) {
|
||||
for (IParam arg : args) {
|
||||
Double val = NumFormat.$Double(arg.getVal());
|
||||
valMap.put(val, valMap.get(val) == null ? 1 : (valMap.get(val) + 1));
|
||||
}
|
||||
Map<Double, Integer> valueMap = MapSortUtil.sortMapByValue(valMap, "DESC");
|
||||
Double massValue = valueMap.entrySet().iterator().next().getKey(); // 众数
|
||||
mass.setVal(massValue);
|
||||
return mass;
|
||||
}
|
||||
|
||||
public Double getMassValue() {
|
||||
return (Double) mass.getVal();
|
||||
}
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
package org.code.modules.plugins.function.method.mathematical.dataset;
|
||||
|
||||
import com.luqj.util.NumFormat;
|
||||
import org.code.modules.plugins.function.IFunc;
|
||||
import org.code.modules.plugins.function.IParam;
|
||||
import org.code.modules.plugins.function.method.AbstractMathFunc;
|
||||
import org.code.modules.plugins.function.param.StandTypeParam;
|
||||
|
||||
/**
|
||||
* 最大值函数
|
||||
* Created by lucheng on 2017/8/28.
|
||||
*/
|
||||
public class RMaxFunc extends AbstractMathFunc implements IFunc {
|
||||
|
||||
final double INIT_VALUE = Double.MIN_VALUE;
|
||||
|
||||
private StandTypeParam max = StandTypeParam.createConstantParam(INIT_VALUE);
|
||||
|
||||
@Override
|
||||
public IParam _fx(IParam[] args) {
|
||||
Double t = (Double) max.getVal();
|
||||
for (IParam arg : args) {
|
||||
Double val = NumFormat.$Double(arg.getVal());
|
||||
if (t.compareTo(val) < 0) {
|
||||
t = val;
|
||||
}
|
||||
}
|
||||
max.setVal(t);
|
||||
return max;
|
||||
}
|
||||
|
||||
public Double getMaxValue() {
|
||||
return (Double) max.getVal();
|
||||
}
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
package org.code.modules.plugins.function.method.mathematical.dataset;
|
||||
|
||||
import org.code.modules.plugins.function.IFunc;
|
||||
import org.code.modules.plugins.function.IParam;
|
||||
import org.code.modules.plugins.function.method.AbstractMathFunc;
|
||||
import org.code.modules.plugins.function.param.StandTypeParam;
|
||||
|
||||
/**
|
||||
* 最长值函数
|
||||
* Created by lucheng on 2017/8/29.
|
||||
*/
|
||||
public class RMaxLengthFunc extends AbstractMathFunc implements IFunc {
|
||||
|
||||
final int INIT_VALUE = Integer.MIN_VALUE;
|
||||
|
||||
private StandTypeParam maxLength = StandTypeParam.createConstantParam(INIT_VALUE);
|
||||
|
||||
@Override
|
||||
public IParam _fx(IParam[] args) {
|
||||
Integer t = (Integer) maxLength.getVal();
|
||||
for (IParam arg : args) {
|
||||
Integer val = arg.getVal().toString().length();
|
||||
if (t.compareTo(val) < 0) {
|
||||
t = val;
|
||||
}
|
||||
}
|
||||
maxLength.setVal(t);
|
||||
return maxLength;
|
||||
}
|
||||
|
||||
public Integer getMaxLengthValue() {
|
||||
return (Integer) maxLength.getVal();
|
||||
}
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
package org.code.modules.plugins.function.method.mathematical.dataset;
|
||||
|
||||
import com.luqj.util.MapSortUtil;
|
||||
import com.luqj.util.NumFormat;
|
||||
import org.code.modules.plugins.function.IFunc;
|
||||
import org.code.modules.plugins.function.IParam;
|
||||
import org.code.modules.plugins.function.method.AbstractMathFunc;
|
||||
import org.code.modules.plugins.function.param.StandTypeParam;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
/**
|
||||
* 中位数函数
|
||||
* Created by lucheng on 2017/8/31.
|
||||
*/
|
||||
public class RMidValueFunc extends AbstractMathFunc implements IFunc {
|
||||
|
||||
private Map<Double, Integer> valMap = new HashMap<Double, Integer>();
|
||||
|
||||
private StandTypeParam midVal = StandTypeParam.createConstantParam(new Double("0"));
|
||||
|
||||
private Integer count = 0;
|
||||
|
||||
@Override
|
||||
public IParam _fx(IParam[] args) {
|
||||
count++;
|
||||
for (IParam arg : args) {
|
||||
Double val = NumFormat.$Double(arg.getVal());
|
||||
valMap.put(val, valMap.get(val) == null ? 1 : (valMap.get(val) + 1));
|
||||
}
|
||||
|
||||
Integer pos1 = null, pos2 = null;
|
||||
if (count % 2 == 0) { // 偶数个
|
||||
pos1 = count / 2;
|
||||
pos2 = count / 2 + 1;
|
||||
} else { // 奇数个
|
||||
pos1 = count / 2 + 1;
|
||||
}
|
||||
// key从小到大排序
|
||||
TreeMap<Double, Integer> newRange = MapSortUtil.sortMapByKey(valMap, "ASC");
|
||||
Integer sumCount = 0;
|
||||
Double middleValue = null; //中位数
|
||||
for (Map.Entry<Double, Integer> newEntry : newRange.entrySet()) {
|
||||
// Double number = newEntry.getKey();
|
||||
Integer count = newEntry.getValue();
|
||||
sumCount += count;
|
||||
}
|
||||
if (pos2 == null && pos1 <= sumCount) { // 奇数个
|
||||
Double number = MapSortUtil.getKeyByIndex(newRange, pos1);
|
||||
middleValue = new Double(number);
|
||||
} else {
|
||||
Double number1 = MapSortUtil.getKeyByIndex(newRange, pos1);
|
||||
Double number2 = MapSortUtil.getKeyByIndex(newRange, pos2);
|
||||
middleValue = new Double((number1 + number2) / 2);
|
||||
}
|
||||
midVal.setVal(middleValue);
|
||||
return midVal;
|
||||
}
|
||||
|
||||
public Double getMidValue() {
|
||||
return (Double) midVal.getVal();
|
||||
}
|
||||
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
package org.code.modules.plugins.function.method.mathematical.dataset;
|
||||
|
||||
import com.luqj.util.NumFormat;
|
||||
import org.code.modules.plugins.function.IFunc;
|
||||
import org.code.modules.plugins.function.IParam;
|
||||
import org.code.modules.plugins.function.method.AbstractMathFunc;
|
||||
import org.code.modules.plugins.function.param.StandTypeParam;
|
||||
|
||||
/**
|
||||
* 最小值函数
|
||||
* Created by lucheng on 2017/8/29.
|
||||
*/
|
||||
public class RMinFunc extends AbstractMathFunc implements IFunc {
|
||||
|
||||
final double INIT_VALUE = Double.MAX_VALUE;
|
||||
|
||||
private StandTypeParam min = StandTypeParam.createConstantParam(INIT_VALUE);
|
||||
|
||||
@Override
|
||||
public IParam _fx(IParam[] args) {
|
||||
Double t = (Double) min.getVal();
|
||||
for (IParam arg : args) {
|
||||
Double val = NumFormat.$Double(arg.getVal());
|
||||
if (t.compareTo(val) > 0) {
|
||||
t = val;
|
||||
}
|
||||
}
|
||||
min.setVal(t);
|
||||
return min;
|
||||
}
|
||||
|
||||
public Double getMinValue() {
|
||||
return (Double) min.getVal();
|
||||
}
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
package org.code.modules.plugins.function.method.mathematical.dataset;
|
||||
|
||||
import org.code.modules.plugins.function.IFunc;
|
||||
import org.code.modules.plugins.function.IParam;
|
||||
import org.code.modules.plugins.function.method.AbstractMathFunc;
|
||||
import org.code.modules.plugins.function.param.StandTypeParam;
|
||||
|
||||
/**
|
||||
* 最短值函数
|
||||
* Created by lucheng on 2017/8/29.
|
||||
*/
|
||||
public class RMinLengthFunc extends AbstractMathFunc implements IFunc {
|
||||
|
||||
final int INIT_VALUE = Integer.MAX_VALUE;
|
||||
|
||||
private StandTypeParam minLength = StandTypeParam.createConstantParam(INIT_VALUE);
|
||||
|
||||
@Override
|
||||
public IParam _fx(IParam[] args) {
|
||||
Integer t = (Integer) minLength.getVal();
|
||||
for (IParam arg : args) {
|
||||
Integer val = arg.getVal().toString().length();
|
||||
if (t.compareTo(val) > 0) {
|
||||
t = val;
|
||||
}
|
||||
}
|
||||
minLength.setVal(t);
|
||||
return minLength;
|
||||
}
|
||||
|
||||
public Integer getMinLengthValue() {
|
||||
return (Integer) minLength.getVal();
|
||||
}
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
package org.code.modules.plugins.function.method.mathematical.dataset;
|
||||
|
||||
import com.luqj.util.MapSortUtil;
|
||||
import com.luqj.util.NumFormat;
|
||||
import org.code.modules.plugins.function.IFunc;
|
||||
import org.code.modules.plugins.function.IParam;
|
||||
import org.code.modules.plugins.function.method.AbstractMathFunc;
|
||||
import org.code.modules.plugins.function.param.StandTypeParam;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
/**
|
||||
* 四分位数q3
|
||||
* Created by lucheng on 2017/8/31.
|
||||
*/
|
||||
public class RQtr3Func extends AbstractMathFunc implements IFunc {
|
||||
|
||||
private Map<Double, Integer> valMap = new HashMap<Double, Integer>();
|
||||
|
||||
private StandTypeParam qtr3 = StandTypeParam.createConstantParam(new Double("0"));
|
||||
|
||||
private Integer count = 0;
|
||||
|
||||
@Override
|
||||
public IParam _fx(IParam[] args) {
|
||||
count++;
|
||||
for (IParam arg : args) {
|
||||
Double val = NumFormat.$Double(arg.getVal());
|
||||
valMap.put(val, valMap.get(val) == null ? 1 : (valMap.get(val) + 1));
|
||||
}
|
||||
TreeMap<Double, Integer> newRange = MapSortUtil.sortMapByKey(valMap, "ASC");
|
||||
|
||||
double p3 = 3 * (count + 1) / 4;
|
||||
if (p3 < 1) {
|
||||
p3 = 1;
|
||||
}
|
||||
int d3 = (int) p3;
|
||||
double f3 = MapSortUtil.getKeyByIndex(newRange, d3);
|
||||
double a3 = count >= (d3 + 1) ? MapSortUtil.getKeyByIndex(newRange, d3 + 1) : 0;
|
||||
double q3 = f3 * (1 - (p3 - d3)) + a3 * (p3 - d3);
|
||||
|
||||
qtr3.setVal(q3);
|
||||
return qtr3;
|
||||
}
|
||||
|
||||
public Double getQtr3Value() {
|
||||
return (Double) qtr3.getVal();
|
||||
}
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
package org.code.modules.plugins.function.method.mathematical.dataset;
|
||||
|
||||
import com.luqj.util.MapSortUtil;
|
||||
import com.luqj.util.NumFormat;
|
||||
import org.code.modules.plugins.function.IFunc;
|
||||
import org.code.modules.plugins.function.IParam;
|
||||
import org.code.modules.plugins.function.method.AbstractMathFunc;
|
||||
import org.code.modules.plugins.function.param.StandTypeParam;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
/**
|
||||
* 四分位数q1
|
||||
* Created by lucheng on 2017/8/31.
|
||||
*/
|
||||
public class RQtrFunc extends AbstractMathFunc implements IFunc {
|
||||
|
||||
private Map<Double, Integer> valMap = new HashMap<Double, Integer>();
|
||||
|
||||
private StandTypeParam qtr = StandTypeParam.createConstantParam(new Double("0"));
|
||||
|
||||
private Integer count = 0;
|
||||
|
||||
@Override
|
||||
public IParam _fx(IParam[] args) {
|
||||
count++;
|
||||
for (IParam arg : args) {
|
||||
Double val = NumFormat.$Double(arg.getVal());
|
||||
valMap.put(val, valMap.get(val) == null ? 1 : (valMap.get(val) + 1));
|
||||
}
|
||||
TreeMap<Double, Integer> newRange = MapSortUtil.sortMapByKey(valMap, "ASC");
|
||||
|
||||
double p1 = (count + 1) / 4;
|
||||
if (p1 < 1) {
|
||||
p1 = 1;
|
||||
}
|
||||
int d1 = (int) p1; // 向下取整
|
||||
double f1 = MapSortUtil.getKeyByIndex(newRange, d1);
|
||||
double a1 = count >= (d1 + 1) ? MapSortUtil.getKeyByIndex(newRange, d1 + 1) : 0;
|
||||
double q1 = f1 * (1 - (p1 - d1)) + a1 * (p1 - d1);
|
||||
|
||||
qtr.setVal(q1);
|
||||
return qtr;
|
||||
}
|
||||
|
||||
public Double getQtrValue() {
|
||||
return (Double) qtr.getVal();
|
||||
}
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
package org.code.modules.plugins.function.method.mathematical.dataset;
|
||||
|
||||
import com.luqj.util.MapSortUtil;
|
||||
import com.luqj.util.NumFormat;
|
||||
import org.code.modules.plugins.function.IFunc;
|
||||
import org.code.modules.plugins.function.IParam;
|
||||
import org.code.modules.plugins.function.method.AbstractMathFunc;
|
||||
import org.code.modules.plugins.function.param.StandTypeParam;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
/**
|
||||
* 四分位数极差函数
|
||||
* Created by lucheng on 2017/8/31.
|
||||
*/
|
||||
public class RQtrMinusFunc extends AbstractMathFunc implements IFunc {
|
||||
|
||||
private Map<Double, Integer> valMap = new HashMap<Double, Integer>();
|
||||
|
||||
private StandTypeParam qtrMinus = StandTypeParam.createConstantParam(new Double("0"));
|
||||
|
||||
private Integer count = 0;
|
||||
|
||||
@Override
|
||||
public IParam _fx(IParam[] args) {
|
||||
count++;
|
||||
for (IParam arg : args) {
|
||||
Double val = NumFormat.$Double(arg.getVal());
|
||||
valMap.put(val, valMap.get(val) == null ? 1 : (valMap.get(val) + 1));
|
||||
}
|
||||
TreeMap<Double, Integer> newRange = MapSortUtil.sortMapByKey(valMap, "ASC");
|
||||
|
||||
double p1 = (count + 1) / 4;
|
||||
if (p1 < 1) {
|
||||
p1 = 1;
|
||||
}
|
||||
int d1 = (int) p1; // 向下取整
|
||||
double f1 = MapSortUtil.getKeyByIndex(newRange, d1);
|
||||
double a1 = count >= (d1 + 1) ? MapSortUtil.getKeyByIndex(newRange, d1 + 1) : 0;
|
||||
double q1 = f1 * (1 - (p1 - d1)) + a1 * (p1 - d1);
|
||||
|
||||
double p3 = 3 * (count + 1) / 4;
|
||||
if (p3 < 1) {
|
||||
p3 = 1;
|
||||
}
|
||||
int d3 = (int) p3;
|
||||
double f3 = MapSortUtil.getKeyByIndex(newRange, d3);
|
||||
double a3 = count >= (d3 + 1) ? MapSortUtil.getKeyByIndex(newRange, d3 + 1) : 0;
|
||||
double q3 = f3 * (1 - (p3 - d3)) + a3 * (p3 - d3);
|
||||
|
||||
// 四分位数极差
|
||||
double qMinus = q3 - q1;
|
||||
qtrMinus.setVal(qMinus);
|
||||
return qtrMinus;
|
||||
}
|
||||
|
||||
public Double getQtrMinus() {
|
||||
return (Double) qtrMinus.getVal();
|
||||
}
|
||||
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
package org.code.modules.plugins.function.method.mathematical.dataset;
|
||||
|
||||
import com.luqj.util.NumFormat;
|
||||
import org.code.modules.plugins.function.IFunc;
|
||||
import org.code.modules.plugins.function.IParam;
|
||||
import org.code.modules.plugins.function.method.AbstractMathFunc;
|
||||
import org.code.modules.plugins.function.param.StandTypeParam;
|
||||
|
||||
/**
|
||||
* 极差函数
|
||||
* Created by lucheng on 2017/8/29.
|
||||
*/
|
||||
public class RRangeFunc extends AbstractMathFunc implements IFunc {
|
||||
|
||||
|
||||
private StandTypeParam max = StandTypeParam.createConstantParam(Double.MIN_VALUE);
|
||||
|
||||
private StandTypeParam min = StandTypeParam.createConstantParam(Double.MAX_VALUE);
|
||||
|
||||
private StandTypeParam range = StandTypeParam.createConstantParam(new Double("0"));
|
||||
|
||||
@Override
|
||||
public IParam _fx(IParam[] args) {
|
||||
Double tMax = (Double) max.getVal();
|
||||
Double tMin = (Double) min.getVal();
|
||||
for (IParam arg : args) {
|
||||
Double val = NumFormat.$Double(arg.getVal());
|
||||
if (tMax.compareTo(val) < 0) {
|
||||
tMax = val;
|
||||
}
|
||||
if (tMin.compareTo(val) > 0) {
|
||||
tMin = val;
|
||||
}
|
||||
}
|
||||
max.setVal(tMax);
|
||||
min.setVal(tMin);
|
||||
Double rangeVal = (Double) max.getVal() - (Double) min.getVal();
|
||||
range.setVal(rangeVal);
|
||||
return range;
|
||||
}
|
||||
|
||||
public Double getRangeValue() {
|
||||
return (Double) range.getVal();
|
||||
}
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
package org.code.modules.plugins.function.method.mathematical.dataset;
|
||||
|
||||
import com.luqj.util.NumFormat;
|
||||
import org.code.modules.plugins.function.IFunc;
|
||||
import org.code.modules.plugins.function.IParam;
|
||||
import org.code.modules.plugins.function.method.AbstractMathFunc;
|
||||
import org.code.modules.plugins.function.param.StandTypeParam;
|
||||
|
||||
/**
|
||||
* 标准差公式
|
||||
* Created by lucheng on 2017/8/29.
|
||||
*/
|
||||
public class RStdDevFunc extends AbstractMathFunc implements IFunc {
|
||||
|
||||
final Double INIT_VALUE = Double.valueOf(0);
|
||||
|
||||
private StandTypeParam sum = StandTypeParam.createConstantParam(INIT_VALUE);
|
||||
|
||||
private StandTypeParam sum2 = StandTypeParam.createConstantParam(INIT_VALUE);
|
||||
|
||||
private StandTypeParam variance = StandTypeParam.createConstantParam(INIT_VALUE);
|
||||
|
||||
private Integer count = 0;
|
||||
|
||||
@Override
|
||||
public IParam _fx(IParam[] args) {
|
||||
count++;
|
||||
Double s = (Double) sum.getVal();
|
||||
Double s2 = (Double) sum2.getVal();
|
||||
for (IParam arg : args) {
|
||||
s += NumFormat.$Double(arg.getVal());
|
||||
s2 += (NumFormat.$Double(arg.getVal()) * NumFormat.$Double(arg.getVal()));
|
||||
}
|
||||
Double avgValue = s * 1.0f / count;
|
||||
Double var = s2 / count - avgValue * avgValue;
|
||||
sum.setVal(s);
|
||||
sum2.setVal(s2);
|
||||
variance.setVal(var);
|
||||
return variance;
|
||||
}
|
||||
|
||||
public Double getStdDevValue() {
|
||||
double var = (double) variance.getVal();
|
||||
double sqrt = Math.sqrt(var);
|
||||
return (double) Math.round(sqrt * 100) / 100;
|
||||
}
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
package org.code.modules.plugins.function.method.mathematical.dataset;
|
||||
|
||||
import com.luqj.util.NumFormat;
|
||||
import org.code.modules.plugins.function.IFunc;
|
||||
import org.code.modules.plugins.function.IParam;
|
||||
import org.code.modules.plugins.function.method.AbstractMathFunc;
|
||||
import org.code.modules.plugins.function.param.SimpleIteratorParam;
|
||||
import org.code.modules.plugins.function.param.StandardMutlValTypeParam;
|
||||
import org.code.modules.plugins.types.MapType;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 值分布函数
|
||||
* Created by lucheng on 2017/8/29.
|
||||
*/
|
||||
public class RValueRangeFunc extends AbstractMathFunc implements IFunc {
|
||||
|
||||
private Map<Double, Integer> valMap = new HashMap<Double, Integer>();
|
||||
|
||||
private StandardMutlValTypeParam param = null;
|
||||
|
||||
public RValueRangeFunc() {
|
||||
param = new SimpleIteratorParam(new MapType(Integer.class), valMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IParam _fx(IParam[] args) {
|
||||
for (IParam arg : args) {
|
||||
Double val = NumFormat.$Double(arg.getVal());
|
||||
valMap.put(val, valMap.get(val) == null ? 1 : (valMap.get(val) + 1));
|
||||
}
|
||||
return param;
|
||||
}
|
||||
|
||||
public Map<Double, Integer> getRangeMap() {
|
||||
return (Map<Double, Integer>) param.getVal();
|
||||
}
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
package org.code.modules.plugins.function.method.mathematical.dataset;
|
||||
|
||||
import com.luqj.util.NumFormat;
|
||||
import org.code.modules.plugins.function.IFunc;
|
||||
import org.code.modules.plugins.function.IParam;
|
||||
import org.code.modules.plugins.function.method.AbstractMathFunc;
|
||||
import org.code.modules.plugins.function.param.StandTypeParam;
|
||||
|
||||
/**
|
||||
* 方差公式
|
||||
* Created by lucheng on 2017/8/29.
|
||||
*/
|
||||
public class RVarianceFunc extends AbstractMathFunc implements IFunc {
|
||||
|
||||
final Double INIT_VALUE = Double.valueOf(0);
|
||||
|
||||
private StandTypeParam sum = StandTypeParam.createConstantParam(INIT_VALUE);
|
||||
|
||||
private StandTypeParam sum2 = StandTypeParam.createConstantParam(INIT_VALUE);
|
||||
|
||||
private StandTypeParam variance = StandTypeParam.createConstantParam(INIT_VALUE);
|
||||
|
||||
private Integer count = 0;
|
||||
|
||||
@Override
|
||||
public IParam _fx(IParam[] args) {
|
||||
count++;
|
||||
Double s = (Double) sum.getVal();
|
||||
Double s2 = (Double) sum2.getVal();
|
||||
for (IParam arg : args) {
|
||||
s += NumFormat.$Double(arg.getVal());
|
||||
s2 += (NumFormat.$Double(arg.getVal()) * NumFormat.$Double(arg.getVal()));
|
||||
}
|
||||
Double avgValue = s * 1.0f / count;
|
||||
Double var = s2 / count - avgValue * avgValue;
|
||||
sum.setVal(s);
|
||||
sum2.setVal(s2);
|
||||
variance.setVal(var);
|
||||
return variance;
|
||||
}
|
||||
|
||||
public Double getVarianceValue() {
|
||||
double var = (double) variance.getVal();
|
||||
return (double) Math.round(var * 100) / 100;
|
||||
}
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
package org.code.modules.plugins.function.method.series;
|
||||
|
||||
import org.code.modules.plugins.function.IExpression;
|
||||
import org.code.modules.plugins.function.IExpressionContext;
|
||||
import org.code.modules.plugins.function.IFunc;
|
||||
import org.code.modules.plugins.function.IParam;
|
||||
import org.code.modules.plugins.function.cache.FreqSeriesRolling;
|
||||
import org.code.modules.plugins.function.cache.IRollingCaching;
|
||||
import org.code.modules.plugins.function.expression.DefaultExpressionContext;
|
||||
import org.code.modules.plugins.function.param.ParamFormat;
|
||||
import org.code.modules.plugins.function.param.StandTypeParam;
|
||||
import org.code.modules.plugins.function.parse.ExpressionParse;
|
||||
import org.code.modules.plugins.types.TypeEnum;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by liwei on 2017/9/20.
|
||||
*/
|
||||
public class SeriesFreq implements IFunc {
|
||||
|
||||
|
||||
private FreqSeriesRolling<Double,Double> cachingRolling;
|
||||
private StandTypeParam result = StandTypeParam.createParamByType(TypeEnum.Double);
|
||||
private IExpression expression;
|
||||
private IExpressionContext cxt;
|
||||
|
||||
IRollingCaching.IRollingApply<Double,Long,Double> apply = new IRollingCaching.IRollingApply<Double,Long,Double> () {
|
||||
@Override
|
||||
public Double apply(String key, Map<Double, Long> val) {
|
||||
double result2 = 0;
|
||||
for (Double v : val.keySet()){
|
||||
cxt.setExpressionData("VAL" ,v);
|
||||
result2 = ParamFormat.format(expression.execExpression(cxt)).doubleValue();
|
||||
}
|
||||
return result2;
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public IParam fx(IParam... args) {
|
||||
if(expression != null){
|
||||
String exp = ParamFormat.obj2Str(args[2]);
|
||||
expression = ExpressionParse.createDefaultParse().parseExpression(exp);
|
||||
cxt = new DefaultExpressionContext();
|
||||
}
|
||||
result.setVal(cachingRolling.rollingBefore(ParamFormat.obj2Str(args[0]),ParamFormat.format(args[1]).doubleValue(),apply,true)); ;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package org.code.modules.plugins.function.method.text;
|
||||
|
||||
|
||||
import org.code.modules.plugins.function.IFunc;
|
||||
import org.code.modules.plugins.function.IParam;
|
||||
import org.code.modules.plugins.function.method.AbstractTextFunc;
|
||||
import org.code.modules.plugins.function.param.ParamFormat;
|
||||
import org.code.modules.plugins.function.param.StandTypeParam;
|
||||
import org.code.modules.plugins.types.TypeEnum;
|
||||
|
||||
public class ConcatFunc extends AbstractTextFunc implements IFunc{
|
||||
private StandTypeParam result = StandTypeParam.createParamByType(TypeEnum.String);
|
||||
|
||||
private StringBuilder builder = new StringBuilder();
|
||||
|
||||
@Override
|
||||
public IParam _fx(IParam[] args) {
|
||||
if(builder.length() > 0)
|
||||
builder.delete(0, builder.length());
|
||||
for(IParam arg : args) {
|
||||
builder.append(ParamFormat.obj2Str(arg));
|
||||
}
|
||||
result.setVal(builder.toString());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package org.code.modules.plugins.function.method.text;
|
||||
|
||||
import org.code.modules.plugins.function.IFunc;
|
||||
import org.code.modules.plugins.function.IParam;
|
||||
import org.code.modules.plugins.function.method.AbstractTextFunc;
|
||||
import org.code.modules.plugins.function.param.ParamFormat;
|
||||
import org.code.modules.plugins.function.param.StandTypeParam;
|
||||
import org.code.modules.plugins.types.TypeEnum;
|
||||
|
||||
public class ExactFunc extends AbstractTextFunc implements IFunc{
|
||||
private StandTypeParam result = StandTypeParam.createParamByType(TypeEnum.Boolean);
|
||||
|
||||
@Override
|
||||
public IParam _fx(IParam[] args) {
|
||||
if(args.length != 2) {
|
||||
throw new IllegalArgumentException("EXACT函数参数必须是两个");
|
||||
}
|
||||
result.setVal(ParamFormat.isEqual(args[0], args[1]));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package org.code.modules.plugins.function.method.text;
|
||||
|
||||
import org.code.modules.plugins.function.IFunc;
|
||||
import org.code.modules.plugins.function.IParam;
|
||||
import org.code.modules.plugins.function.method.AbstractTextFunc;
|
||||
import org.code.modules.plugins.function.param.ParamFormat;
|
||||
import org.code.modules.plugins.function.param.StandTypeParam;
|
||||
import org.code.modules.plugins.types.TypeEnum;
|
||||
|
||||
public class FindFunc extends AbstractTextFunc implements IFunc{
|
||||
private StandTypeParam result = StandTypeParam.createParamByType(TypeEnum.Integer);
|
||||
|
||||
@Override
|
||||
public IParam _fx(IParam[] args) {
|
||||
if(args.length != 2) {
|
||||
throw new IllegalArgumentException("FindFunc函数参数有且只有两个参数");
|
||||
}
|
||||
if(!ParamFormat.argIsNull(args[0]) ) {
|
||||
result.setVal(ParamFormat.obj2Str(args[0]).indexOf(ParamFormat.obj2Str(args[1])));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
package org.code.modules.plugins.function.method.text;
|
||||
|
||||
import org.code.modules.plugins.function.IFunc;
|
||||
import org.code.modules.plugins.function.IParam;
|
||||
import org.code.modules.plugins.function.method.AbstractTextFunc;
|
||||
import org.code.modules.plugins.function.param.ParamFormat;
|
||||
import org.code.modules.plugins.function.param.SimpleIteratorParam;
|
||||
import org.code.modules.plugins.function.param.StandardMutlValTypeParam;
|
||||
import org.code.modules.plugins.types.MapType;
|
||||
import net.sf.json.JSONObject;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* JSON函数解析
|
||||
*/
|
||||
public class JsonParseFunc extends AbstractTextFunc implements IFunc{
|
||||
private Map<String, Object> valMap = new HashMap<String, Object>();
|
||||
|
||||
private StandardMutlValTypeParam param = null;
|
||||
|
||||
public JsonParseFunc() {
|
||||
param = new SimpleIteratorParam(new MapType(Object.class), valMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IParam _fx(IParam[] args) {
|
||||
if(ParamFormat.argIsNull(args[0])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
//clear data
|
||||
this.valMap.clear();
|
||||
|
||||
JSONObject jsonObj = null;
|
||||
try {
|
||||
jsonObj = JSONObject.fromObject(ParamFormat.obj2Str(args[0]));
|
||||
}catch (Exception e) {
|
||||
throw new IllegalStateException("[" + ParamFormat.obj2Str(args[0]) + "]数据解析异常", e);
|
||||
}
|
||||
|
||||
for(int i = 1; i < args.length; i++) {
|
||||
String key = ParamFormat.obj2Str(args[i]);
|
||||
valMap.put(key, getObj(jsonObj, key));
|
||||
}
|
||||
return param;
|
||||
}
|
||||
|
||||
private Object getObj(JSONObject jsonObj, String name) {
|
||||
if(name.contains(".")) {
|
||||
String[] objProperties = name.split("\\.");
|
||||
JSONObject temp = jsonObj;
|
||||
for(int i = 0; i < objProperties.length - 1; i++) {
|
||||
temp = temp.getJSONObject(objProperties[i]);
|
||||
}
|
||||
return temp.get(objProperties[objProperties.length - 1]).toString();
|
||||
}else {
|
||||
return jsonObj.get(name).toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package org.code.modules.plugins.function.method.text;
|
||||
|
||||
import org.code.modules.plugins.function.IFunc;
|
||||
import org.code.modules.plugins.function.IParam;
|
||||
import org.code.modules.plugins.function.method.AbstractTextFunc;
|
||||
import org.code.modules.plugins.function.param.ParamFormat;
|
||||
import org.code.modules.plugins.function.param.StandTypeParam;
|
||||
import org.code.modules.plugins.types.TypeEnum;
|
||||
|
||||
public class LenFunc extends AbstractTextFunc implements IFunc{
|
||||
private StandTypeParam result = StandTypeParam.createParamByType(TypeEnum.Integer);
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public IParam _fx(IParam[] args) {
|
||||
if(args.length != 1) {
|
||||
throw new IllegalArgumentException("Len函数参数只能有一个");
|
||||
}
|
||||
if(!ParamFormat.argIsNull(args[0])) {
|
||||
result.setVal(ParamFormat.obj2Str(args[0]).length());
|
||||
}else {
|
||||
result.setVal(0);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package org.code.modules.plugins.function.method.text;
|
||||
|
||||
import org.code.modules.plugins.function.IFunc;
|
||||
import org.code.modules.plugins.function.IParam;
|
||||
import org.code.modules.plugins.function.method.AbstractTextFunc;
|
||||
import org.code.modules.plugins.function.param.ParamFormat;
|
||||
import org.code.modules.plugins.function.param.StandTypeParam;
|
||||
import org.code.modules.plugins.types.TypeEnum;
|
||||
|
||||
public class LowerFunc extends AbstractTextFunc implements IFunc{
|
||||
private StandTypeParam result = StandTypeParam.createParamByType(TypeEnum.String);
|
||||
|
||||
@Override
|
||||
public IParam _fx(IParam[] args) {
|
||||
if(args.length != 1) {
|
||||
throw new IllegalArgumentException("LOWER函数参数只能有一个");
|
||||
}
|
||||
if(!ParamFormat.argIsNull(args[0])) {
|
||||
result.setVal(ParamFormat.obj2Str(args[0]).toLowerCase());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
package org.code.modules.plugins.function.method.text;
|
||||
|
||||
import com.luqj.util.NumFormat;
|
||||
import org.code.modules.plugins.function.IFunc;
|
||||
import org.code.modules.plugins.function.IParam;
|
||||
import org.code.modules.plugins.function.method.AbstractTextFunc;
|
||||
import org.code.modules.plugins.function.param.ParamFormat;
|
||||
import org.code.modules.plugins.function.param.StandTypeParam;
|
||||
import org.code.modules.plugins.types.TypeEnum;
|
||||
|
||||
public class ReplaceFunc extends AbstractTextFunc implements IFunc{
|
||||
private StandTypeParam result = null;
|
||||
|
||||
int type = 0;
|
||||
|
||||
@Override
|
||||
public IParam _fx(IParam[] args) {
|
||||
if(args.length < 3 || args.length > 4) {
|
||||
throw new IllegalArgumentException("REPLACE函数参数必须是大于等于三个");
|
||||
}
|
||||
|
||||
if(result == null) {
|
||||
result = StandTypeParam.createParamByType(TypeEnum.String);
|
||||
if(args.length == 4) {
|
||||
type = NumFormat.$Intger(args[3]);
|
||||
}
|
||||
}
|
||||
|
||||
if(args[0].getVal() != null) {
|
||||
switch(type) {
|
||||
case 0:
|
||||
result.setVal(ParamFormat.obj2Str(args[0]).replaceAll(ParamFormat.obj2Str(args[1]), ParamFormat.obj2Str(args[2])));
|
||||
break;
|
||||
case 1:
|
||||
result.setVal(ParamFormat.obj2Str(args[0]).replace(ParamFormat.obj2Str(args[1]), ParamFormat.obj2Str(args[2])));
|
||||
break;
|
||||
case 2:
|
||||
result.setVal(ParamFormat.obj2Str(args[0]).replaceFirst(ParamFormat.obj2Str(args[1]), ParamFormat.obj2Str(args[2])));
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return _nullChr;
|
||||
}
|
||||
}
|
||||
Loaded 100 of 308 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user