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

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

Introduction

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

Prototype

public static boolean isEqualCollection(final Collection a, final Collection 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:org.springframework.security.access.hierarchicalroles.HierarchicalRolesTestHelper.java

public static boolean containTheSameGrantedAuthorities(Collection<? extends GrantedAuthority> authorities1,
        Collection<? extends GrantedAuthority> authorities2) {
    if (authorities1 == null && authorities2 == null) {
        return true;
    }/*  w ww.j a v  a2 s.co  m*/

    if (authorities1 == null || authorities2 == null) {
        return false;
    }
    return CollectionUtils.isEqualCollection(authorities1, authorities2);
}

From source file:org.springframework.security.access.hierarchicalroles.HierarchicalRolesTestHelper.java

public static boolean containTheSameGrantedAuthoritiesCompareByAuthorityString(
        Collection<? extends GrantedAuthority> authorities1,
        Collection<? extends GrantedAuthority> authorities2) {
    if (authorities1 == null && authorities2 == null) {
        return true;
    }//  ww  w.  j a v a 2 s .c om

    if (authorities1 == null || authorities2 == null) {
        return false;
    }
    return CollectionUtils.isEqualCollection(toCollectionOfAuthorityStrings(authorities1),
            toCollectionOfAuthorityStrings(authorities2));
}

From source file:org.springframework.security.access.hierarchicalroles.TestHelperTests.java

@Test
public void testToListOfAuthorityStrings() {
    Collection<GrantedAuthority> authorities1 = AuthorityUtils.createAuthorityList("ROLE_A", "ROLE_B");
    Collection<GrantedAuthority> authorities2 = AuthorityUtils.createAuthorityList("ROLE_B", "ROLE_A");
    Collection<GrantedAuthority> authorities3 = AuthorityUtils.createAuthorityList("ROLE_A", "ROLE_C");
    Collection<GrantedAuthority> authorities4 = AuthorityUtils.createAuthorityList("ROLE_A");
    Collection<GrantedAuthority> authorities5 = AuthorityUtils.createAuthorityList("ROLE_A", "ROLE_A");

    List<String> authoritiesStrings1 = new ArrayList<>();
    authoritiesStrings1.add("ROLE_A");
    authoritiesStrings1.add("ROLE_B");

    List<String> authoritiesStrings2 = new ArrayList<>();
    authoritiesStrings2.add("ROLE_B");
    authoritiesStrings2.add("ROLE_A");

    List<String> authoritiesStrings3 = new ArrayList<>();
    authoritiesStrings3.add("ROLE_A");
    authoritiesStrings3.add("ROLE_C");

    List<String> authoritiesStrings4 = new ArrayList<>();
    authoritiesStrings4.add("ROLE_A");

    List<String> authoritiesStrings5 = new ArrayList<>();
    authoritiesStrings5.add("ROLE_A");
    authoritiesStrings5.add("ROLE_A");

    assertThat(CollectionUtils.isEqualCollection(
            HierarchicalRolesTestHelper.toCollectionOfAuthorityStrings(authorities1), authoritiesStrings1))
                    .isTrue();//from   w ww  .  java  2s .  co  m

    assertThat(CollectionUtils.isEqualCollection(
            HierarchicalRolesTestHelper.toCollectionOfAuthorityStrings(authorities2), authoritiesStrings2))
                    .isTrue();

    assertThat(CollectionUtils.isEqualCollection(
            HierarchicalRolesTestHelper.toCollectionOfAuthorityStrings(authorities3), authoritiesStrings3))
                    .isTrue();

    assertThat(CollectionUtils.isEqualCollection(
            HierarchicalRolesTestHelper.toCollectionOfAuthorityStrings(authorities4), authoritiesStrings4))
                    .isTrue();

    assertThat(CollectionUtils.isEqualCollection(
            HierarchicalRolesTestHelper.toCollectionOfAuthorityStrings(authorities5), authoritiesStrings5))
                    .isTrue();
}

From source file:org.squashtest.tm.service.internal.execution.ExecutionStepModificationHelper.java

private boolean hasChanged(final DenormalizedFieldValue denormVal, final CustomFieldValue origVal) {

    final boolean[] hasChanged = { false };

    origVal.getCustomField().accept(new CustomFieldVisitor() {

        private void testValChange() {
            if (valueHasChanged(denormVal, origVal)) {
                hasChanged[0] = true;/*from   w  w w .j  av  a  2s  . c  o m*/
            }
        }

        @Override
        public void visit(MultiSelectField multiselect) {
            testValChange();
        }

        @Override
        public void visit(RichTextField richField) {
            testValChange();

        }

        @Override
        public void visit(CustomField standardValue) {
            testValChange();

        }

        @Override
        public void visit(SingleSelectField selectField) {
            testValChange();
            testOptionsChange(selectField);
        }

        private void testOptionsChange(SingleSelectField selectField) {

            DenormalizedSingleSelectField denormSSF = (DenormalizedSingleSelectField) denormVal;

            if (!CollectionUtils.isEqualCollection(denormSSF.getOptions(), selectField.getOptions())) {
                hasChanged[0] = true;
            }
        }
    });

    return hasChanged[0];
}

From source file:org.structnetalign.merge.BronKerboschCliqueFinder.java

@Override
public NavigableSet<Set<V>> transform(UndirectedGraph<V, E> graph) {
    InternalBronKerboschCliqueFinder<V, E> finder = new InternalBronKerboschCliqueFinder<V, E>(graph);
    Collection<Set<V>> unsortedCliques = finder.getAllMaximalCliques();
    Comparator<Set<V>> comparator = new Comparator<Set<V>>() {
        @Override/*from  www.j a  v a 2s  .  c  o m*/
        public int compare(Set<V> clique1, Set<V> clique2) {
            if (CollectionUtils.isEqualCollection(clique1, clique2))
                return 0;
            if (clique1.size() < clique2.size()) {
                return 1;
            } else if (clique1.size() > clique2.size()) {
                return -1;
            } else {
                return -1;
            }
        }
    };
    NavigableSet<Set<V>> yes = new TreeSet<>(comparator);
    for (Set<V> s : unsortedCliques) {
        yes.add(s);
    }
    return yes;
}

From source file:org.structnetalign.merge.BronKerboschMergeJob.java

@Override
public List<NavigableSet<Integer>> call() throws Exception {

    logger.info("Searching for cliques on job " + index + " containing " + graph.getVertexCount()
            + " vertices and " + graph.getHomologyCount() + " homology edges");

    // find the cliques
    BronKerboschCliqueFinder<Integer, HomologyEdge> finder = new BronKerboschCliqueFinder<>();

    // these cliques are ordered from largest to smallest
    Collection<Set<Integer>> cliques = finder.transform(graph.getHomology());

    // just report the cliques we're using
    logger.info("Job " + index + ": " + "Found " + cliques.size() + " maximal cliques");
    int i = 1;/*from  www  .  j  ava2s.co  m*/
    for (Set<Integer> clique : cliques) {
        logger.debug("Job " + index + ": " + "Clique " + i + ": " + clique);
        i++;
    }

    // partition the cliques by sets of interactions
    // we call these (maximal) degenerate sets
    List<NavigableSet<Integer>> simpleDegenerateSets = new ArrayList<NavigableSet<Integer>>();
    for (Set<Integer> clique : cliques) {
        NavigableMap<String, NavigableSet<Integer>> degenerateSetMap = new TreeMap<>();
        for (int v : clique) {
            Collection<Integer> neighbors = graph.getInteractionNeighbors(v);
            String hash = hashVertexInteractions(neighbors);
            NavigableSet<Integer> degenerateSet = degenerateSetMap.get(hash);
            if (degenerateSet == null) {
                degenerateSet = new TreeSet<>();
                degenerateSetMap.put(hash, degenerateSet);
            }
            degenerateSet.add(v);
            logger.trace("Job " + index + ": " + "Found " + hash + " --> " + degenerateSetMap.get(hash));
        }
        for (NavigableSet<Integer> set : degenerateSetMap.values()) {
            simpleDegenerateSets.add(set);
        }
    }

    /*
     * Now sort the degenerate sets from largest to smallest.
     * Take into account the edge case where the sizes are the same.
     */
    Comparator<NavigableSet<Integer>> comparator = new Comparator<NavigableSet<Integer>>() {
        @Override
        public int compare(NavigableSet<Integer> clique1, NavigableSet<Integer> clique2) {
            if (CollectionUtils.isEqualCollection(clique1, clique2))
                return 0;
            if (clique1.size() < clique2.size()) {
                return 1;
            } else if (clique1.size() > clique2.size()) {
                return -1;
            } else {
                Iterator<Integer> iter1 = clique1.iterator();
                Iterator<Integer> iter2 = clique2.iterator();
                while (iter1.hasNext()) { // we know they're the same size
                    int v1 = iter1.next();
                    int v2 = iter2.next();
                    if (v1 < v2) {
                        return 1;
                    } else if (v1 > v2) {
                        return -1;
                    }
                }
            }
            // they're the same throughout, so they're equal
            return 0;
        }
    };
    List<NavigableSet<Integer>> sortedDegenerateSets = new ArrayList<>(simpleDegenerateSets.size());
    sortedDegenerateSets.addAll(simpleDegenerateSets);
    Collections.sort(sortedDegenerateSets, comparator);

    /*
     * Now we want to return only the maximal maximal degenerate sets.
     */

    TreeSet<String> verticesAlreadyUsed = new TreeSet<String>();

    List<NavigableSet<Integer>> finalDegenerateSets = new ArrayList<>(sortedDegenerateSets.size());

    int nTrivial = 0;
    int nWeak = 0; // a degenerate set is weak if it contains a vertex that is added first

    forcliques: for (NavigableSet<Integer> set : sortedDegenerateSets) {

        // discard trivial degenerate sets
        if (set.size() < 2) {
            nTrivial++;
            continue;
        }

        // verify that we haven't already used any vertex in this degenerate set
        for (int v : set) {
            String hash = NetworkUtils.hash(v); // use MD5 for safety
            if (verticesAlreadyUsed.contains(hash)) {
                // discard this degenerate set and do NOT say we've used any of these vertices
                nWeak++;
                continue forcliques;
            }
        }

        // we haven't used any vertex in this degenerate set
        // now add all of these vertices
        // do NOT add before, or we'll add vertices we haven't used yet
        for (int v : set) {
            String hash = NetworkUtils.hash(v);
            verticesAlreadyUsed.add(hash);
        }
        finalDegenerateSets.add(set); // keep this degenerate set
    }

    logger.info("Job " + index + ": " + "Found " + finalDegenerateSets.size()
            + " strong nontrivial maximal degenerate sets found (" + nTrivial + " trivial and " + nWeak
            + " weak)");

    return finalDegenerateSets;
}

From source file:org.structnetalign.util.GraphMLAdaptorTest.java

@Test
public void testReadGraph() {
    UndirectedGraph<String, String> graph = GraphMLAdaptor.readGraph(RESOURCE_DIR + "agraph.graphml.xml");
    assertEquals(11, graph.getVertexCount());
    assertEquals(8, graph.getEdgeCount());
    String[] vertices = new String[] { "x", "s", "t", "x3", "x4", "v5", "v6", "v7", "v8", "v9", "v10" };
    SortedSet<String> vSet = new TreeSet<>();
    for (String v : vertices)
        vSet.add(v);/*from   w  ww .j a v a 2s.  co  m*/
    String[] edges = new String[] { "e1", "e2", "e3", "e4", "e5", "e6", "e7", "y_" };
    SortedSet<String> eSet = new TreeSet<>();
    for (String e : edges)
        eSet.add(e);
    assertTrue("Vertices are wrong", CollectionUtils.isEqualCollection(vSet, graph.getVertices()));
    assertTrue("Edges are wrong", CollectionUtils.isEqualCollection(eSet, graph.getEdges()));
}

From source file:org.structnetalign.util.GraphMLAdaptorTest.java

@Test
public void testReadInterationGraph() throws IOException, SAXException {
    File file = new File(RESOURCE_DIR + "int_1.graphml.xml");
    UndirectedGraph<Integer, InteractionEdge> graph = GraphMLAdaptor.readInteractionGraph(file);
    HashSet<Integer> vertexIds = new HashSet<Integer>();
    vertexIds.add(0);/*w  ww .  j  a  v  a 2  s  . c  o m*/
    vertexIds.add(2);
    vertexIds.add(4);
    vertexIds.add(5);
    assertTrue("Vertices are wrong", CollectionUtils.isEqualCollection(vertexIds, graph.getVertices()));
    HashSet<InteractionEdge> weights = new HashSet<>();
    weights.add(new InteractionEdge(0, 0.1));
    weights.add(new InteractionEdge(1, 0.3));
    weights.add(new InteractionEdge(2, 0.6));
    assertTrue("Edges are wrong", CollectionUtils.isEqualCollection(weights, graph.getEdges()));
}

From source file:org.talend.designer.core.ui.AbstractMultiPageTalendEditor.java

/**
 * DOC hcw Comment method "restorePropertyInformation".
 *//*from w  w w  .ja  v  a 2s. co m*/
protected void savePropertyIfNeededForErrorStatus() {
    if (designerEditor.isReadOnly()) {
        return;
    }
    Property property = processEditorInput.getItem().getProperty();
    if (propertyInformation != null
            && !CollectionUtils.isEqualCollection(propertyInformation, property.getInformations())) {
        Problems.computePropertyMaxInformationLevel(property, true);
    }
}

From source file:org.trnltk.testutil.testmatchers.ParseResultsEqualMatcher.java

@Override
public boolean matchesSafely(Collection<String> item) {
    if (ignoreVerbPresA3Sg) // filter out some verb results to make the test have less results
        item = Collections2.filter(item, Predicates.not(Predicates.containsPattern("\\Zero\\+Pres\\+")));
    return CollectionUtils.isEqualCollection(expectedParseResults, item);
}