List of usage examples for org.apache.commons.lang3.mutable MutableBoolean booleanValue
public boolean booleanValue()
From source file:org.apache.asterix.external.classad.AttributeReference.java
@Override public boolean privateEvaluate(EvalState state, Value val, ExprTreeHolder sig) throws HyracksDataException { ExprTreeHolder tree = objectPool.mutableExprPool.get(); ExprTreeHolder exprSig = objectPool.mutableExprPool.get(); ClassAd curAd = objectPool.classAdPool.get(); curAd.copyFrom(state.getCurAd());//from w w w .ja v a2 s . com MutableBoolean rval = objectPool.boolPool.get(); rval.setValue(true); switch (findExpr(state, tree, exprSig, true)) { case EVAL_FAIL: rval.setValue(false); break; case EVAL_ERROR: val.setErrorValue(); break; case EVAL_UNDEF: val.setUndefinedValue(); break; case EVAL_OK: { if (state.getDepthRemaining() <= 0) { val.setErrorValue(); state.getCurAd().setValue(curAd); return false; } state.decrementDepth(); rval.setValue(tree.publicEvaluate(state, val)); state.incrementDepth(); break; } default: throw new HyracksDataException("ClassAd: Should not reach here"); } AttributeReference newAttrRef = objectPool.attrRefPool.get(); newAttrRef.setValue(exprSig, attributeStr, absolute); sig.setInnerTree(newAttrRef); state.getCurAd().setValue(curAd); return rval.booleanValue(); }
From source file:org.apache.asterix.external.classad.ClassAd.java
public boolean privateGetExternalReferences(ExprTree expr, ClassAd ad, EvalState state, TreeSet<String> refs, boolean fullNames) throws HyracksDataException { if (expr.isTreeHolder()) { expr = ((ExprTreeHolder) expr).getInnerTree(); }/*from w w w . j a v a2s . c o m*/ switch (expr.getKind()) { case LITERAL_NODE: // no external references here return (true); case ATTRREF_NODE: { ClassAd start = objectPool.classAdPool.get(); ExprTreeHolder tree = objectPool.mutableExprPool.get(); ExprTreeHolder result = objectPool.mutableExprPool.get(); AMutableCharArrayString attr = objectPool.strPool.get(); Value val = objectPool.valuePool.get(); MutableBoolean abs = objectPool.boolPool.get(); ((AttributeReference) expr).getComponents(tree, attr, abs); // establish starting point for attribute search if (tree.getInnerTree() == null) { start = abs.booleanValue() ? state.getRootAd() : state.getCurAd(); if (abs.booleanValue() && (start == null)) {// NAC - circularity so no root return false; // NAC } // NAC } else { if (!tree.publicEvaluate(state, val)) { return (false); } // if the tree evals to undefined, the external references // are in the tree part if (val.isUndefinedValue()) { if (fullNames) { AMutableCharArrayString fullName = objectPool.strPool.get(); if (tree.getInnerTree() != null) { ClassAdUnParser unparser = objectPool.prettyPrintPool.get(); unparser.unparse(fullName, tree); fullName.appendChar('.'); } fullName.appendString(attr); refs.add(fullName.toString()); return true; } else { if (state.getDepthRemaining() <= 0) { return false; } state.decrementDepth(); boolean ret = privateGetExternalReferences(tree, ad, state, refs, fullNames); state.incrementDepth(); return ret; } } // otherwise, if the tree didn't evaluate to a classad, // we have a problem if (!val.isClassAdValue(start)) { return (false); } } // lookup for attribute ClassAd curAd = state.getCurAd(); switch (start.lookupInScope(attr.toString(), result, state)) { case EVAL_ERROR_Int: // some error return (false); case EVAL_UNDEF_Int: // attr is external refs.add(attr.toString()); state.setCurAd(curAd); return (true); case EVAL_OK_Int: { // attr is internal; find external refs in result if (state.getDepthRemaining() <= 0) { state.setCurAd(curAd); return false; } state.decrementDepth(); boolean rval = privateGetExternalReferences(result, ad, state, refs, fullNames); state.incrementDepth(); state.setCurAd(curAd); return (rval); } case EVAL_FAIL_Int: default: // enh?? return (false); } } case OP_NODE: { // recurse on subtrees AMutableInt32 opKind = objectPool.int32Pool.get(); ExprTreeHolder t1 = objectPool.mutableExprPool.get(); ExprTreeHolder t2 = objectPool.mutableExprPool.get(); ExprTreeHolder t3 = objectPool.mutableExprPool.get(); ((Operation) expr).getComponents(opKind, t1, t2, t3); if (t1.getInnerTree() != null && !privateGetExternalReferences(t1, ad, state, refs, fullNames)) { return (false); } if (t2.getInnerTree() != null && !privateGetExternalReferences(t2, ad, state, refs, fullNames)) { return (false); } if (t3.getInnerTree() != null && !privateGetExternalReferences(t3, ad, state, refs, fullNames)) { return (false); } return (true); } case FN_CALL_NODE: { // recurse on subtrees AMutableCharArrayString fnName = objectPool.strPool.get(); ExprList args = objectPool.exprListPool.get(); ((FunctionCall) expr).getComponents(fnName, args); for (ExprTree tree : args.getExprList()) { if (!privateGetExternalReferences(tree, ad, state, refs, fullNames)) { return (false); } } return (true); } case CLASSAD_NODE: { // recurse on subtrees Map<CaseInsensitiveString, ExprTree> attrs = objectPool.strToExprPool.get(); ((ClassAd) expr).getComponents(attrs, objectPool); for (Entry<CaseInsensitiveString, ExprTree> entry : attrs.entrySet()) { if (state.getDepthRemaining() <= 0) { return false; } state.decrementDepth(); boolean ret = privateGetExternalReferences(entry.getValue(), ad, state, refs, fullNames); state.incrementDepth(); if (!ret) { return (false); } } return (true); } case EXPR_LIST_NODE: { // recurse on subtrees ExprList exprs = objectPool.exprListPool.get(); ((ExprList) expr).getComponents(exprs); for (ExprTree exprTree : exprs.getExprList()) { if (state.getDepthRemaining() <= 0) { return false; } state.decrementDepth(); boolean ret = privateGetExternalReferences(exprTree, ad, state, refs, fullNames); state.incrementDepth(); if (!ret) { return (false); } } return (true); } default: return false; } }
From source file:org.apache.asterix.external.classad.ClassAd.java
public boolean privateGetExternalReferences(ExprTree expr, ClassAd ad, EvalState state, Map<ClassAd, TreeSet<String>> refs) throws HyracksDataException { switch (expr.getKind()) { case LITERAL_NODE: // no external references here return (true); case ATTRREF_NODE: { ClassAd start = objectPool.classAdPool.get(); ExprTreeHolder tree = objectPool.mutableExprPool.get(); ExprTreeHolder result = objectPool.mutableExprPool.get(); AMutableCharArrayString attr = objectPool.strPool.get(); Value val = objectPool.valuePool.get(); MutableBoolean abs = objectPool.boolPool.get(); ((AttributeReference) expr).getComponents(tree, attr, abs); // establish starting point for attribute search if (tree.getInnerTree() == null) { start = abs.booleanValue() ? state.getRootAd() : state.getCurAd(); if (abs.booleanValue() && (start == null)) {// NAC - circularity so no root return false; // NAC } // NAC } else {/*from w w w. j av a2 s. c om*/ if (!tree.publicEvaluate(state, val)) { return (false); } // if the tree evals to undefined, the external references // are in the tree part if (val.isUndefinedValue()) { return (privateGetExternalReferences(tree, ad, state, refs)); } // otherwise, if the tree didn't evaluate to a classad, // we have a problem if (!val.isClassAdValue(start)) { return (false); } // make sure that we are starting from a "valid" scope if (!refs.containsKey(start) && start != this) { return (false); } } // lookup for attribute ClassAd curAd = state.getCurAd(); TreeSet<String> pitr = refs.get(start); if (pitr == null) { pitr = objectPool.strSetPool.get(); refs.put(start, pitr); } switch (start.lookupInScope(attr.toString(), result, state)) { case EVAL_ERROR_Int: // some error return (false); case EVAL_UNDEF_Int: // attr is external pitr.add(attr.toString()); state.setCurAd(curAd); return (true); case EVAL_OK_Int: { // attr is internal; find external refs in result boolean rval = privateGetExternalReferences(result, ad, state, refs); state.setCurAd(curAd); return (rval); } case EVAL_FAIL_Int: default: // enh?? return (false); } } case OP_NODE: { // recurse on subtrees AMutableInt32 opKind = objectPool.int32Pool.get(); ExprTreeHolder t1 = objectPool.mutableExprPool.get(); ExprTreeHolder t2 = objectPool.mutableExprPool.get(); ExprTreeHolder t3 = objectPool.mutableExprPool.get(); ((Operation) expr).getComponents(opKind, t1, t2, t3); if (t1.getInnerTree() != null && !privateGetExternalReferences(t1, ad, state, refs)) { return (false); } if (t2.getInnerTree() != null && !privateGetExternalReferences(t2, ad, state, refs)) { return (false); } if (t3.getInnerTree() != null && !privateGetExternalReferences(t3, ad, state, refs)) { return (false); } return (true); } case FN_CALL_NODE: { // recurse on subtrees AMutableCharArrayString fnName = objectPool.strPool.get(); ExprList args = objectPool.exprListPool.get(); ((FunctionCall) expr).getComponents(fnName, args); for (ExprTree exprTree : args.getExprList()) { if (!privateGetExternalReferences(exprTree, ad, state, refs)) { return (false); } } return (true); } case CLASSAD_NODE: { // recurse on subtrees HashMap<CaseInsensitiveString, ExprTree> attrs = objectPool.strToExprPool.get(); ((ClassAd) expr).getComponents(attrs, objectPool); for (Entry<CaseInsensitiveString, ExprTree> entry : attrs.entrySet()) { if (!privateGetExternalReferences(entry.getValue(), ad, state, refs)) { return (false); } } return (true); } case EXPR_LIST_NODE: { // recurse on subtrees ExprList exprs = objectPool.exprListPool.get(); ((ExprList) expr).getComponents(exprs); for (ExprTree exprTree : exprs.getExprList()) { if (!privateGetExternalReferences(exprTree, ad, state, refs)) { return (false); } } return (true); } default: return false; } }
From source file:org.apache.asterix.external.classad.ClassAd.java
public boolean privateGetInternalReferences(ExprTree expr, ClassAd ad, EvalState state, TreeSet<String> refs, boolean fullNames) throws HyracksDataException { switch (expr.getKind()) { //nothing to be found here! case LITERAL_NODE: { return true; }/* ww w . j av a2 s . c o m*/ case ATTRREF_NODE: { ClassAd start = objectPool.classAdPool.get(); ; ExprTreeHolder tree = objectPool.mutableExprPool.get(); ExprTreeHolder result = objectPool.mutableExprPool.get(); AMutableCharArrayString attr = objectPool.strPool.get(); Value val = objectPool.valuePool.get(); MutableBoolean abs = objectPool.boolPool.get(); ((AttributeReference) expr).getComponents(tree, attr, abs); //figuring out which state to base this off of if (tree.getInnerTree() == null) { start = abs.booleanValue() ? state.getRootAd() : state.getCurAd(); //remove circularity if (abs.booleanValue() && (start == null)) { return false; } } else { boolean orig_inAttrRefScope = state.isInAttrRefScope(); state.setInAttrRefScope(true); boolean rv = privateGetInternalReferences(tree, ad, state, refs, fullNames); state.setInAttrRefScope(orig_inAttrRefScope); if (!rv) { return false; } if (!tree.publicEvaluate(state, val)) { return false; } // TODO Do we need extra handling for list values? // Should types other than undefined, error, or list // cause a failure? if (val.isUndefinedValue()) { return true; } //otherwise, if the tree didn't evaluate to a classad, //we have a problemo, mon. //TODO: but why? if (!val.isClassAdValue(start)) { return false; } } ClassAd curAd = state.getCurAd(); switch (start.lookupInScope(attr.toString(), result, state)) { case EVAL_ERROR_Int: return false; //attr is external, so let's find the internals in that //result //JUST KIDDING case EVAL_UNDEF_Int: { //boolean rval = _GetInternalReferences(result, ad, state, refs, fullNames); //state.getCurAd() = curAd; return true; } case EVAL_OK_Int: { //whoo, it's internal. // Check whether the attribute was found in the root // ad for this evaluation and that the attribute isn't // one of our special ones (self, parent, my, etc.). // If the ad actually has an attribute with the same // name as one of our special attributes, then count // that as an internal reference. // TODO LookupInScope() knows whether it's returning // the expression of one of the special attributes // or that of an attribute that actually appears in // the ad. If it told us which one, then we could // avoid the Lookup() call below. if (state.getCurAd() == state.getRootAd() && state.getCurAd().lookup(attr.toString()) != null) { refs.add(attr.toString()); } if (state.getDepthRemaining() <= 0) { state.setCurAd(curAd); return false; } state.decrementDepth(); boolean rval = privateGetInternalReferences(result, ad, state, refs, fullNames); state.incrementDepth(); //TODO: Does this actually matter? state.setCurAd(curAd); return rval; } case EVAL_FAIL_Int: default: // "enh??" return false; } } case OP_NODE: { //recurse on subtrees AMutableInt32 op = objectPool.int32Pool.get(); ExprTreeHolder t1 = objectPool.mutableExprPool.get(); ExprTreeHolder t2 = objectPool.mutableExprPool.get(); ExprTreeHolder t3 = objectPool.mutableExprPool.get(); ((Operation) expr).getComponents(op, t1, t2, t3); if (t1.getInnerTree() != null && !privateGetInternalReferences(t1, ad, state, refs, fullNames)) { return false; } if (t2.getInnerTree() != null && !privateGetInternalReferences(t2, ad, state, refs, fullNames)) { return false; } if (t3.getInnerTree() != null && !privateGetInternalReferences(t3, ad, state, refs, fullNames)) { return false; } return true; } case FN_CALL_NODE: { //recurse on the subtrees! AMutableCharArrayString fnName = objectPool.strPool.get(); ExprList args = objectPool.exprListPool.get(); ((FunctionCall) expr).getComponents(fnName, args); for (ExprTree exprTree : args.getExprList()) { if (!privateGetInternalReferences(exprTree, ad, state, refs, fullNames)) { return false; } } return true; } case CLASSAD_NODE: { //also recurse on subtrees... HashMap<CaseInsensitiveString, ExprTree> attrs = objectPool.strToExprPool.get(); // If this ClassAd is only being used here as the scoping // for an attribute reference, don't recurse into all of // its attributes. if (state.isInAttrRefScope()) { return true; } ((ClassAd) expr).getComponents(attrs, objectPool); for (Entry<CaseInsensitiveString, ExprTree> entry : attrs.entrySet()) { if (state.getDepthRemaining() <= 0) { return false; } state.decrementDepth(); boolean ret = privateGetInternalReferences(entry.getValue(), ad, state, refs, fullNames); state.incrementDepth(); if (!ret) { return false; } } return true; } case EXPR_LIST_NODE: { ExprList exprs = objectPool.exprListPool.get(); ((ExprList) expr).getComponents(exprs); for (ExprTree exprTree : exprs.getExprList()) { if (state.getDepthRemaining() <= 0) { return false; } state.decrementDepth(); boolean ret = privateGetInternalReferences(exprTree, ad, state, refs, fullNames); state.incrementDepth(); if (!ret) { return false; } } return true; } default: return false; } }
From source file:org.apache.asterix.external.classad.ClassAdUnParser.java
/** * Unparse a value/*from ww w . j a v a2 s . co m*/ * * @param buffer * The string to unparse to * @param val * The value to unparse * @throws HyracksDataException */ public void unparse(AMutableCharArrayString buffer, Value val) throws HyracksDataException { switch (val.getType()) { case NULL_VALUE: buffer.appendString("(null-value)"); break; case STRING_VALUE: { AMutableCharArrayString s = objectPool.strPool.get(); val.isStringValue(s); buffer.appendChar('"'); for (int i = 0; i < s.getLength(); i++) { char ch = s.charAt(i); if (ch == delimiter) { if (delimiter == '\"') { buffer.appendString("\\\""); continue; } else { buffer.appendString("\\\'"); continue; } } switch (ch) { case '\b': buffer.appendString("\\b"); continue; case '\f': buffer.appendString("\\f"); continue; case '\n': buffer.appendString("\\n"); continue; case '\r': buffer.appendString("\\r"); continue; case '\t': buffer.appendString("\\t"); continue; case '\\': buffer.appendString("\\\\"); continue; case '\'': buffer.appendString("\'"); continue; case '\"': buffer.appendString("\""); continue; default: if (Character.isISOControl(ch)) { // print octal representation buffer.appendString(String.format("\\%03o", ch)); continue; } break; } buffer.appendChar(ch); } buffer.appendChar('"'); return; } case INTEGER_VALUE: { AMutableInt64 i = objectPool.int64Pool.get(); val.isIntegerValue(i); buffer.appendString(String.valueOf(i.getLongValue())); return; } case REAL_VALUE: { AMutableDouble real = objectPool.doublePool.get(); val.isRealValue(real); if (real.getDoubleValue() == 0.0) { // It might be positive or negative and it's // hard to tell. printf is good at telling though. // We also want to print it with as few // digits as possible, which is why we don't use the // case below. buffer.appendString(String.valueOf(real.getDoubleValue())); } else if (Util.isNan(real.getDoubleValue())) { buffer.appendString("real(\"NaN\")"); } else if (Util.isInf(real.getDoubleValue()) == -1) { buffer.appendString("real(\"-INF\")"); } else if (Util.isInf(real.getDoubleValue()) == 1) { buffer.appendString("real(\"INF\")"); } else { buffer.appendString(String.format("%1.15E", real.getDoubleValue())); } return; } case BOOLEAN_VALUE: { MutableBoolean b = objectPool.boolPool.get(); val.isBooleanValue(b); buffer.appendString(b.booleanValue() ? "true" : "false"); return; } case UNDEFINED_VALUE: { buffer.appendString("undefined"); return; } case ERROR_VALUE: { buffer.appendString("error"); return; } case ABSOLUTE_TIME_VALUE: { ClassAdTime asecs = objectPool.classAdTimePool.get(); val.isAbsoluteTimeValue(asecs); buffer.appendString("absTime(\""); Util.absTimeToString(asecs, buffer); buffer.appendString("\")"); return; } case RELATIVE_TIME_VALUE: { ClassAdTime rsecs = objectPool.classAdTimePool.get(); val.isRelativeTimeValue(rsecs); buffer.appendString("relTime(\""); Util.relTimeToString(rsecs.getRelativeTime(), buffer); buffer.appendString("\")"); return; } case CLASSAD_VALUE: { ClassAd ad = objectPool.classAdPool.get(); Map<CaseInsensitiveString, ExprTree> attrs = objectPool.strToExprPool.get(); val.isClassAdValue(ad); ad.getComponents(attrs, objectPool); unparseAux(buffer, attrs); return; } case SLIST_VALUE: case LIST_VALUE: { ExprList el = objectPool.exprListPool.get(); val.isListValue(el); unparseAux(buffer, el); return; } } }
From source file:org.apache.asterix.external.classad.ClassAdUnParser.java
/** * Unparse an expression//from www. j a va2s. c om * * @param buffer * The string to unparse to * @param expr * The expression to unparse * @throws HyracksDataException */ public void unparse(AMutableCharArrayString buffer, ExprTree tree) throws HyracksDataException { if (tree == null) { buffer.appendString("<error:null expr>"); return; } switch (tree.getKind()) { case LITERAL_NODE: { // value Value val = objectPool.valuePool.get(); AMutableNumberFactor factor = objectPool.numFactorPool.get(); ((Literal) tree.getTree()).getComponents(val, factor); unparseAux(buffer, val, factor.getFactor()); return; } case ATTRREF_NODE: { // string ExprTreeHolder expr = objectPool.mutableExprPool.get(); //needs initialization AMutableCharArrayString ref = objectPool.strPool.get(); MutableBoolean absolute = objectPool.boolPool.get(); ((AttributeReference) tree.getTree()).getComponents(expr, ref, absolute); unparseAux(buffer, expr, ref, absolute.booleanValue()); return; } case OP_NODE: { //string AMutableInt32 op = objectPool.int32Pool.get(); ExprTreeHolder t1 = objectPool.mutableExprPool.get(); ExprTreeHolder t2 = objectPool.mutableExprPool.get(); ExprTreeHolder t3 = objectPool.mutableExprPool.get(); ((Operation) tree.getTree()).getComponents(op, t1, t2, t3); unparseAux(buffer, op.getIntegerValue().intValue(), t1, t2, t3); return; } case FN_CALL_NODE: { // string AMutableCharArrayString fnName = objectPool.strPool.get(); ExprList args = objectPool.exprListPool.get(); ((FunctionCall) tree.getTree()).getComponents(fnName, args); unparseAux(buffer, fnName, args); return; } case CLASSAD_NODE: { // nested record Map<CaseInsensitiveString, ExprTree> attrs = objectPool.strToExprPool.get(); ((ClassAd) tree.getTree()).getComponents(attrs, objectPool); unparseAux(buffer, attrs); return; } case EXPR_LIST_NODE: { // list ExprList exprs = objectPool.exprListPool.get(); ((ExprList) tree.getTree()).getComponents(exprs); unparseAux(buffer, exprs); return; } default: // I really wonder whether we should except here, but I // don't want to do that without further consultation. // wenger 2003-12-11. buffer.setValue(""); throw new HyracksDataException("unknown expression type"); } }
From source file:org.apache.asterix.external.classad.ExprTree.java
public void debugFormatValue(Value value, double time) throws HyracksDataException { MutableBoolean boolValue = objectPool.boolPool.get(); AMutableInt64 intValue = objectPool.int64Pool.get(); AMutableDouble doubleValue = objectPool.doublePool.get(); AMutableCharArrayString stringValue = objectPool.strPool.get(); if (NodeKind.CLASSAD_NODE == getKind()) { return;/* w w w . jav a 2s .co m*/ } PrettyPrint unp = objectPool.prettyPrintPool.get(); AMutableCharArrayString buffer = objectPool.strPool.get(); unp.unparse(buffer, this); String result = "Classad debug: "; if (time != 0) { String buf = String.format("%5.5fms", time * 1000); result += "["; result += buf; result += "] "; } result += buffer; result += " --> "; switch (value.getType()) { case NULL_VALUE: result += "NULL\n"; break; case ERROR_VALUE: if ((NodeKind.FN_CALL_NODE == getKind()) && !((FunctionCall) (this)).functionIsDefined()) { result += "ERROR (function is not defined)\n"; } else { result += "ERROR\n"; } break; case UNDEFINED_VALUE: result += "UNDEFINED\n"; break; case BOOLEAN_VALUE: if (value.isBooleanValue(boolValue)) { result += boolValue.booleanValue() ? "TRUE\n" : "FALSE\n"; } break; case INTEGER_VALUE: if (value.isIntegerValue(intValue)) { result += String.format("%lld", intValue.getLongValue()); result += "\n"; } break; case REAL_VALUE: if (value.isRealValue(doubleValue)) { result += String.format("%lld", doubleValue.getDoubleValue()); result += "\n"; } break; case RELATIVE_TIME_VALUE: result += "RELATIVE TIME\n"; break; case ABSOLUTE_TIME_VALUE: result += "ABSOLUTE TIME\n"; break; case STRING_VALUE: if (value.isStringValue(stringValue)) { result += stringValue.toString(); result += "\n"; } break; case CLASSAD_VALUE: result += "CLASSAD\n"; break; case LIST_VALUE: result += "LIST\n"; break; case SLIST_VALUE: result += "SLIST\n"; break; } debugPrint(result); }
From source file:org.apache.asterix.external.classad.FunctionCall.java
@Override public boolean privateEvaluate(EvalState state, Value value, ExprTreeHolder tree) throws HyracksDataException { FunctionCall tmpSig = objectPool.funcPool.get(); Value tmpVal = objectPool.valuePool.get(); ExprTreeHolder argSig = objectPool.mutableExprPool.get(); MutableBoolean rval = objectPool.boolPool.get(); if (!privateEvaluate(state, value)) { return false; }// w ww . j a v a 2 s .c o m tmpSig.functionName.set(functionName.get()); rval.setValue(true); for (ExprTree i : arguments.getExprList()) { rval.setValue(i.publicEvaluate(state, tmpVal, argSig)); if (rval.booleanValue()) { tmpSig.arguments.add(argSig.getInnerTree()); } } tree.setInnerTree(tmpSig); return rval.booleanValue(); }
From source file:org.apache.asterix.external.classad.Operation.java
public static int privateDoOperation(int op, Value val1, Value val2, Value val3, boolean valid1, boolean valid2, boolean valid3, Value result, EvalState es, ClassAdObjectPool objectPool) throws HyracksDataException { ValueType vt1;/*from w ww. j av a2s. c o m*/ ValueType vt2; ValueType vt3; // get the types of the values vt1 = val1.getType(); vt2 = val2.getType(); vt3 = val3.getType(); // take care of the easy cases if (op == OpKind_NO_OP || op == OpKind_PARENTHESES_OP) { result.setValue(val1); return SigValues.SIG_CHLD1.ordinal(); } else if (op == OpKind_UNARY_PLUS_OP) { if (vt1 == ValueType.BOOLEAN_VALUE || vt1 == ValueType.STRING_VALUE || val1.isListValue() || vt1 == ValueType.CLASSAD_VALUE || vt1 == ValueType.ABSOLUTE_TIME_VALUE) { result.setErrorValue(); } else { // applies for ERROR, UNDEFINED and Numbers result.setValue(val1); } return SigValues.SIG_CHLD1.ordinal(); } // test for cases when evaluation is strict if (isStrictOperator(op)) { // check for error values if (vt1 == ValueType.ERROR_VALUE) { result.setErrorValue(); return SigValues.SIG_CHLD1.ordinal(); } if (valid2 && vt2 == ValueType.ERROR_VALUE) { result.setErrorValue(); return SigValues.SIG_CHLD2.ordinal(); } if (valid3 && vt3 == ValueType.ERROR_VALUE) { result.setErrorValue(); return SigValues.SIG_CHLD3.ordinal(); } // check for undefined values. we need to check if the corresponding // tree exists, because these values would be undefined" anyway then. if (valid1 && vt1 == ValueType.UNDEFINED_VALUE) { result.setUndefinedValue(); return SigValues.SIG_CHLD1.ordinal(); } if (valid2 && vt2 == ValueType.UNDEFINED_VALUE) { result.setUndefinedValue(); return SigValues.SIG_CHLD2.ordinal(); } if (valid3 && vt3 == ValueType.UNDEFINED_VALUE) { result.setUndefinedValue(); return SigValues.SIG_CHLD3.ordinal(); } } // comparison operations (binary, one unary) if (op >= OpKind_COMPARISON_START && op <= OpKind_COMPARISON_END) { return (doComparison(op, val1, val2, result, objectPool)); } // arithmetic operations (binary) if (op >= OpKind_ARITHMETIC_START && op <= OpKind_ARITHMETIC_END) { return (doArithmetic(op, val1, val2, result, objectPool)); } // logical operators (binary, one unary) if (op >= OpKind_LOGIC_START && op <= OpKind_LOGIC_END) { return (doLogical(op, val1, val2, result, objectPool)); } // bitwise operators (binary, one unary) if (op >= OpKind_BITWISE_START && op <= OpKind_BITWISE_END) { return (doBitwise(op, val1, val2, result, objectPool)); } // misc. if (op == OpKind_TERNARY_OP) { // ternary (if-operator) MutableBoolean b = objectPool.boolPool.get(); // if the selector is UNDEFINED, the result is undefined if (vt1 == ValueType.UNDEFINED_VALUE) { result.setUndefinedValue(); return SigValues.SIG_CHLD1.ordinal(); } if (!val1.isBooleanValueEquiv(b)) { result.setErrorValue(); return SigValues.SIG_CHLD1.ordinal(); } else if (b.booleanValue()) { result.setValue(val2); return (SigValues.SIG_CHLD2.ordinal()); } else { result.setValue(val3); return (SigValues.SIG_CHLD3.ordinal()); } } else if (op == OpKind_SUBSCRIPT_OP) { // subscripting from a list (strict) if (vt1 == ValueType.CLASSAD_VALUE && vt2 == ValueType.STRING_VALUE) { ClassAd classad = objectPool.classAdPool.get(); AMutableCharArrayString index = objectPool.strPool.get(); val1.isClassAdValue(classad); val2.isStringValue(index); if (classad.lookup(index.toString()) == null) { result.setErrorValue(); return SigValues.SIG_CHLD2.ordinal(); } if (!classad.evaluateAttr(index.toString(), result)) { result.setErrorValue(); return SigValues.SIG_CHLD2.ordinal(); } return (SigValues.SIG_CHLD1.ordinal() | SigValues.SIG_CHLD2.ordinal()); } else if (val1.isListValue() && vt2 == ValueType.INTEGER_VALUE) { AMutableInt64 index = objectPool.int64Pool.get(); ExprList elist = objectPool.exprListPool.get(); val1.isListValue(elist); val2.isIntegerValue(index); // check bounds if (index.getLongValue() < 0 || index.getLongValue() >= elist.getExprList().size()) { result.setErrorValue(); return SigValues.SIG_CHLD2.ordinal(); } // get value elist.getValue(result, elist.get((int) index.getLongValue()), es); return (SigValues.SIG_CHLD1.ordinal() | SigValues.SIG_CHLD2.ordinal()); } // should not reach here throw new HyracksDataException("Should not get here"); } return -1; }
From source file:org.apache.asterix.external.classad.Operation.java
public boolean shortCircuit(EvalState state, Value arg1, Value result) throws HyracksDataException { MutableBoolean arg1_bool = objectPool.boolPool.get(); switch (opKind) { case OpKind_LOGICAL_OR_OP: if (arg1.isBooleanValueEquiv(arg1_bool) && arg1_bool.booleanValue()) { result.setBooleanValue(true); return true; }/*from w ww.ja va 2s . c o m*/ break; case OpKind_LOGICAL_AND_OP: if (arg1.isBooleanValueEquiv(arg1_bool) && !arg1_bool.booleanValue()) { result.setBooleanValue(false); return true; } break; case OpKind_TERNARY_OP: if (arg1.isBooleanValueEquiv(arg1_bool)) { if (arg1_bool.booleanValue()) { if (child2 != null) { return child2.publicEvaluate(state, result); } } else { if (child3 != null) { return child3.publicEvaluate(state, result); } } } break; default: // no-op break; } return false; }