Example usage for org.apache.commons.lang3.mutable MutableBoolean MutableBoolean

List of usage examples for org.apache.commons.lang3.mutable MutableBoolean MutableBoolean

Introduction

In this page you can find the example usage for org.apache.commons.lang3.mutable MutableBoolean MutableBoolean.

Prototype

public MutableBoolean() 

Source Link

Document

Constructs a new MutableBoolean with the default value of false.

Usage

From source file:asterix.parser.classad.test.ClassAdUnitTester.java

/*********************************************************************
 * Function: test_value//  w w  w .j a v  a 2  s  .  c  o m
 * Purpose: Test the Value class.
 * 
 * @throws HyracksDataException
 *********************************************************************/
public static void testValue(Parameters parameters, Results results) throws HyracksDataException {
    Value v = new Value();
    boolean isExpectedType;
    System.out.println("Testing the Value class...");
    test("New value is undefined", (v.isUndefinedValue()), "test_value 1", results);
    test("New value isn't boolean", !(v.isBooleanValue()), "test_value 2", results);
    test("GetType gives UNDEFINED_VALUE", (v.getType() == ValueType.UNDEFINED_VALUE), "test_value 3", results);

    v.setErrorValue();
    test("Is error value", (v.isErrorValue()), "test_value 4", results);
    test("GetType gives ERROR_VALUE", (v.getType() == ValueType.ERROR_VALUE), "test_value 5", results);

    MutableBoolean b = new MutableBoolean();
    v.setBooleanValue(true);
    isExpectedType = v.isBooleanValue(b);
    test("Value is not undefined", !(v.isUndefinedValue()), "Value is not undefined", results);
    test("Value is boolean", (v.isBooleanValue()), "Value is boolean", results);
    test("Try 2: New value is boolean", (isExpectedType == true), "Try 2: New value is boolean", results);
    test("Boolean is true", (b.booleanValue() == true), "Boolean is true", results);
    test("GetType gives BOOLEAN_VALUE", (v.getType() == ValueType.BOOLEAN_VALUE), "GetType gives BOOLEAN_VALUE",
            results);

    AMutableDouble r = new AMutableDouble(0.0);
    v.setRealValue(1.0);
    isExpectedType = v.isRealValue(r);
    test("Value is real", isExpectedType, results);
    test("Real is 1.0", (r.getDoubleValue() == 1.0), results);
    test("GetType gives REAL_VALUE", (v.getType() == ValueType.REAL_VALUE), results);
    test("Real is a number", v.isNumber(), results);

    AMutableInt64 i = new AMutableInt64(0);
    v.setIntegerValue(1);
    isExpectedType = v.isIntegerValue(i);
    test("Value is integer", isExpectedType, results);
    test("Integer is 1", (i.getLongValue() == 1), results);
    test("GetType gives INTEGER_VALUE", (v.getType() == ValueType.INTEGER_VALUE), results);
    test("Integer is a number", v.isNumber(), results);

    AMutableCharArrayString s = new AMutableCharArrayString();
    v.setStringValue("Robert-Houdin");
    isExpectedType = v.isStringValue(s);
    test("Value is String", isExpectedType, results);
    test("String is 'Robert-Houdin'", (0 == s.compareTo("Robert-Houdin")), results);
    test("GetType gives STRING_VALUE", (v.getType() == ValueType.STRING_VALUE), results);

    ClassAdTime at = new ClassAdTime(10, 36000000);
    v.setAbsoluteTimeValue(at);
    at.setValue(0);
    at.setTimeZone(0);
    isExpectedType = v.isAbsoluteTimeValue(at);
    test("Value is absolute time", isExpectedType, results);
    test("Absolute time is 10, 0", (10 == at.getTime() && 36000000 == at.getOffset()), results);
    test("GetType gives ABSOLUTE_TIME_VALUE", (v.getType() == ValueType.ABSOLUTE_TIME_VALUE), results);

    ClassAdTime rt = new ClassAdTime(10, false);
    v.setRelativeTimeValue(10);
    isExpectedType = v.isRelativeTimeValue(rt);
    test("Value is relative time", isExpectedType, results);
    test("Relative time is 10", (10 == rt.getRelativeTime()), results);
    test("GetType gives RELATIVE_TIME_VALUE", (v.getType() == ValueType.RELATIVE_TIME_VALUE), results);

    ExprList l = new ExprList();
    ExprList ll = new ExprList();
    v.setListValue(l);
    isExpectedType = v.isListValue(ll);
    test("Value is list value", isExpectedType, results);
    test("List value is correct", l.equals(ll), results);
    test("GetType gives LIST_VALUE", (v.getType() == ValueType.LIST_VALUE), results);

    ExprList sl = new ExprList(true);
    ll = new ExprList(true);
    v.setListValue(sl);
    isExpectedType = v.isListValue(ll);
    test("Value is list value", isExpectedType, results);
    test("List value is correct", sl.equals(ll), results);
    test("GetType gives SLIST_VALUE", (v.getType() == ValueType.SLIST_VALUE), results);

    ClassAd c = new ClassAd();
    c.insertAttr("test_int", 10);
    ClassAd cc = new ClassAd();
    v.setClassAdValue(c);
    isExpectedType = v.isClassAdValue(cc);
    test("Value is ClassAd value", isExpectedType, results);
    test("ClassAd value is correct", c.equals(cc), results);
    test("GetType gives CLASSAD_VALUE", (v.getType() == ValueType.CLASSAD_VALUE), results);
    return;
}

