public static boolean notEquals(VariableScope variableScope, String variableName, Object variableValue) { // Special handling for null: when the variable is null, false is returned. // This is similar to equals, where a null variable value will always return false // (it's effectively ignored) - unless it's compared to null itself) Object actualValue = getVariableValue(variableScope, variableName); if (actualValue != null) { return !VariableEqualsExpressionFunction.equals(variableScope, variableName, variableValue); } return false; } }
public static Object getOrDefault(VariableScope variableScope, String variableName, Object value) { Object variableValue = getVariableValue(variableScope, variableName); if (variableValue != null) { return variableValue; } else { return value; } }
public static Object get(VariableScope variableScope, String variableName) { Object variableValue = getVariableValue(variableScope, variableName); return variableValue; }
public void initShortHandExpressionFunctions() { if (shortHandExpressionFunctions == null) { shortHandExpressionFunctions = new ArrayList<>(); String variableScopeName = "planItemInstance"; shortHandExpressionFunctions.add(new VariableGetExpressionFunction(variableScopeName)); shortHandExpressionFunctions.add(new VariableGetOrDefaultExpressionFunction(variableScopeName)); shortHandExpressionFunctions.add(new VariableContainsAnyExpressionFunction(variableScopeName)); shortHandExpressionFunctions.add(new VariableContainsExpressionFunction(variableScopeName)); shortHandExpressionFunctions.add(new VariableEqualsExpressionFunction(variableScopeName)); shortHandExpressionFunctions.add(new VariableNotEqualsExpressionFunction(variableScopeName)); shortHandExpressionFunctions.add(new VariableExistsExpressionFunction(variableScopeName)); shortHandExpressionFunctions.add(new VariableIsEmptyExpressionFunction(variableScopeName)); shortHandExpressionFunctions.add(new VariableIsNotEmptyExpressionFunction(variableScopeName)); shortHandExpressionFunctions.add(new VariableLowerThanExpressionFunction(variableScopeName)); shortHandExpressionFunctions.add(new VariableLowerThanOrEqualsExpressionFunction(variableScopeName)); shortHandExpressionFunctions.add(new VariableGreaterThanExpressionFunction(variableScopeName)); shortHandExpressionFunctions.add(new VariableGreaterThanOrEqualsExpressionFunction(variableScopeName)); } }
this.pattern = Pattern.compile(buildOrWordGroup(getFunctionPrefixOptions()) + ":" + buildOrWordGroup(functionNameOptions) + "\\s*\\(\\s*'?\"?(.*?)'?\"?\\s*" + (isMultiParameterFunction() ? "," : "\\)")); this.replacePattern = getFinalFunctionPrefix() + ":" + functionName + "(" + variableScopeName + ",'$3'" // 3th word group: prefix and function name are two first groups + (isMultiParameterFunction() ? "," : ")"); this.prefix = getFinalFunctionPrefix(); this.localName = functionName; this.method = findMethod();
@SuppressWarnings({ "rawtypes"}) public static boolean containsAny(VariableScope variableScope, String variableName, Object... values) { Object variableValue = getVariableValue(variableScope, variableName); if (variableValue != null) { if (variableValue instanceof String) { Collection collectionVariableValue = (Collection) variableValue; for (Object value : values) { if (VariableContainsExpressionFunction.collectionContains(collectionVariableValue, value)) { return true; ArrayNode arrayNodeVariableValue = (ArrayNode) variableValue; for (Object value : values) { if (VariableContainsExpressionFunction.arrayNodeContains(arrayNodeVariableValue, value)) { return true;
@SuppressWarnings({ "rawtypes"}) public static boolean contains(VariableScope variableScope, String variableName, Object... values) { Object variableValue = getVariableValue(variableScope, variableName); if (variableValue != null) { if (variableValue instanceof String) { Collection collectionVariableValue = (Collection) variableValue; for (Object value : values) { if (!collectionContains(collectionVariableValue, value)) { return false; ArrayNode arrayNodeVariableValue = (ArrayNode) variableValue; for (Object value : values) { if (!arrayNodeContains(arrayNodeVariableValue, value)) { return false;
public static boolean equals(VariableScope variableScope, String variableName, Object comparedValue) { Object variableValue = getVariableValue(variableScope, variableName); if (comparedValue != null && variableValue != null) { if (valuesAreNumbers(comparedValue, variableValue)) { if (variableValue instanceof Long) { return ((Number) variableValue).longValue() == ((Number) comparedValue).longValue(); return defaultEquals(comparedValue, variableValue);
@SuppressWarnings({ "unchecked", "rawtypes" }) protected static boolean compareVariableValue(VariableScope variableScope, String variableName, Object comparedValue, OPERATOR operator) { Object variableValue = getVariableValue(variableScope, variableName); if (comparedValue != null && variableValue != null) { if (valuesAreNumbers(comparedValue, variableValue)) { if (variableValue instanceof Long) {
public static boolean greaterThanOrEquals(VariableScope variableScope, String variableName, Object comparedValue) { return compareVariableValue(variableScope, variableName, comparedValue, OPERATOR.GTE); }
public static boolean lowerThan(VariableScope variableScope, String variableName, Object comparedValue) { return compareVariableValue(variableScope, variableName, comparedValue, OPERATOR.LT); }
public static boolean isNotEmpty(VariableScope variableScope, String variableName) { return !VariableIsEmptyExpressionFunction.isEmpty(variableScope, variableName); }
public static boolean exists(VariableScope variableScope, String variableName) { return getVariableValue(variableScope, variableName) != null; }
public static boolean greaterThan(VariableScope variableScope, String variableName, Object comparedValue) { return compareVariableValue(variableScope, variableName, comparedValue, OPERATOR.GT); }
public static boolean lowerThanOrEquals(VariableScope variableScope, String variableName, Object comparedValue) { return compareVariableValue(variableScope, variableName, comparedValue, OPERATOR.LTE); }
@SuppressWarnings("rawtypes") public static boolean isEmpty(VariableScope variableScope, String variableName) { Object variableValue = getVariableValue(variableScope, variableName); if (variableValue == null) { return true; } else if (variableValue instanceof String) { return StringUtils.isEmpty((String) variableValue); } else if (variableValue instanceof Collection) { return CollectionUtil.isEmpty((Collection) variableValue); } else if (variableValue instanceof ArrayNode) { return ((ArrayNode) variableValue).size() == 0; } else { return false; } }
public void initShortHandExpressionFunctions() { if (shortHandExpressionFunctions == null) { shortHandExpressionFunctions = new ArrayList<>(); String variableScopeName = "execution"; shortHandExpressionFunctions.add(new VariableGetExpressionFunction(variableScopeName)); shortHandExpressionFunctions.add(new VariableGetOrDefaultExpressionFunction(variableScopeName)); shortHandExpressionFunctions.add(new VariableContainsAnyExpressionFunction(variableScopeName)); shortHandExpressionFunctions.add(new VariableContainsExpressionFunction(variableScopeName)); shortHandExpressionFunctions.add(new VariableEqualsExpressionFunction(variableScopeName)); shortHandExpressionFunctions.add(new VariableNotEqualsExpressionFunction(variableScopeName)); shortHandExpressionFunctions.add(new VariableExistsExpressionFunction(variableScopeName)); shortHandExpressionFunctions.add(new VariableIsEmptyExpressionFunction(variableScopeName)); shortHandExpressionFunctions.add(new VariableIsNotEmptyExpressionFunction(variableScopeName)); shortHandExpressionFunctions.add(new VariableLowerThanExpressionFunction(variableScopeName)); shortHandExpressionFunctions.add(new VariableLowerThanOrEqualsExpressionFunction(variableScopeName)); shortHandExpressionFunctions.add(new VariableGreaterThanExpressionFunction(variableScopeName)); shortHandExpressionFunctions.add(new VariableGreaterThanOrEqualsExpressionFunction(variableScopeName)); } }