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

com.alogic.xscript.plugins.Decr Maven / Gradle / Ivy

There is a newer version: 1.6.17
Show newest version
package com.alogic.xscript.plugins;

import com.alogic.xscript.AbstractLogiclet;
import com.alogic.xscript.ExecuteWatcher;
import com.alogic.xscript.Logiclet;
import com.alogic.xscript.LogicletContext;
import com.alogic.xscript.doc.XsObject;
import com.anysoft.util.Properties;
import com.anysoft.util.PropertiesConstants;
import org.apache.commons.lang3.StringUtils;

/**
 * 对整形变量执行累减操作
 * 
 * @author yyduan
 *
 * @since 1.6.10.1
 * 
 * @version 1.6.11.16 [20180207 duanyy] 
* - value缺省值由0更改为1;
* * @version 1.6.12.40 [20190814]
* - id参数支持计算
*/ public class Decr extends AbstractLogiclet { protected String $id; protected String value = "1"; public Decr(String tag, Logiclet p) { super(tag, p); } @Override public void configure(Properties p){ super.configure(p); $id = PropertiesConstants.getRaw(p,"id",""); value = PropertiesConstants.getRaw(p,"value",value); } @Override protected void onExecute(XsObject root,XsObject current,final LogicletContext ctx,final ExecuteWatcher watcher){ String id = PropertiesConstants.transform(ctx,$id,""); if (StringUtils.isNotEmpty(id)) { long oldValue = getLong(ctx.GetValue(id, "0"), 0); long incrValue = getLong(ctx.transform(value), 0); ctx.SetValue(id, String.valueOf(oldValue - incrValue)); } } protected long getLong(String v,long dft){ try{ return Long.parseLong(v); }catch (NumberFormatException ex){ return dft; } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy