/** * Converts the given object value into an instance of this Result enumeration. * * @param value The object to convert. * @return The corresponding result value. */ public static Result toResult(Object value) { if (value == null || value == Result.FALSE || value == Boolean.FALSE || (Number.class.isInstance(value) && ((Number)value).doubleValue() == 0)) { return Result.FALSE; } else if (value == INVALID) { return Result.INVALID; } else if (value instanceof AttributeNode.VariableValueList) { return ((AttributeNode.VariableValueList)value).isEmpty() ? Result.FALSE : Result.TRUE; } else if (value instanceof ResultList) { return ((ResultList)value).toResult(); } else { return Result.TRUE; } } }
private static Object evaluateFieldPath(String fieldPth, Object value) { if (value instanceof DocumentPut) { final Document doc = ((DocumentPut) value).getDocument(); FieldPath fieldPath = doc.getDataType().buildFieldPath(fieldPth); IteratorHandler handler = new IteratorHandler(); doc.iterateNested(fieldPath, 0, handler); if (handler.values.isEmpty()) { return null; } return handler.values; } else if (value instanceof DocumentUpdate) { return Result.INVALID; } else if (value instanceof DocumentRemove) { return Result.INVALID; } else if (value instanceof DocumentGet) { return Result.INVALID; } return Result.FALSE; }
public ResultList evaluateListsTrue(AttributeNode.VariableValueList lhs, AttributeNode.VariableValueList rhs) { if (lhs.size() != rhs.size()) { return new ResultList(Result.FALSE); } for (int i = 0; i < lhs.size(); i++) { if (!lhs.get(i).getVariables().equals(rhs.get(i).getVariables())) { return new ResultList(Result.FALSE); } if (evaluateEquals(lhs.get(i).getValue(), rhs.get(i).getValue()) == Result.FALSE) { return new ResultList(Result.FALSE); } } return new ResultList(Result.TRUE); }
public ResultList evaluateListAndSingle(AttributeNode.VariableValueList lhs, Object rhs) { if (rhs == null && lhs == null) { return new ResultList(Result.TRUE); } if (rhs == null || lhs == null) { return new ResultList(Result.FALSE); } ResultList retVal = new ResultList(); for (int i = 0; i < lhs.size(); i++) { Result result = evaluateBool(lhs.get(i).getValue(), rhs); retVal.add((FieldPathIteratorHandler.VariableMap)lhs.get(i).getVariables().clone(), result); } return retVal; }
private static Object evaluateFunction(String function, Object value) { if (value instanceof VariableValueList) { VariableValueList retVal = new VariableValueList(); for (ResultList.VariableValue val : ((VariableValueList)value)) { retVal.add(new ResultList.VariableValue( (FieldPathIteratorHandler.VariableMap)val.getVariables().clone(), applyFunction(function, val.getValue()))); } return retVal; } return applyFunction(function, value); }
@Override public void onPrimitive(FieldValue fv) { values.add(new ResultList.VariableValue((VariableMap)getVariables().clone(), fv)); } }