From source file:de.uni_potsdam.hpi.asg.logictool.mapping.SequenceBasedAndGateDecomposer.java

private boolean categoriseSequences(BDD bdd, SortedSet<IOBehaviour> sequences, List<IOBehaviour> falling,
        List<IOBehaviour> rising, List<IOBehaviour> constant) {
    for (IOBehaviour beh : sequences) {
        BDD startBDD = bdd;/*from  w  ww. j ava 2  s. com*/
        MutableBoolean resultStart = new MutableBoolean();
        if (!evaluateBDD(resultStart, startBDD, beh.getStart())) {
            logger.error("Something went wrong");
            return false;
        }
        BDD endBDD = bdd;
        MutableBoolean resultEnd = new MutableBoolean();
        if (!evaluateBDD(resultEnd, endBDD, beh.getEnd())) {
            logger.error("Something went wrong");
            return false;
        }

        if (resultStart.isTrue() && resultEnd.isFalse()) {
            falling.add(beh);
            //System.out.println("uups? falling?");
        } else if (resultStart.isFalse() && resultEnd.isTrue()) {
            rising.add(beh);
        } else if (resultStart.isFalse() && resultEnd.isFalse()) {
            constant.add(beh);
        } else {
            logger.error("Const 1 should not happen");
            return false;
        }
        //System.out.println(resultStart.booleanValue() + "=>" + resultEnd.booleanValue() + " : " + beh);
    }
    return true;
}

