@Override public ExprValue getValue(DataProvider provider) { return new ExprValue(value); }
@Override protected void onExecute(XsObject root,XsObject current, LogicletContext ctx, ExecuteWatcher watcher) { if (expr != null){ try { String value = expr.getValue(ctx).toString(); ctx.SetValue(id, value); }catch (Exception ex){ logger.error(ExceptionUtils.getStackTrace(ex)); } } }
case Long:// NOSONAR if (other.dataType == DataType.Long){ setLong(getLong() + other.getLong()); return this; }else{ if (other.dataType == DataType.Double){ setDouble(getLong() + other.getDouble()); return this; case Double: if (other.dataType == DataType.Long || other.dataType == DataType.Double){ setDouble(getDouble() + other.getDouble()); return this; setString(getString() + other.getString()); return this; default:
case Long:// NOSONAR if (other.dataType == DataType.Long){ setLong(getLong() - other.getLong()); return this; }else{ if (other.dataType == DataType.Double){ setDouble(getLong() - other.getDouble()); return this; case Double: if (other.dataType == DataType.Long || other.dataType == DataType.Double){ setDouble(getDouble() - other.getDouble()); return this;
case OP_Negative:{ // NOSONAR ExprValue value = expr.getValue(provider); switch (value.getDataType()){ case Long: return new ExprValue(-value.getLong()); case Double: return new ExprValue(-value.getDouble()); default: throw new FormulaException("Can not get a negative value of " + value.getDataType()); case OP_Not:{ // NOSONAR ExprValue value = expr.getValue(provider); if (value.getDataType() == DataType.Boolean){ return new ExprValue(!value.getBoolean()); throw new FormulaException("Can not get a negative value of " + value.getDataType());
public ExprValue getValue(DataProvider provider) throws FormulaException { if (getArgumentCount() != 2){ throw new FormulaException("substr function need 2 argument."); } String srcString = getArgument(0).getValue(provider).getString(); String childString = getArgument(1).getValue(provider).getString(); return new ExprValue(srcString.indexOf(childString)); } }
public ExprValue getValue(DataProvider provider) throws FormulaException { if (getArgumentCount() != 3){ throw new FormulaException("substr function need 3 argument."); } String string = getArgument(0).getValue(provider).getString(); int startOffset = getArgument(1).getValue(provider).getInt(); int length = getArgument(2).getValue(provider).getInt(); startOffset = startOffset < 0 ? 0 : startOffset >= string.length()?string.length() - 1:startOffset; length = string.length() - startOffset < length ? string.length() - startOffset:length; return new ExprValue(string.substring(startOffset, startOffset + length)); } }
/** * to compute the expression with {@code DataProvider} * @param provider instance of DataProvider * @return value of expr */ @Override public ExprValue getValue(DataProvider provider){ // NOSONAR switch (operator) { case OP_Add: return left.getValue(provider).add(right.getValue(provider)); case OP_Sub: return left.getValue(provider).sub(right.getValue(provider)); case OP_Mul: return left.getValue(provider).mul(right.getValue(provider)); case OP_Div: return left.getValue(provider).div(right.getValue(provider)); case OP_Mod: return left.getValue(provider).mod(right.getValue(provider)); default: } throw new FormulaException("Unsupport operator:" + operator); }
switch (operator) { case OP_Greater: return new ExprValue(left.getValue(provider).compareTo( right.getValue(provider)) > 0); case OP_Greater_Equal: return new ExprValue(left.getValue(provider).compareTo( right.getValue(provider)) >= 0); case OP_Equal: return new ExprValue(left.getValue(provider).compareTo( right.getValue(provider)) == 0); case OP_Not_Equal: return new ExprValue(left.getValue(provider).compareTo( right.getValue(provider)) != 0); case OP_Less: return new ExprValue(left.getValue(provider).compareTo( right.getValue(provider)) < 0); case OP_Less_Equal: return new ExprValue(left.getValue(provider).compareTo( right.getValue(provider)) <= 0); case OP_Or: return new ExprValue(left.getValue(provider).getBoolean() || right.getValue(provider).getBoolean()); case OP_And: return new ExprValue(left.getValue(provider).getBoolean() && right.getValue(provider).getBoolean()); default:
public ExprValue getValue(DataProvider provider) throws FormulaException { if (getArgumentCount() < 1){ throw new FormulaException("to_char function need at least 1 argument.we have " + getArgumentCount()); } String pattern = "yyyyMMddHHmmss"; if (getArgument(1) != null){ pattern = getArgument(1).getValue(provider).getString(); } Date value = getArgument(0).getValue(provider).getDate(); return new ExprValue(DateUtil.formatDate(value, pattern)); } }
@Override public ExprValue getValue(DataProvider provider) throws FormulaException { int arguCnt = getArgumentCount(); ExprValue bindValue = null; if (arguCnt <= 0){ bindValue = new ExprValue("?"); }else{ bindValue = getArgument(0).getValue(provider); if (arguCnt <= 1){ bind(KeyGen.uuid()); }else{ if (arguCnt <= 2){ int length = getArgument(1).getValue(provider).getInt(); bind(KeyGen.uuid(length, 0)); }else{ int length = getArgument(1).getValue(provider).getInt(); int redix = getArgument(2).getValue(provider).getInt(); bind(KeyGen.uuid(length, redix)); } } } return bindValue; } }
return ((Long)value).compareTo((Long)other.value); case Double: // NOSONAR if (getLong() > other.getDouble()){ return 1; }else{ return other.getDouble() > getLong() ? -1 : 0; return ((Double)value).compareTo((Double)other.value); case Long: // NOSONAR boolean compare = getDouble() > other.getLong(); if (compare){ return 1; }else{ return getDouble() < other.getLong() ? -1 : 0;
public float getFloat(){ return (float)getDouble(); }
public ExprValue getValue(DataProvider provider) throws FormulaException { if (getArgumentCount() != 3){ throw new FormulaException("choice function need 3 arguments.we have " + getArgumentCount()); } Expression boolExpr = getArgument(0); ExprValue boolValue = boolExpr.getValue(provider); if (boolValue.getBoolean()){ return getArgument(1).getValue(provider); }else{ return getArgument(2).getValue(provider); } } }
case Long: // NOSONAR if (other.dataType == DataType.Long){ setLong(getLong() * other.getLong()); return this; }else{ if (other.dataType == DataType.Double){ setDouble(getLong() * other.getDouble()); return this; case Double: if (other.dataType == DataType.Long || other.dataType == DataType.Double){ setDouble(getDouble() * other.getDouble()); return this;
public ExprValue getValue(DataProvider provider) throws FormulaException { if (getArgumentCount() != 2){ throw new FormulaException("match function need 2 argument."); } String srcString = getArgument(0).getValue(provider).getString(); String regex = getArgument(1).getValue(provider).getString(); return new ExprValue(srcString.matches(regex)); } }
@Override public ExprValue getValue(DataProvider provider) throws FormulaException { int arguCnt = getArgumentCount(); if (arguCnt > 2 || arguCnt <= 0) { throw new FormulaException( "bind function need 1 argument.we have " + arguCnt); } ExprValue value = getArgument(0).getValue(provider); String varName = value.toString(); if (varContext == null) { varContext = provider.getContext(varName); } String object = provider.getValue(varName, varContext, ""); bind(object); if (arguCnt <= 1){ return new ExprValue("?"); }else{ return getArgument(1).getValue(provider); } } }
case Long: // NOSONAR if (other.dataType == DataType.Long){ if (other.getLong() == 0) throw new FormulaException("divided by zero"); // NOSONAR setLong(getLong() / other.getLong()); return this; }else{ if (other.dataType == DataType.Double){ if (other.getDouble() == 0) // NOSONAR throw new FormulaException("divided by zero"); setDouble(getLong() / other.getDouble()); return this; case Double: // NOSONAR if (other.dataType == DataType.Long || other.dataType == DataType.Double){ if (other.getDouble() == 0) // NOSONAR throw new FormulaException("divided by zero"); setDouble(getDouble() / other.getDouble()); return this;