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() != 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)); } }
public ExprValue getValue(DataProvider provider) throws FormulaException { if (getArgumentCount() != 1){ throw new FormulaException("to_long function need 1 argument."); } String value = getArgument(0).getValue(provider).getString(); return new ExprValue(Long.valueOf(value)); } }
public ExprValue getValue(DataProvider provider) throws FormulaException { if (getArgumentCount() != 1){ throw new FormulaException("to_double function need 1 argument."); } String value = getArgument(0).getValue(provider).getString(); return new ExprValue(Double.valueOf(value)); } }
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)); } }
public ExprValue getValue(DataProvider provider) throws FormulaException { if (getArgumentCount() < 1){ throw new FormulaException("to_date function need at least 1 argument.we have " + getArgumentCount()); } String pattern = "yyyyMMddHHmmss"; if (getArgument(1) != null){ pattern = getArgument(1).getValue(provider).getString(); } String value = getArgument(0).getValue(provider).getString(); return new ExprValue(DateUtil.parseDate(value, pattern)); } }
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)); } }