From source file:asterix.parser.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();
    }/*  w  w w  . jav a 2 s . c o  m*/
    switch (expr.getKind()) {
    case LITERAL_NODE:
        // no external references here
        return (true);

    case ATTRREF_NODE: {
        ClassAd start = new ClassAd();
        ExprTreeHolder tree = new ExprTreeHolder();
        ExprTreeHolder result = new ExprTreeHolder();
        AMutableCharArrayString attr = new AMutableCharArrayString();
        Value val = new Value();
        MutableBoolean abs = new MutableBoolean();

        ((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 = new AMutableCharArrayString();
                    if (tree.getInnerTree() != null) {
                        ClassAdUnParser unparser = new PrettyPrint();
                        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 = new AMutableInt32(0);
        ExprTreeHolder t1 = new ExprTreeHolder();
        ExprTreeHolder t2 = new ExprTreeHolder();
        ExprTreeHolder t3 = new ExprTreeHolder();

        ((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 = new AMutableCharArrayString();
        ExprList args = new ExprList();
        ((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 = new HashMap<CaseInsensitiveString, ExprTree>();
        ((ClassAd) expr).getComponents(attrs);
        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 = new ExprList();

        ((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:asterix.parser.classad.Operation.java

public static int doArithmetic(int op, Value v1, Value v2, Value result) throws HyracksDataException {
    AMutableInt64 i1 = new AMutableInt64(0);
    AMutableInt64 i2 = new AMutableInt64(0);
    ClassAdTime t1 = new ClassAdTime();
    AMutableDouble r1 = new AMutableDouble(0);
    MutableBoolean b1 = new MutableBoolean();

    // ensure the operands have arithmetic types
    if ((!v1.isIntegerValue() && !v1.isRealValue() && !v1.isAbsoluteTimeValue() && !v1.isRelativeTimeValue()
            && !v1.isBooleanValue())
            || (op != OpKind_UNARY_MINUS_OP && !v2.isBooleanValue() && !v2.isIntegerValue() && !v2.isRealValue()
                    && !v2.isAbsoluteTimeValue() && !v2.isRelativeTimeValue())) {
        result.setErrorValue();//from  ww w  . j a va 2 s  .c  o  m
        return (SigValues.SIG_CHLD1.ordinal() | SigValues.SIG_CHLD2.ordinal());
    }

    // take care of the unary arithmetic operators
    if (op == OpKind_UNARY_MINUS_OP) {
        if (v1.isIntegerValue(i1)) {
            result.setIntegerValue((-1L) * i1.getLongValue());
            return SigValues.SIG_CHLD1.ordinal();
        } else if (v1.isRealValue(r1)) {
            result.setRealValue((-1) * r1.getDoubleValue());
            return SigValues.SIG_CHLD1.ordinal();
        } else if (v1.isRelativeTimeValue(t1)) {
            t1.setValue((-1) * t1.getTimeInMillis());
            result.setRelativeTimeValue(t1);
            return (SigValues.SIG_CHLD1.ordinal());
        } else if (v1.isBooleanValue(b1)) {
            result.setBooleanValue(!b1.booleanValue());
        } else if (v1.isExceptional()) {
            // undefined or error --- same as operand
            result.copyFrom(v1);
            return SigValues.SIG_CHLD1.ordinal();
        }
        // unary minus not defined on any other operand type
        result.setErrorValue();
        return (SigValues.SIG_CHLD1.ordinal());
    }

    // perform type promotions and proceed with arithmetic
    switch (coerceToNumber(v1, v2)) {
    case INTEGER_VALUE:
        v1.isIntegerValue(i1);
        v2.isIntegerValue(i2);
        switch (op) {
        case OpKind_ADDITION_OP:
            result.setIntegerValue(i1.getLongValue() + i2.getLongValue());
            return (SigValues.SIG_CHLD1.ordinal() | SigValues.SIG_CHLD2.ordinal());

        case OpKind_SUBTRACTION_OP:
            result.setIntegerValue(i1.getLongValue() - i2.getLongValue());
            return (SigValues.SIG_CHLD1.ordinal() | SigValues.SIG_CHLD2.ordinal());

        case OpKind_MULTIPLICATION_OP:
            result.setIntegerValue(i1.getLongValue() * i2.getLongValue());
            return (SigValues.SIG_CHLD1.ordinal() | SigValues.SIG_CHLD2.ordinal());

        case OpKind_DIVISION_OP:
            if (i2.getLongValue() != 0L) {
                result.setIntegerValue(i1.getLongValue() / i2.getLongValue());
            } else {
                result.setErrorValue();
            }
            return (SigValues.SIG_CHLD1.ordinal() | SigValues.SIG_CHLD2.ordinal());

        case OpKind_MODULUS_OP:
            if (i2.getLongValue() != 0) {
                result.setIntegerValue(i1.getLongValue() % i2.getLongValue());
            } else {
                result.setErrorValue();
            }
            return (SigValues.SIG_CHLD1.ordinal() | SigValues.SIG_CHLD2.ordinal());

        default:
            // should not reach here
            throw new HyracksDataException("Should not get here");
        }

    case REAL_VALUE: {
        return (doRealArithmetic(op, v1, v2, result));
    }
    case ABSOLUTE_TIME_VALUE:
    case RELATIVE_TIME_VALUE: {
        return (doTimeArithmetic(op, v1, v2, result));
    }
    default:
        // should not get here
        throw new HyracksDataException("Should not get here");
    }
}

From source file:asterix.parser.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 = new ClassAd();
        ExprTreeHolder tree = new ExprTreeHolder();
        ExprTreeHolder result = new ExprTreeHolder();
        AMutableCharArrayString attr = new AMutableCharArrayString();
        Value val = new Value();
        MutableBoolean abs = new MutableBoolean();

        ((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 {/*w  ww.jav a 2s.c o m*/
            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 = new TreeSet<String>();
            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 = new AMutableInt32(0);
        ExprTreeHolder t1 = new ExprTreeHolder();
        ExprTreeHolder t2 = new ExprTreeHolder();
        ExprTreeHolder t3 = new ExprTreeHolder();
        ((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 = new AMutableCharArrayString();
        ExprList args = new ExprList();

        ((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 = new HashMap<CaseInsensitiveString, ExprTree>();

        ((ClassAd) expr).getComponents(attrs);
        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 = new ExprList();
        ((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:asterix.parser.classad.Operation.java

public static int doLogical(int op, Value v1, Value v2, Value result) throws HyracksDataException {
    MutableBoolean b1 = new MutableBoolean();
    MutableBoolean b2 = new MutableBoolean();

    // first coerece inputs to boolean if they are considered equivalent
    if (!v1.isBooleanValue(b1) && v1.isBooleanValueEquiv(b1)) {
        v1.setBooleanValue(b1.booleanValue());
    }// w  w w .  ja va  2s . co  m
    if (!v2.isBooleanValue(b2) && v2.isBooleanValueEquiv(b2)) {
        v2.setBooleanValue(b2);
    }

    ValueType vt1 = v1.getType();
    ValueType vt2 = v2.getType();

    if (vt1 != ValueType.UNDEFINED_VALUE && vt1 != ValueType.ERROR_VALUE && vt1 != ValueType.BOOLEAN_VALUE) {
        result.setErrorValue();
        return SigValues.SIG_CHLD1.ordinal();
    }
    if (vt2 != ValueType.UNDEFINED_VALUE && vt2 != ValueType.ERROR_VALUE && vt2 != ValueType.BOOLEAN_VALUE) {
        result.setErrorValue();
        return SigValues.SIG_CHLD2.ordinal();
    }

    // handle unary operator
    if (op == OpKind_LOGICAL_NOT_OP) {
        if (vt1 == ValueType.BOOLEAN_VALUE) {
            result.setBooleanValue(!b1.booleanValue());
        } else {
            result.copyFrom(v1);
        }
        return SigValues.SIG_CHLD1.ordinal();
    }

    if (op == OpKind_LOGICAL_OR_OP) {
        if (vt1 == ValueType.BOOLEAN_VALUE && b1.booleanValue()) {
            result.setBooleanValue(true);
            return SigValues.SIG_CHLD1.ordinal();
        } else if (vt1 == ValueType.ERROR_VALUE) {
            result.setErrorValue();
            return SigValues.SIG_CHLD1.ordinal();
        } else if (vt1 == ValueType.BOOLEAN_VALUE && !b1.booleanValue()) {
            result.copyFrom(v2);
        } else if (vt2 != ValueType.BOOLEAN_VALUE) {
            result.copyFrom(v2);
        } else if (b2.booleanValue()) {
            result.setBooleanValue(true);
        } else {
            result.setUndefinedValue();
        }
        return (SigValues.SIG_CHLD1.ordinal() | SigValues.SIG_CHLD2.ordinal());
    } else if (op == OpKind_LOGICAL_AND_OP) {
        if (vt1 == ValueType.BOOLEAN_VALUE && !b1.booleanValue()) {
            result.setBooleanValue(false);
            return SigValues.SIG_CHLD1.ordinal();
        } else if (vt1 == ValueType.ERROR_VALUE) {
            result.setErrorValue();
            return SigValues.SIG_CHLD1.ordinal();
        } else if (vt1 == ValueType.BOOLEAN_VALUE && b1.booleanValue()) {
            result.copyFrom(v2);
        } else if (vt2 != ValueType.BOOLEAN_VALUE) {
            result.copyFrom(v2);
        } else if (!b2.booleanValue()) {
            result.setBooleanValue(false);
        } else {
            result.setUndefinedValue();
        }
        return (SigValues.SIG_CHLD1.ordinal() | SigValues.SIG_CHLD2.ordinal());
    }

    throw new HyracksDataException("Shouldn't reach here");
}

From source file:asterix.parser.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;
    }/*w  w  w  . j  a  v a2 s.c  o  m*/

    case ATTRREF_NODE: {
        ClassAd start = new ClassAd();
        ExprTreeHolder tree = new ExprTreeHolder();
        ExprTreeHolder result = new ExprTreeHolder();
        AMutableCharArrayString attr = new AMutableCharArrayString();
        Value val = new Value();
        MutableBoolean abs = new MutableBoolean();

        ((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 = new AMutableInt32(0);
        ExprTreeHolder t1 = new ExprTreeHolder();
        ExprTreeHolder t2 = new ExprTreeHolder();
        ExprTreeHolder t3 = new ExprTreeHolder();
        ((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 = new AMutableCharArrayString();
        ExprList args = new ExprList();

        ((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 = new HashMap<CaseInsensitiveString, ExprTree>();

        // 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);
        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 = new ExprList();

        ((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:asterix.parser.classad.Operation.java

public static void compareBools(int op, Value v1, Value v2, Value result) throws HyracksDataException {
    MutableBoolean b1 = new MutableBoolean();
    MutableBoolean b2 = new MutableBoolean();
    boolean compResult = false;
    v1.isBooleanValue(b1);// w w w. ja v a 2  s  .co m
    v2.isBooleanValue(b2);

    switch (op) {
    case OpKind_LESS_THAN_OP:
        compResult = (b1.compareTo(b2) < 0);
        break;
    case OpKind_LESS_OR_EQUAL_OP:
        compResult = (b1.compareTo(b2) <= 0);
        break;
    case OpKind_EQUAL_OP:
        compResult = (b1.booleanValue() == b2.booleanValue());
        break;
    case OpKind_META_EQUAL_OP:
        compResult = (b1.booleanValue() == b2.booleanValue());
        break;
    case OpKind_NOT_EQUAL_OP:
        compResult = (b1.booleanValue() != b2.booleanValue());
        break;
    case OpKind_META_NOT_EQUAL_OP:
        compResult = (b1.booleanValue() != b2.booleanValue());
        break;
    case OpKind_GREATER_THAN_OP:
        compResult = (b1.compareTo(b2) > 0);
        break;
    case OpKind_GREATER_OR_EQUAL_OP:
        compResult = (b1.compareTo(b2) >= 0);
        break;
    default:
        // should not get here
        throw new HyracksDataException("Should not get here");
    }
    result.setBooleanValue(compResult);
}

From source file:asterix.parser.classad.ClassAdParser.java

private boolean parsePrimaryExpression(ExprTreeHolder tree) throws IOException {
    ExprTreeHolder treeL;/*from   w w w . ja  v a 2s . c o m*/
    TokenValue tv = tokenValuePool.get();
    TokenType tt;
    tree.setInnerTree(null);
    switch ((tt = lexer.peekToken(tv))) {
    // identifiers
    case LEX_IDENTIFIER:
        isExpr = true;
        lexer.consumeToken();
        // check for funcion call
        if ((tt = lexer.peekToken()) == TokenType.LEX_OPEN_PAREN) {
            ExprList argList = exprListPool.get();
            if (!parseArgumentList(argList)) {
                tree.setInnerTree(null);
                return false;
            }
            ;
            // special case function-calls should be converted
            // into a literal expression if the argument is a
            // string literal
            if (shouldEvaluateAtParseTime(tv.getStrValue().toString(), argList)) {
                tree.setInnerTree(evaluateFunction(tv.getStrValue().toString(), argList));
            } else {
                tree.setInnerTree(FunctionCall.createFunctionCall(tv.getStrValue().toString(), argList));
            }
        } else {
            // I don't think this is ever hit
            tree.setInnerTree(AttributeReference.createAttributeReference(null, tv.getStrValue(), false));
        }
        return (tree.getInnerTree() != null);
    case LEX_SELECTION:
        isExpr = true;
        lexer.consumeToken();
        if ((tt = lexer.consumeToken(tv)) == TokenType.LEX_IDENTIFIER) {
            // the boolean final arg signifies that reference is absolute
            tree.setInnerTree(AttributeReference.createAttributeReference(null, tv.getStrValue(), true));
            return (tree.size() != 0);
        }
        // not an identifier following the '.'
        throw new HyracksDataException(
                "need identifier in selection expression (got" + Lexer.strLexToken(tt) + ")");
        // parenthesized expression
    case LEX_OPEN_PAREN: {
        isExpr = true;
        lexer.consumeToken();
        treeL = mutableExprPool.get();
        parseExpression(treeL);
        if (treeL.getInnerTree() == null) {
            tree.resetExprTree(null);
            return false;
        }

        if ((tt = lexer.consumeToken()) != TokenType.LEX_CLOSE_PAREN) {
            throw new HyracksDataException("exptected LEX_CLOSE_PAREN, but got " + Lexer.strLexToken(tt));
            // tree.resetExprTree(null);
            // return false;
        }
        // assume make operation will return a new tree
        tree.setInnerTree(Operation.createOperation(Operation.OpKind_PARENTHESES_OP, treeL));
        return (tree.size() != 0);
    }
    // constants
    case LEX_OPEN_BOX: {
        isExpr = true;
        ClassAd newAd = classAdPool.get();
        if (!parseClassAd(newAd)) {
            tree.resetExprTree(null);
            return false;
        }
        tree.setInnerTree(newAd);
    }
        return true;

    case LEX_OPEN_BRACE: {
        isExpr = true;
        ExprList newList = exprListPool.get();
        if (!parseExprList(newList)) {
            tree.setInnerTree(null);
            return false;
        }
        tree.setInnerTree(newList);
    }
        return true;

    case LEX_UNDEFINED_VALUE: {
        Value val = valuePool.get();
        lexer.consumeToken();
        val.setUndefinedValue();
        tree.setInnerTree(Literal.createLiteral(val));
        return (tree.getInnerTree() != null);
    }
    case LEX_ERROR_VALUE: {
        Value val = valuePool.get();
        lexer.consumeToken();
        val.setErrorValue();
        tree.setInnerTree(Literal.createLiteral(val));
        return (tree.getInnerTree() != null);
    }
    case LEX_BOOLEAN_VALUE: {
        Value val = valuePool.get();
        MutableBoolean b = new MutableBoolean();
        tv.getBoolValue(b);
        lexer.consumeToken();
        val.setBooleanValue(b);
        tree.setInnerTree(Literal.createLiteral(val));
        return (tree.getInnerTree() != null);
    }

    case LEX_INTEGER_VALUE: {
        Value val = valuePool.get();
        lexer.consumeToken();
        val.setIntegerValue(tv.getIntValue());
        tree.setInnerTree(Literal.createLiteral(val, tv.getFactor()));
        return (tree.getInnerTree() != null);
    }

    case LEX_REAL_VALUE: {
        Value val = valuePool.get();
        lexer.consumeToken();
        val.setRealValue(tv.getRealValue());
        tree.setInnerTree(Literal.createLiteral(val, tv.getFactor()));
        return (tree.getInnerTree() != null);
    }

    case LEX_STRING_VALUE: {
        Value val = valuePool.get();
        lexer.consumeToken();
        val.setStringValue(tv.getStrValue());
        tree.setInnerTree(Literal.createLiteral(val));
        return (tree.getInnerTree() != null);
    }

    case LEX_ABSOLUTE_TIME_VALUE: {
        Value val = valuePool.get();
        lexer.consumeToken();
        val.setAbsoluteTimeValue(tv.getTimeValue());
        tree.setInnerTree(Literal.createLiteral(val));
        return (tree.getInnerTree() != null);
    }

    case LEX_RELATIVE_TIME_VALUE: {
        Value val = valuePool.get();
        lexer.consumeToken();
        val.setRelativeTimeValue(tv.getTimeValue().getRelativeTime());
        tree.setInnerTree(Literal.createLiteral(val));
        return (tree.getInnerTree() != null);
    }

    default:
        tree.setInnerTree(null);
        return false;
    }
}

From source file:asterix.parser.classad.Operation.java

public static ValueType coerceToNumber(Value v1, Value v2) {
    AMutableInt64 i = new AMutableInt64(0);
    AMutableDouble r = new AMutableDouble(0);
    MutableBoolean b = new MutableBoolean();

    // either of v1, v2 not numerical?
    if (v1.isClassAdValue() || v2.isClassAdValue())
        return ValueType.CLASSAD_VALUE;
    if (v1.isListValue() || v2.isListValue())
        return ValueType.LIST_VALUE;
    if (v1.isStringValue() || v2.isStringValue())
        return ValueType.STRING_VALUE;
    if (v1.isUndefinedValue() || v2.isUndefinedValue())
        return ValueType.UNDEFINED_VALUE;
    if (v1.isErrorValue() || v2.isErrorValue())
        return ValueType.ERROR_VALUE;
    if (v1.isAbsoluteTimeValue() || v2.isAbsoluteTimeValue())
        return ValueType.ABSOLUTE_TIME_VALUE;
    if (v1.isRelativeTimeValue() || v2.isRelativeTimeValue())
        return ValueType.RELATIVE_TIME_VALUE;

    // promote booleans to integers
    if (v1.isBooleanValue(b)) {
        if (b.booleanValue()) {
            v1.setIntegerValue(1);/*from   www  .j a v a  2  s .  c o m*/
        } else {
            v1.setIntegerValue(0);
        }
    }

    if (v2.isBooleanValue(b)) {
        if (b.booleanValue()) {
            v2.setIntegerValue(1);
        } else {
            v2.setIntegerValue(0);
        }
    }

    // both v1 and v2 of same numerical type
    if (v1.isIntegerValue(i) && v2.isIntegerValue(i))
        return ValueType.INTEGER_VALUE;
    if (v1.isRealValue(r) && v2.isRealValue(r))
        return ValueType.REAL_VALUE;

    // type promotions required
    if (v1.isIntegerValue(i) && v2.isRealValue(r))
        v1.setRealValue((double) i.getLongValue());
    else if (v1.isRealValue(r) && v2.isIntegerValue(i))
        v2.setRealValue((double) i.getLongValue());

    return ValueType.REAL_VALUE;
}