Example usage for org.apache.commons.collections15 CollectionUtils isEqualCollection

List of usage examples for org.apache.commons.collections15 CollectionUtils isEqualCollection

Introduction

In this page you can find the example usage for org.apache.commons.collections15 CollectionUtils isEqualCollection.

Prototype

public static <E> boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b) 

Source Link

Document

Returns true iff the given Collection s contain exactly the same elements with exactly the same cardinalities.

Usage

From source file:com.davidsoergel.trees.ImmutableSortedSetHierarchyNode.java

public boolean equals(Object o) {
    if (this == o) {
        return true;
    }//from   w  ww.  j  av  a 2  s .c  om
    if (o == null || getClass() != o.getClass()) {
        return false;
    }

    ImmutableSortedSetHierarchyNode<T> that = (ImmutableSortedSetHierarchyNode<T>) o;

    if (!CollectionUtils.isEqualCollection(children, that.children)) {
        return false;
    }
    if (contents != null ? !contents.equals(that.contents) : that.contents != null) {
        return false;
    }
    if (parent != null ? !parent.equals(that.parent) : that.parent != null) {
        return false;
    }

    return true;
}

From source file:com.davidsoergel.trees.RootedPhylogenyInterfaceTest.java

@Test
public void intersectionTreeFromTwoLeafSetsSkipsInternalNodes() throws Exception {
    T mainTree = tif.createInstance();/*ww w. ja v a  2 s .  c om*/

    RootedPhylogeny extractedTree = mainTree.extractIntersectionTree(
            DSCollectionUtils.setOf("aaaa", "baa", "bba", "bbba"),
            DSCollectionUtils.setOf("bab", "bba", "bbba", "ca", "cb"), null);

    assert extractedTree.getUniqueIdToNodeMap().size() == 6;
    assert extractedTree.getLeaves().size() == 3;
    assert CollectionUtils.isEqualCollection(extractedTree.getLeafValues(),
            DSCollectionUtils.setOf("ba", "bba", "bbba"));
    assert CollectionUtils.isEqualCollection(extractedTree.getNodeValues(),
            DSCollectionUtils.setOf("ba", "bba", "bbba", "bb", "b", "root"));
}

From source file:org.intermine.modelviewer.jaxb.ConfigParserTest.java

/**
 * Tests that the two lists of classes contain the same classes,
 * and that all of those classes are the same as their counterparts in the
 * other list./* w  ww. ja v a2s.com*/
 * 
 * @param c1 The first list of Classes.
 * @param c2 The second list of Classes.
 */
private void genomicCoreEquality(List<Class> c1, List<Class> c2) {

    if (c1 == null) {
        assertNull("First classes null, second classes not null", c2);
        return;
    }
    if (c2 == null) {
        assertNull("First classes not null, second classes null", c1);
        return;
    }

    assertEquals("Wrong number of classes", c1.size(), c2.size());

    Map<String, Class> c1Classes = new HashMap<String, Class>();
    for (Class c : c1) {
        c1Classes.put(c.getName(), c);
    }
    Map<String, Class> c2Classes = new HashMap<String, Class>();
    for (Class c : c2) {
        c2Classes.put(c.getName(), c);
    }

    assertTrue("Class names don't match",
            CollectionUtils.isEqualCollection(c1Classes.keySet(), c2Classes.keySet()));

    Map<String, Attribute> c1Attributes = new HashMap<String, Attribute>();
    Map<String, Attribute> c2Attributes = new HashMap<String, Attribute>();
    Map<String, ClassReference> c1Refs = new HashMap<String, ClassReference>();
    Map<String, ClassReference> c2Refs = new HashMap<String, ClassReference>();

    for (String cname : c1Classes.keySet()) {
        Class c1c = c1Classes.get(cname);
        Class c2c = c2Classes.get(cname);

        assertEquals("Superclass of class " + cname + " wrong", c1c.getExtends(), c2c.getExtends());
        assertEquals("Interface flag of " + cname + " wrong", c1c.isIsInterface(), c2c.isIsInterface());

        assertEquals("Wrong number of attributes on class " + cname, c1c.getAttribute().size(),
                c2c.getAttribute().size());

        c1Attributes.clear();
        for (Attribute a : c1c.getAttribute()) {
            c1Attributes.put(a.getName(), a);
        }
        c2Attributes.clear();
        for (Attribute a : c2c.getAttribute()) {
            c2Attributes.put(a.getName(), a);
        }

        assertTrue("Attribute names on class " + cname + " don't match",
                CollectionUtils.isEqualCollection(c1Attributes.keySet(), c2Attributes.keySet()));

        for (String aname : c1Attributes.keySet()) {
            Attribute a1 = c1Attributes.get(aname);
            Attribute a2 = c2Attributes.get(aname);

            assertEquals("Type of attribute " + aname + " on class " + cname + " mismatches", a1.getType(),
                    a2.getType());
        }

        assertEquals("Wrong number of collections on class " + cname, c1c.getCollection().size(),
                c2c.getCollection().size());

        c1Refs.clear();
        for (ClassReference r : c1c.getCollection()) {
            c1Refs.put(r.getName(), r);
        }
        c2Refs.clear();
        for (ClassReference r : c2c.getCollection()) {
            c2Refs.put(r.getName(), r);
        }

        assertTrue("Collection names on class " + cname + " don't match",
                CollectionUtils.isEqualCollection(c1Refs.keySet(), c2Refs.keySet()));

        for (String rname : c1Refs.keySet()) {
            ClassReference r1 = c1Refs.get(rname);
            ClassReference r2 = c2Refs.get(rname);

            assertEquals("Referenced type of collection " + rname + " on class " + cname + " mismatches",
                    r1.getReferencedType(), r2.getReferencedType());
            assertEquals("Reverse reference of collection " + rname + " on class " + cname + " mismatches",
                    r1.getReverseReference(), r2.getReverseReference());
        }

        assertEquals("Wrong number of refer4ences on class " + cname, c1c.getReference().size(),
                c2c.getReference().size());

        c1Refs.clear();
        for (ClassReference r : c1c.getReference()) {
            c1Refs.put(r.getName(), r);
        }
        c2Refs.clear();
        for (ClassReference r : c2c.getReference()) {
            c2Refs.put(r.getName(), r);
        }

        assertTrue("Reference names on class " + cname + " don't match",
                CollectionUtils.isEqualCollection(c1Refs.keySet(), c2Refs.keySet()));

        for (String rname : c1Refs.keySet()) {
            ClassReference r1 = c1Refs.get(rname);
            ClassReference r2 = c2Refs.get(rname);

            assertEquals("Referenced type of reference " + rname + " on class " + cname + " mismatches",
                    r1.getReferencedType(), r2.getReferencedType());
            assertEquals("Reverse reference of reference " + rname + " on class " + cname + " mismatches",
                    r1.getReverseReference(), r2.getReverseReference());
        }
    }
}

