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.Operation.java

public boolean flattenSpecials(EvalState state, Value val, ExprTreeHolder tree) throws HyracksDataException {
    ExprTreeHolder fChild1 = new ExprTreeHolder();
    ExprTreeHolder fChild2 = new ExprTreeHolder();
    ExprTreeHolder fChild3 = new ExprTreeHolder();
    Value eval1 = new Value();
    Value eval2 = new Value();
    Value eval3 = new Value();

    switch (opKind) {
    case OpKind_UNARY_PLUS_OP:
    case OpKind_UNARY_MINUS_OP:
    case OpKind_PARENTHESES_OP:
    case OpKind_LOGICAL_NOT_OP:
    case OpKind_BITWISE_NOT_OP:
        if (!child1.publicFlatten(state, eval1, fChild1)) {
            tree.setInnerTree(null);/*from w w  w  . j a va  2  s  . c om*/
            return false;
        }
        if (fChild1.getInnerTree() != null) {
            tree.setInnerTree(Operation.createOperation(opKind, fChild1));
            return (tree.getInnerTree() != null);
        } else {
            privateDoOperation(opKind, eval1, null, null, true, false, false, val);
            tree.setInnerTree(null);
            eval1.clear();
            return true;
        }
    case OpKind_TERNARY_OP:
        // Flatten the selector expression
        if (!child1.publicFlatten(state, eval1, fChild1)) {
            tree.setInnerTree(null);
            return false;
        }

        // check if selector expression collapsed to a non-undefined value
        if (fChild1.getInnerTree() == null && !eval1.isUndefinedValue()) {
            MutableBoolean b = new MutableBoolean();
            // if the selector is not boolean-equivalent, propagate error
            if (!eval1.isBooleanValueEquiv(b)) {
                val.setErrorValue();
                eval1.clear();
                tree.setInnerTree(null);
                return true;
            }

            // eval1 is either a real or an integer
            if (b.booleanValue()) {
                return child2.publicFlatten(state, val, tree);
            } else {
                return child3.publicFlatten(state, val, tree);
            }
        } else {
            // Flatten arms of the if expression
            if (!child2.publicFlatten(state, eval2, fChild2) || !child3.publicFlatten(state, eval3, fChild3)) {
                // clean up
                tree.setInnerTree(null);
                return false;
            }

            // if any arm collapsed into a value, make it a Literal
            if (fChild2.getInnerTree() == null)
                fChild2.setInnerTree(Literal.createLiteral(eval2));
            if (fChild3.getInnerTree() == null)
                fChild3.setInnerTree(Literal.createLiteral(eval3));
            if (fChild2.getInnerTree() == null || fChild3.getInnerTree() == null) {
                tree.setInnerTree(null);
                ;
                return false;
            }

            // fChild1 may be NULL if child1 Flattened to UNDEFINED
            if (fChild1.getInnerTree() == null) {
                fChild1.setInnerTree(child1.copy());
            }

            tree.setInnerTree(Operation.createOperation(opKind, fChild1, fChild2, fChild3));
            if (tree.getInnerTree() == null) {
                return false;
            }
            return true;
        }
    case OpKind_SUBSCRIPT_OP:
        // Flatten both arguments
        if (!child1.publicFlatten(state, eval1, fChild1) || !child2.publicFlatten(state, eval2, fChild2)) {
            tree.setInnerTree(null);
            return false;
        }

        // if both arguments Flattened to values, Evaluate now
        if (fChild1.getInnerTree() == null && fChild2.getInnerTree() == null) {
            privateDoOperation(opKind, eval1, eval2, null, true, true, false, val);
            tree.setInnerTree(null);
            return true;
        }

        // otherwise convert Flattened values into literals
        if (fChild1.getInnerTree() == null)
            fChild1.setInnerTree(Literal.createLiteral(eval1));
        if (fChild2.getInnerTree() == null)
            fChild2.setInnerTree(Literal.createLiteral(eval2));
        if (fChild1.getInnerTree() == null || fChild2.getInnerTree() == null) {
            tree.setInnerTree(null);
            return false;
        }

        tree.setInnerTree(Operation.createOperation(opKind, fChild1, fChild2));
        if (tree.getInnerTree() == null) {
            return false;
        }
        return true;

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

From source file:nl.b3p.viewer.config.services.ArcGISService.java

private void updateLayers(final ArcGISService update, final ArcGISFeatureSource linkedFS,
        final UpdateResult result) {
    /* This is a lot simpler than WMS, because layers always have an id
     * (name in WMS and our Layer object)
     *//*from www. jav a 2  s  .c  o  m*/

    Map<String, Layer> updatedLayersById = new HashMap();

    SimpleFeatureType ft;

    for (Layer updateLayer : update.layersById.values()) {

        MutablePair<Layer, UpdateResult.Status> layerStatus = result.getLayerStatus()
                .get(updateLayer.getName());
        Layer updatedLayer = null;

        if (layerStatus == null) {
            // New layer
            ft = updateLayer.getFeatureType();
            if (updateLayer.getFeatureType() != null) {

                if (linkedFS != null) {
                    updateLayer.setFeatureType(
                            linkedFS.addOrUpdateFeatureType(updateLayer.getName(), ft, new MutableBoolean()));
                } else {
                    // New FeatureSource to be persisted
                    ft.getFeatureSource().setLinkedService(this);
                }
            }

            result.getLayerStatus().put(updateLayer.getName(),
                    new MutablePair(updateLayer, UpdateResult.Status.NEW));

            updatedLayer = updateLayer;
        } else {

            assert (layerStatus.getRight() == UpdateResult.Status.MISSING);

            Layer old = layerStatus.getLeft();

            old.setParent(null);
            old.update(updateLayer, additionalUpdatableDetails);

            layerStatus.setRight(UpdateResult.Status.UNMODIFIED);

            // Do not overwrite manually set feature source
            if (old.getFeatureType() == null
                    || old.getFeatureType().getFeatureSource().getLinkedService() == this) {
                if (updateLayer.getFeatureType() == null) {
                    // If was set before the old feature type will be removed 
                    // later when all orphan MISSING layers are removed
                    if (old.getFeatureType() != null) {
                        layerStatus.setRight(UpdateResult.Status.UPDATED);
                    }
                    old.setFeatureType(null);
                } else {
                    if (linkedFS != null) {
                        MutableBoolean updated = new MutableBoolean(false);
                        ft = linkedFS.addOrUpdateFeatureType(updateLayer.getName(),
                                updateLayer.getFeatureType(), updated);
                        if (old.getFeatureType() == null || updated.isTrue()) {
                            layerStatus.setRight(UpdateResult.Status.UPDATED);
                        }
                    } else {
                        ft = updateLayer.getFeatureType();
                        // New FeatureSource to be persisted
                        ft.getFeatureSource().setLinkedService(this);
                        layerStatus.setRight(UpdateResult.Status.UPDATED);
                    }
                    old.setFeatureType(ft);
                }
            }

            updatedLayer = old;
        }

        // will be filled in setLayerTree()                
        updatedLayer.getChildren().clear();
        updatedLayer.setParent(null);

        updatedLayer.setService(this);

        updatedLayersById.put(updateLayer.getName(), updatedLayer);
    }

    setLayerTree(getTopLayer(), updatedLayersById, update.childrenByLayerId);
}

From source file:nl.b3p.viewer.config.services.ArcIMSService.java

private void updateLayers(final ArcIMSService update, final ArcXMLFeatureSource linkedFS,
        final UpdateResult result) {
    /* This is a lot simpler than WMS, because layers always have an id
     * (name in WMS and our Layer object)
     * //from   ww  w  .j  a va 2 s . co  m
     * And even simpler than ArcGIS because layers have no tree structure.
     */

    getTopLayer().getChildren().clear();

    SimpleFeatureType ft;

    for (Layer updateLayer : update.getTopLayer().getChildren()) {

        MutablePair<Layer, UpdateResult.Status> layerStatus = result.getLayerStatus()
                .get(updateLayer.getName());
        Layer updatedLayer;

        if (layerStatus == null) {
            // New layer
            ft = updateLayer.getFeatureType();
            if (updateLayer.getFeatureType() != null) {

                if (linkedFS != null) {
                    linkedFS.addOrUpdateFeatureType(updateLayer.getName(), ft, new MutableBoolean());
                } else {
                    // New FeatureSource to be persisted
                    ft.getFeatureSource().setLinkedService(this);
                }
            }

            result.getLayerStatus().put(updateLayer.getName(),
                    new MutablePair(updateLayer, UpdateResult.Status.NEW));

            updatedLayer = updateLayer;
        } else {

            assert (layerStatus.getRight() == UpdateResult.Status.MISSING);

            Layer old = layerStatus.getLeft();

            old.update(updateLayer);

            layerStatus.setRight(UpdateResult.Status.UNMODIFIED);

            // Do not overwrite manually set feature source
            if (old.getFeatureType() == null
                    || old.getFeatureType().getFeatureSource().getLinkedService() == this) {
                if (updateLayer.getFeatureType() == null) {
                    // If was set before the old feature type will be removed 
                    // later when all orphan MISSING layers are removed
                    if (old.getFeatureType() != null) {
                        layerStatus.setRight(UpdateResult.Status.UPDATED);
                    }
                    old.setFeatureType(null);
                } else {
                    if (linkedFS != null) {
                        MutableBoolean updated = new MutableBoolean(false);
                        ft = linkedFS.addOrUpdateFeatureType(updateLayer.getName(),
                                updateLayer.getFeatureType(), updated);
                        if (old.getFeatureType() == null || updated.isTrue()) {
                            layerStatus.setRight(UpdateResult.Status.UPDATED);
                        }
                    } else {
                        ft = updateLayer.getFeatureType();
                        // New FeatureSource to be persisted
                        ft.getFeatureSource().setLinkedService(this);
                        layerStatus.setRight(UpdateResult.Status.UPDATED);
                    }
                    old.setFeatureType(ft);
                }
            }

            updatedLayer = old;
        }

        assert updatedLayer.getChildren().isEmpty();

        updatedLayer.setService(this);
        updatedLayer.setParent(getTopLayer());
        getTopLayer().getChildren().add(updatedLayer);
    }
}

From source file:nl.b3p.viewer.config.services.UpdatableFeatureSource.java

/**
 * Update this featuresource/*from w w  w  .j a v a  2s  . c om*/
 */
public FeatureSourceUpdateResult update() throws Exception {
    final FeatureSourceUpdateResult result = new FeatureSourceUpdateResult(this);
    try {
        List<SimpleFeatureType> newFeatureTypes = this
                .createFeatureTypes(result.getWaitPageStatus().subtask("", 80));
        //update and add the new featuretypes.
        for (SimpleFeatureType newFt : newFeatureTypes) {
            MutableBoolean updated = new MutableBoolean();
            this.addOrUpdateFeatureType(newFt.getTypeName(), newFt, updated);

            MutablePair<SimpleFeatureType, UpdateResult.Status> ftResult = result.getFeatureTypeStatus()
                    .get(newFt.getTypeName());

            if (ftResult == null) {
                result.getFeatureTypeStatus().put(newFt.getTypeName(),
                        new MutablePair(newFt, UpdateResult.Status.NEW));
            } else {
                if (updated.isTrue()) {
                    log.info("Feature type: " + newFt.getTypeName() + " updated");
                    ftResult.setRight(UpdateResult.Status.UPDATED);
                } else {
                    ftResult.setRight(UpdateResult.Status.UNMODIFIED);
                }
            }
        }
        //remove featuretypes when not there
        Iterator<SimpleFeatureType> it = this.getFeatureTypes().iterator();
        while (it.hasNext()) {
            SimpleFeatureType oldFt = it.next();
            boolean stillExists = false;
            for (SimpleFeatureType newFt : newFeatureTypes) {
                if (newFt.getTypeName().equals(oldFt.getTypeName())) {
                    stillExists = true;
                    break;
                }
            }
            if (!stillExists) {
                it.remove();
            }
        }
        result.setStatus(UpdateResult.Status.UPDATED);

    } catch (Exception e) {
        result.failedWithException(e);
    }
    return result;
}

From source file:nl.b3p.viewer.config.services.WMSService.java

private void updateWFS(final WMSService updateWMS, final Map<String, WFSFeatureSource> linkedFSesByURL,
        Set<SimpleFeatureType> updatedFeatureTypes, Collection<SimpleFeatureType> outTypesToRemove,
        final UpdateResult result) {

    final Set<FeatureSource> updateFSes = getAutomaticallyLinkedFeatureSources(updateWMS.getTopLayer());

    for (FeatureSource fs : updateFSes) {

        WFSFeatureSource oldFS = linkedFSesByURL.get(fs.getUrl());

        if (oldFS == null) {
            log.info("Found new WFS with URL " + fs.getUrl() + " linked to WMS");

            // Make available for updating layers in map, will be persisted
            // by cascade from Layer
            linkedFSesByURL.put(fs.getUrl(), (WFSFeatureSource) fs);

            fs.setLinkedService(this);
        } else {/* w  ww.j a  v  a 2  s  .co m*/
            log.info("Updating WFS with URL " + fs.getUrl() + " linked to WMS");

            // Update or add all feature types from updated FS
            for (SimpleFeatureType updateFT : fs.getFeatureTypes()) {
                MutableBoolean updated = new MutableBoolean();
                SimpleFeatureType updatedFT = oldFS.addOrUpdateFeatureType(updateFT.getTypeName(), updateFT,
                        updated);
                boolean isNew = updateFT == updatedFT;
                if (updated.isTrue()) {
                    updatedFeatureTypes.add(updatedFT);
                }
                if (isNew) {
                    log.info("New feature type in WFS: " + updateFT.getTypeName());
                }
            }

            // Find feature types which do not exist in updated FS
            // Remove these later on-
            // 
            Set<SimpleFeatureType> typesToRemove = new HashSet();
            for (SimpleFeatureType oldFT : oldFS.getFeatureTypes()) {
                if (fs.getFeatureType(oldFT.getTypeName()) == null) {
                    // Don'tnot modify list which we are iterating on
                    typesToRemove.add(oldFT);
                    log.info("Feature type " + oldFT.getTypeName() + " does no longer exist");
                }
            }
            outTypesToRemove.addAll(typesToRemove);
        }
    }
}

From source file:org.apache.asterix.external.classad.object.pool.MutableBooleanPool.java

@Override
public MutableBoolean newInstance() {
    return new MutableBoolean();
}

From source file:org.apache.asterix.external.classad.test.ClassAdUnitTester.java

/*********************************************************************
 * Function: test_classad//from  w ww.j ava 2  s  .  co  m
 * Purpose: Test the ClassAd class.
 * @param objectPool 
 *
 * @throws IOException
 *********************************************************************/
public static void testClassad(Parameters parameters, Results results, ClassAdObjectPool objectPool)
        throws IOException {
    ClassAdParser parser = new ClassAdParser(objectPool);
    boolean haveAttribute;
    boolean success;

    System.out.println("Testing the ClassAd class...");

    String input_basic = "[ A = 3; B = 4.0; C = \"babyzilla\"; D = true; E = {1}; F = [ AA = 3; ]; G =\"deleteme\";]";
    ClassAd basic = new ClassAd(objectPool);
    AMutableInt64 i = new AMutableInt64(0);
    MutableBoolean b = new MutableBoolean();
    AMutableDouble r = new AMutableDouble(0);
    AMutableCharArrayString s = new AMutableCharArrayString();
    ClassAd c = new ClassAd(objectPool);
    // ExprList *l;

    basic = parser.parseClassAd(input_basic);

    /* ----- Test EvaluateAttr* ----- */
    haveAttribute = basic.evaluateAttrInt("A", i);
    test("Have attribute A", (haveAttribute == true), "test_classad 1", results);
    test("A is 3", (i.getLongValue() == 3), "test_classad 2", results);

    haveAttribute = basic.evaluateAttrReal("B", r);
    test("Have attribute B", (haveAttribute == true), "test_classad 3", results);
    test("B is 4.0", (r.getDoubleValue() == 4.0), "test_classad 4", results);

    haveAttribute = basic.evaluateAttrString("C", s);
    test("Have attribute C", (haveAttribute == true), "test_classad 5", results);
    test("C is 'babyzilla'", (s.compareTo("babyzilla") == 0), "test_classad 6", results);

    haveAttribute = basic.evaluateAttrBool("D", b);
    test("Have attribute D", (haveAttribute == true), "test_classad 7", results);
    test("D is true", (b.booleanValue() == true), "test_classad 8", results);

    /* ----- Test basic insert and delete ----- */
    success = basic.insertAttr("new", 4);
    test("InsertAttr claims to have worked", (success == true), "test_classad 9", results);
    haveAttribute = basic.evaluateAttrInt("new", i);
    test("Have new attribute", (haveAttribute == true), "test_classad 10", results);
    test("new attribute is 4", i.getLongValue() == 4, "test_classad 11", results);

    success = basic.delete("new");
    test("Delete claims to have worked", (success == true), "test_classad 12", results);
    haveAttribute = basic.evaluateAttrInt("new", i);
    test("New attribute was deleted", (haveAttribute == false), "test_classad 13", results);

    success = basic.delete("G");
    test("DELETE claims to have worked", (success == true), "test_classad 14", results);
    haveAttribute = basic.evaluateAttrString("G", s);
    test("Attribute G was deleted", (haveAttribute == false), "test_classad 15", results);

    basic = null;

    /* ----- Test GetExternalReferences ----- */
    String inputRef = "[ Rank=Member(\"LCG-2_1_0\",other.Environment) ? other.Time/seconds : other.Time/minutes; minutes=60; ]";
    TreeSet<String> refs = new TreeSet<String>();
    ExprTree rank;

    c = parser.parseClassAd(inputRef);
    test("Made classad_ref", (c != null), "Test GetExternalReferences 1", results);
    if (c != null) {
        rank = c.lookup("Rank");
        test("Rank exists", (rank != null), "Test GetExternalReferences 2", results);

        if (rank != null) {
            boolean haveReferences;
            if ((haveReferences = c.getExternalReferences(rank, refs, true))) {
                test("have_references", (haveReferences == true), "Test GetExternalReferences 3", results);

                if (haveReferences) {
                    boolean haveEnvironment;
                    boolean haveTime;
                    boolean haveSeconds;
                    boolean haveOther;
                    haveEnvironment = false;
                    haveTime = false;
                    haveSeconds = false;
                    haveOther = false;
                    for (String entry : refs) {
                        if (entry.compareTo("other.Environment") == 0) {
                            haveEnvironment = true;
                        } else if (entry.compareTo("other.Time") == 0) {
                            haveTime = true;
                        } else if (entry.compareTo("seconds") == 0) {
                            haveSeconds = true;
                        } else {
                            haveOther = true;
                        }
                    }
                    test("Have external reference to Environment", (haveEnvironment == true),
                            "Test GetExternalReferences 4", results);
                    test("Have external reference to Time", (haveTime == true), "Test GetExternalReferences 5",
                            results);
                    test("Have external reference to seconds", (haveSeconds == true),
                            "Test GetExternalReferences 6", results);
                    test("Have no other external references", (haveOther != true),
                            "Test GetExternalReferences 7", results);
                }
            }
        }
        c = null;
    }

    // This ClassAd may cause problems. Perhaps a memory leak.
    // This test is only useful when run under valgrind.
    String memoryProblemClassad = "[ Updates = [status = \"request_completed\"; timestamp = absTime(\"2004-12-16T18:10:59-0600]\")] ]";
    c = parser.parseClassAd(memoryProblemClassad);

    /* ----- Test Parsing multiple ClassAds ----- */
    String twoClassads = "[ a = 3; ][ b = 4; ]";
    ClassAd classad1 = new ClassAd(objectPool);
    ClassAd classad2 = new ClassAd(objectPool);
    AMutableInt32 offset = new AMutableInt32(0);

    parser.parseClassAd(twoClassads, classad1, offset);
    test("Have good offset #1", offset.getIntegerValue().intValue() == 10, "Test Parsing multiple ClassAds 1",
            results);
    parser.parseClassAd(twoClassads, classad2, offset);
    test("Have good offset #2", offset.getIntegerValue().intValue() == 20, "Test Parsing multiple ClassAds 2",
            results);

    /* ----- Test chained ClassAds ----- */
    // classad1 and classad2 from above test are used.
    ClassAd classad3 = new ClassAd(objectPool);

    classad1.chainToAd(classad2);
    test("classad1's parent is classad2", classad1.getChainedParentAd().equals(classad2),
            "Test chained ClassAds 1", results);
    haveAttribute = classad1.evaluateAttrInt("b", i);
    test("chain has attribute b from parent", (haveAttribute == true), "Test chained ClassAds 2", results);
    test("chain attribute b from parent is 4", (i.getLongValue() == 4), "Test chained ClassAds 3", results);

    haveAttribute = classad1.evaluateAttrInt("a", i);
    test("chain has attribute a from self", (haveAttribute == true), "Test chained ClassAds 4", results);
    test("chain attribute a is 3", (i.getLongValue() == 3), "Test chained ClassAds 5", results);

    // Now we modify classad2 (parent) to contain "a".
    success = classad2.insertAttr("a", 7);
    test("insert a into parent", (success == true), "Test chained ClassAds 6", results);
    haveAttribute = classad1.evaluateAttrInt("a", i);
    test("chain has attribute a from self (overriding parent)", (haveAttribute == true),
            "Test chained ClassAds 7", results);
    test("chain attribute a is 3 (overriding parent)", (i.getLongValue() == 3), "Test chained ClassAds 8",
            results);
    haveAttribute = classad2.evaluateAttrInt("a", i);
    test("chain parent has attribute a", (haveAttribute == true), "Test chained ClassAds 9", results);
    test("chain parent attribute a is 7", (i.getLongValue() == 7), "Test chained ClassAds 10", results);

    success = classad3.copyFromChain(classad1);
    test("copy from chain succeeded", (success == true), "Test chained ClassAds 11", results);
    haveAttribute = classad3.evaluateAttrInt("b", i);
    test("copy of chain has attribute b", (haveAttribute == true), "Test chained ClassAds 12", results);
    test("copy of chain has attribute b==4", (i.getLongValue() == 4), "Test chained ClassAds 13", results);

    success = classad3.insertAttr("c", 6);
    test("insert into copy of chain succeeded", (success == true), "Test chained ClassAds 14", results);
    classad3.copyFromChain(classad1);
    haveAttribute = classad3.evaluateAttrInt("c", i);
    test("copy of chain is clean", (haveAttribute == false), "Test chained ClassAds 15", results);
    classad3.insertAttr("c", 6);
    success = classad3.updateFromChain(classad1);
    test("update from chain succeeded", (success == true), "Test chained ClassAds 16", results);
    haveAttribute = classad3.evaluateAttrInt("c", i);
    test("update from chain is merged", (haveAttribute == true), "Test chained ClassAds 17", results);
    test("update from chain has attribute c==6", (i.getLongValue() == 6), "Test chained ClassAds 18", results);
}

From source file:org.apache.asterix.external.classad.test.ClassAdUnitTester.java

/*********************************************************************
 * Function: test_exprlist//ww w.  j  a  v a 2s  .c  o  m
 * Purpose: Test the ExprList class.
 *
 * @throws IOException
 *********************************************************************/
public static void testExprList(Parameters parameters, Results results, ClassAdObjectPool objectPool)
        throws IOException {
    System.out.println("Testing the ExprList class...");

    Literal literal10;
    Literal literal20;
    Literal literal21;

    List<ExprTree> vector1 = new ArrayList<ExprTree>();
    List<ExprTree> vector2 = new ArrayList<ExprTree>();

    ExprList list0;
    ExprList list0Copy;
    ExprList list1;
    ExprList list1Copy;
    ExprList list2;
    ExprList list2Copy;

    /* ----- Setup Literals, the vectors, then ExprLists ----- */
    literal10 = Literal.createReal("1.0", objectPool);
    literal20 = Literal.createReal("2.0", objectPool);
    literal21 = Literal.createReal("2.1", objectPool);

    vector1.add(literal10);
    vector2.add(literal20);
    vector2.add(literal21);

    list0 = new ExprList(objectPool);
    list1 = new ExprList(vector1, objectPool);
    list2 = new ExprList(vector2, objectPool);

    /* ----- Did the lists get made? ----- */
    test("Made list 0", (list0 != null), "Did the lists get made? 0", results);
    test("Made list 1", (list1 != null), "Did the lists get made? 1", results);
    test("Made list 2", (list2 != null), "Did the lists get made? 2", results);

    /* ----- Are these lists identical to themselves? ----- */
    test("ExprList identical 0", list0.sameAs(list0), "Are these lists identical to themselves? 0", results);
    test("ExprList identical 1", list1.sameAs(list1), "Are these lists identical to themselves? 1", results);
    test("ExprList identical 2", list2.sameAs(list2), "Are these lists identical to themselves? 2", results);

    /* ----- Are they different from each other? ----- */
    test("ExprLists different 0-1", !(list0.sameAs(list1)), "Are these lists different from each other? 0",
            results);
    test("ExprLists different 1-2", !(list1.sameAs(list2)), "Are these lists identical from each other? 1",
            results);
    test("ExprLists different 0-2", !(list0.sameAs(list2)), "Are these lists identical from each other? 2",
            results);

    /* ----- Check the size of the ExprLists to make sure they are ok ----- */
    test("ExprList size 0", (list0.size() == 0), "check list size? 0", results);
    test("ExprList size 1", (list1.size() == 1), "check list size? 1", results);
    test("ExprList size 2", (list2.size() == 2), "check list size? 2", results);

    /* ----- Make copies of the ExprLists ----- */
    list0Copy = (ExprList) list0.copy();
    list1Copy = (ExprList) list1.copy();
    list2Copy = (ExprList) list2.copy();

    /* ----- Did the copies get made? ----- */
    test("Made copy of list 0", (list0Copy != null), "Did the copies get made? 0", results);
    test("Made copy of list 1", (list1Copy != null), "Did the copies get made? 1", results);
    test("Made copy of list 2", (list2Copy != null), "Did the copies get made? 2", results);

    /* ----- Are they identical to the originals? ----- */
    test("ExprList self-identity 0", (list0.sameAs(list0Copy)), "Are they identical to the originals? 0",
            results);
    test("ExprList self-identity 1", (list1.sameAs(list1Copy)), "Are they identical to the originals? 1",
            results);
    test("ExprList self-identity 2", (list2.sameAs(list2Copy)), "Are they identical to the originals? 2",
            results);

    /* ----- Test adding and deleting from a list ----- */
    Literal add;
    add = Literal.createReal("2.2", objectPool);

    if (list2Copy != null) {
        list2Copy.insert(add);
        test("Edited list is different", !(list2.sameAs(list2Copy)), "Test adding and deleting from a list 0",
                results);
        list2Copy.erase(list2Copy.size() - 1);
        test("Twice Edited list is same", (list2.sameAs(list2Copy)), "Test adding and deleting from a list 1",
                results);
    }

    // Note that we do not delete the Literals that we created, because
    // they should have been deleted when the list was deleted.

    /* ----- Test an ExprList bug that Nate Mueller found ----- */
    ClassAd classad;
    ClassAdParser parser = new ClassAdParser(objectPool);
    MutableBoolean b = new MutableBoolean();
    boolean haveAttribute;
    boolean canEvaluate;
    Value value = new Value(objectPool);

    String listClassadText = "[foo = 3; have_foo = member(foo, {1, 2, 3});]";
    classad = parser.parseClassAd(listClassadText);
    haveAttribute = classad.evaluateAttrBool("have_foo", b);
    test("Can evaluate list in member function", (haveAttribute == true && b.booleanValue() == true),
            "Test an ExprList bug that Nate Mueller found 0", results);

    canEvaluate = classad.evaluateExpr("member(foo, {1, 2, blah, 3})", value);
    test("Can evaluate list in member() outside of ClassAd", canEvaluate == true,
            "Test an ExprList bug that Nate Mueller found 1", results);
    return;
}

From source file:org.apache.asterix.external.classad.test.ClassAdUnitTester.java

/*********************************************************************
 * Function: test_value//  ww w.  j  a va  2s .co m
 * Purpose: Test the Value class.
 *
 * @throws HyracksDataException
 *********************************************************************/
public static void testValue(Parameters parameters, Results results, ClassAdObjectPool objectPool)
        throws HyracksDataException {
    Value v = new Value(objectPool);
    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(objectPool);
    ExprList ll = new ExprList(objectPool);
    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, objectPool);
    ll = new ExprList(true, objectPool);
    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(objectPool);
    c.insertAttr("test_int", 10);
    ClassAd cc = new ClassAd(objectPool);
    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:org.apache.asterix.external.library.ClassAdParser.java

private boolean parsePrimaryExpression(ExprTreeHolder tree) throws IOException {
    ExprTreeHolder treeL;/*from   w  w  w .  j a  v  a  2s. c  om*/
    TokenValue tv = objectPool.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 = objectPool.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, objectPool));
            }
        } else {
            // I don't think this is ever hit
            tree.setInnerTree(
                    AttributeReference.createAttributeReference(null, tv.getStrValue(), false, objectPool));
        }
        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, objectPool));
            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 = objectPool.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, objectPool));
        return (tree.size() != 0);
    }
    // constants
    case LEX_OPEN_BOX: {
        isExpr = true;
        ClassAd newAd = objectPool.classAdPool.get();
        if (!parseClassAd(newAd)) {
            tree.resetExprTree(null);
            return false;
        }
        tree.setInnerTree(newAd);
    }
        return true;

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

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

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

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

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

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

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

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