From source file:org.intermine.modelviewer.jaxb.ConfigParserTest.java

/**
 * Tests that two projects are the same as each other.
 * /*from w  ww.jav  a  2s.  c om*/
 * @param p1 Project one.
 * @param p2 Project two.
 */
private void projectEquality(Project p1, Project p2) {

    assertEquals("Project type wrong", p1.getType(), p2.getType());

    assertEquals("Wrong number of properties", p1.getProperty().size(), p2.getProperty().size());

    Map<String, Property> p1Properties = new HashMap<String, Property>();
    for (Property p : p1.getProperty()) {
        p1Properties.put(p.getName(), p);
    }
    Map<String, Property> p2Properties = new HashMap<String, Property>();
    for (Property p : p2.getProperty()) {
        p2Properties.put(p.getName(), p);
    }

    assertTrue("Property names don't match",
            CollectionUtils.isEqualCollection(p1Properties.keySet(), p2Properties.keySet()));
    for (String pname : p1Properties.keySet()) {
        Property p1p = p1Properties.get(pname);
        Property p2p = p2Properties.get(pname);

        assertEquals("Value of property " + pname + " wrong", p1p.getValue(), p2p.getValue());
        assertEquals("Location of property " + pname + " wrong", p1p.getLocation(), p2p.getLocation());
    }

    assertEquals("Wrong number of sources", p1.getSources().getSource().size(),
            p2.getSources().getSource().size());

    Map<String, Source> p1Sources = new HashMap<String, Source>();
    for (Source s : p1.getSources().getSource()) {
        p1Sources.put(s.getName(), s);
    }
    Map<String, Source> p2Sources = new HashMap<String, Source>();
    for (Source s : p2.getSources().getSource()) {
        p2Sources.put(s.getName(), s);
    }
    assertTrue("Source names don't match",
            CollectionUtils.isEqualCollection(p1Sources.keySet(), p2Sources.keySet()));

    for (String sname : p1Sources.keySet()) {
        Source p1s = p1Sources.get(sname);
        Source p2s = p2Sources.get(sname);

        assertEquals("Type of source " + sname + " wrong", p1s.getType(), p2s.getType());

        p1Properties.clear();
        for (Property p : p1.getProperty()) {
            p1Properties.put(p.getName(), p);
        }
        p2Properties.clear();
        for (Property p : p2.getProperty()) {
            p2Properties.put(p.getName(), p);
        }

        assertTrue("Property names don't match",
                CollectionUtils.isEqualCollection(p1Properties.keySet(), p2Properties.keySet()));
        for (String pname : p1Properties.keySet()) {
            Property p1p = p1Properties.get(pname);
            Property p2p = p2Properties.get(pname);

            assertEquals("Value of source " + sname + " property " + pname + " wrong", p1p.getValue(),
                    p2p.getValue());
            assertEquals("Location of source " + sname + " property " + pname + " wrong", p1p.getLocation(),
                    p2p.getLocation());
        }
    }

    assertEquals("Wrong number of post processors", p1.getPostProcessing().getPostProcess().size(),
            p2.getPostProcessing().getPostProcess().size());

    Map<String, PostProcess> p1Post = new HashMap<String, PostProcess>();
    for (PostProcess pp : p1.getPostProcessing().getPostProcess()) {
        p1Post.put(pp.getName(), pp);
    }
    Map<String, PostProcess> p2Post = new HashMap<String, PostProcess>();
    for (PostProcess pp : p2.getPostProcessing().getPostProcess()) {
        p2Post.put(pp.getName(), pp);
    }

    assertTrue("Post-processor names don't match",
            CollectionUtils.isEqualCollection(p1Post.keySet(), p2Post.keySet()));

    for (String ppname : p1Post.keySet()) {
        PostProcess p1pp = p1Post.get(ppname);
        PostProcess p2pp = p2Post.get(ppname);

        assertEquals("Post-process " + ppname + " dump is wrong", p1pp.isDump(), p2pp.isDump());
    }
}

From source file:org.springframework.jdbc.repo.impl.jdbc.RawPropertiesRepoImplTest.java

@Test
public void testListEntities() {
    Set<String> expected = new TreeSet<String>();
    for (int index = 0; index < Byte.SIZE; index++) {
        TestEntry e = new TestEntry();
        repo.setProperties(e, new Transformer<TestEntry, Map<String, ?>>() {
            @Override/*from   w ww  .  j a v  a 2  s. co  m*/
            public Map<String, ?> transform(TestEntry input) {
                return Collections.<String, Serializable>singletonMap(PROP_NAME, Double.valueOf(Math.random()));
            }
        });
        expected.add(e.getId());
    }

    List<String> idsList = repo.listEntities();
    assertEquals("Mismatched entities list count", expected.size(), ExtendedCollectionUtils.size(idsList));

    Set<String> actual = new TreeSet<>(idsList);
    assertEquals("Mismatched unique entities count", idsList.size(), actual.size());

    if (!CollectionUtils.isEqualCollection(expected, actual)) {
        fail("Mismatched ID set: expected=" + expected + ", actual=" + actual);
    }
}

From source file:org.springframework.jdbc.repo.impl.jdbc.RawPropertiesRepoImplTest.java

@Test
public void testFindEntitiesByPropertyValue() {
    final String BASE_ID = "testFindEntitiesByPropertyValue";
    Map<String, Serializable> props = createEntityProperties(BASE_ID);
    List<String> expected = new ArrayList<>();
    for (int index = 0; index < Byte.SIZE; index++) {
        String id = BASE_ID + index;
        repo.setProperties(id, props);/*from ww  w  .j av  a  2s  .  c  o  m*/
        expected.add(id);
    }

    for (Map.Entry<String, Serializable> pe : props.entrySet()) {
        String propName = pe.getKey();
        Serializable propValue = pe.getValue();
        List<String> actual = repo.findEntities(propName, propValue);
        if (!CollectionUtils.isEqualCollection(expected, actual)) {
            fail("Mismatched results for " + propName + "=" + propValue + ": expected=" + expected + ", actual="
                    + actual);
        }

        // change the type so we know it won't matcj
        if (propValue instanceof String) {
            propValue = Integer.valueOf(propValue.hashCode());
        } else {
            propValue = propValue.toString();
        }

        actual = repo.findEntities(propName, propValue);
        if (ExtendedCollectionUtils.size(actual) > 0) {
            fail("Unexpected results for " + propName + "=" + propValue + ": " + actual);
        }
    }
}

From source file:org.springframework.jdbc.repo.impl.jdbc.RawPropertiesRepoImplTest.java

@Test
public void testListMatchingIdentifiers() {
    final String COMMON_PART = "testListMatchingIdentifiers";
    // NOTE: we chose a separator that has SQL meaning on purpose
    final String COMMON_PREFIX = getClass().getSimpleName() + "#" + COMMON_PART + "%";
    Map<String, Serializable> props = createEntityProperties(COMMON_PART);
    List<String> expected = new ArrayList<String>();
    for (int index = 0; index < Byte.SIZE; index++) {
        String id = COMMON_PREFIX + index;
        repo.setProperties(id, props);/*from w w w  .j a v  a2  s.  co  m*/
        expected.add(id);
    }

    // create some extra values
    for (int index = 0; index < Byte.SIZE; index++) {
        repo.setProperties(String.valueOf(Math.random()), props);
    }

    List<String> actual = repo.listMatchingIdentifiers("*" + COMMON_PART + "*");
    if (!CollectionUtils.isEqualCollection(expected, actual)) {
        fail("Mismatched common part wildcard results: expected=" + expected + ", actual=" + actual);
    }

    actual = repo.listMatchingIdentifiers(COMMON_PREFIX + "*");
    if (!CollectionUtils.isEqualCollection(expected, actual)) {
        fail("Mismatched common prefix wildcard results: expected=" + expected + ", actual=" + actual);
    }

    for (String id : expected) {
        actual = repo.listMatchingIdentifiers(id);
        assertEquals(id + ": Mismatched results count", 1, ExtendedCollectionUtils.size(actual));
        assertEquals("Mismatched matched identifiers", id, actual.get(0));
    }
}