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.apache.flink.runtime.messages.webmonitor.MultipleJobsDetails.java

@Override
public boolean equals(Object o) {
    if (this == o) {
        return true;
    }//from   w  w  w  .  ja va 2 s.  c o  m
    if (o == null || getClass() != o.getClass()) {
        return false;
    }
    MultipleJobsDetails that = (MultipleJobsDetails) o;

    return CollectionUtils.isEqualCollection(running, that.running)
            && CollectionUtils.isEqualCollection(finished, that.finished);
}

From source file:org.apache.gobblin.ingestion.google.webmaster.GoogleWebmasterDataFetcherImplTest.java

@Test
public void testGetAllPagesWhenDataSizeLessThan5000AndRequestAll() throws Exception {
    GoogleWebmasterClient client = Mockito.mock(GoogleWebmasterClient.class);
    List<String> allPages = new ArrayList<>();
    for (int i = 0; i < 10; ++i) {
        allPages.add(Integer.toString(i));
    }/*w  w w. j a v a 2s  .c  o  m*/
    Mockito.when(client.getPages(eq(_property), any(String.class), any(String.class), eq("ALL"),
            any(Integer.class), any(List.class), any(List.class), eq(0))).thenReturn(allPages);

    WorkUnitState workUnitState = new WorkUnitState();
    workUnitState.setProp(GoogleWebMasterSource.KEY_PROPERTY, _property);

    GoogleWebmasterDataFetcher dataFetcher = new GoogleWebmasterDataFetcherImpl(_property, client,
            workUnitState);
    Collection<ProducerJob> response = dataFetcher.getAllPages(null, null, "ALL", 5000);

    List<String> pageStrings = new ArrayList<>();
    for (ProducerJob page : response) {
        pageStrings.add(page.getPage());
    }

    Assert.assertTrue(CollectionUtils.isEqualCollection(pageStrings, allPages));
    Mockito.verify(client, Mockito.times(2)).getPages(eq(_property), any(String.class), any(String.class),
            eq("ALL"), any(Integer.class), any(List.class), any(List.class), eq(0));
}

From source file:org.apache.ignite.internal.processors.cache.datastructures.GridCacheQueueMultiNodeConsistencySelfTest.java

/**
 * Starts {@code GRID_CNT} nodes, broadcasts {@code AddAllJob} to them then starts new grid and
 * reads cache queue content and finally asserts queue content is the same.
 *
 * @throws Exception If failed.//  ww  w .j a  va2  s.co  m
 */
private void checkCacheQueue() throws Exception {
    startGrids(GRID_CNT);

    final String queueName = UUID.randomUUID().toString();

    IgniteQueue<Integer> queue0 = grid(0).queue(queueName, QUEUE_CAPACITY, config(false));

    assertTrue(queue0.isEmpty());

    grid(0).compute().broadcast(new AddAllJob(queueName, RETRIES));

    assertEquals(GRID_CNT * RETRIES, queue0.size());

    if (stopRandomGrid)
        stopGrid(1 + new Random().nextInt(GRID_CNT));

    if (forceRepartition) {
        for (int i = 0; i < GRID_CNT; i++) {
            IgniteKernal ignite = (IgniteKernal) grid(i);

            boolean found = false;

            for (GridCacheContext ctx : ignite.context().cache().context().cacheContexts()) {
                if (ctx.name() != null && ctx.name().startsWith("datastructures")) {
                    ctx.cache().rebalance().get();

                    found = true;
                }
            }

            assertTrue(found);
        }
    }

    Ignite newIgnite = startGrid(GRID_CNT + 1);

    // Intentionally commented code cause in this way inconsistent queue problem doesn't appear.
    // IgniteQueue<Integer> newQueue = newGrid.cache().queue(queueName);
    // assertTrue(CollectionUtils.isEqualCollection(queue0, newQueue));

    Collection<Integer> locQueueContent = compute(newIgnite.cluster().forLocal())
            .call(new IgniteCallable<Collection<Integer>>() {
                @IgniteInstanceResource
                private Ignite grid;

                /** {@inheritDoc} */
                @Override
                public Collection<Integer> call() throws Exception {
                    Collection<Integer> values = new ArrayList<>();

                    grid.log().info(
                            "Running job [node=" + grid.cluster().localNode().id() + ", job=" + this + "]");

                    IgniteQueue<Integer> locQueue = grid.queue(queueName, QUEUE_CAPACITY, config(false));

                    grid.log().info("Queue size " + locQueue.size());

                    for (Integer element : locQueue)
                        values.add(element);

                    return values;
                }
            });

    assertTrue(CollectionUtils.isEqualCollection(queue0, locQueueContent));

    queue0.close();
}

From source file:org.apache.marmotta.kiwi.sparql.test.KiWiSparqlJoinTest.java

private void compareResults(TupleQueryResult result1, TupleQueryResult result2)
        throws QueryEvaluationException {
    List<BindingSet> bindingSets1 = Iterations.asList(result1);
    List<BindingSet> bindingSets2 = Iterations.asList(result2);

    Set<Set<Pair>> set1 = new HashSet<Set<Pair>>(Lists.transform(bindingSets1, new BindingSetPairFunction()));
    Set<Set<Pair>> set2 = new HashSet<Set<Pair>>(Lists.transform(bindingSets2, new BindingSetPairFunction()));

    for (Set<Pair> p : set1) {
        Assert.assertTrue("binding " + p + " from result set not found in reference set", set2.contains(p));
    }/*from  w ww .  java 2  s  .c o  m*/
    for (Set<Pair> p : set2) {
        Assert.assertTrue("binding " + p + " from reference set not found in result set", set1.contains(p));
    }

    Assert.assertTrue(CollectionUtils.isEqualCollection(set1, set2));
}

From source file:org.apache.maven.archetype.mojos.IntegrationTestMojo.java

/**
 * Checks that actual directory content is the same as reference.
 *
 * @param reference the reference directory
 * @param actual    the actual directory to compare with the reference
 * @throws IntegrationTestFailure if content differs
 *//*from  w w  w.j  ava  2s .  c o  m*/
private void assertDirectoryEquals(File reference, File actual) throws IntegrationTestFailure, IOException {
    List<String> referenceFiles = FileUtils.getFileAndDirectoryNames(reference, "**", null, false, true, true,
            true);
    getLog().debug("reference content: " + referenceFiles);

    List<String> actualFiles = FileUtils.getFileAndDirectoryNames(actual, "**", null, false, true, true, true);
    getLog().debug("actual content: " + referenceFiles);

    boolean fileNamesEquals = CollectionUtils.isEqualCollection(referenceFiles, actualFiles);

    if (!fileNamesEquals) {
        getLog().debug("Actual list of files is not the same as reference:");
        int missing = 0;
        for (String ref : referenceFiles) {
            if (actualFiles.contains(ref)) {
                actualFiles.remove(ref);
                getLog().debug("Contained " + ref);
            } else {
                missing++;
                getLog().error("Not contained " + ref);
            }
        }
        getLog().error("Remains " + actualFiles);

        throw new IntegrationTestFailure("Reference and generated project differs (missing: " + missing
                + ", unexpected: " + actualFiles.size() + ")");
    }

    boolean contentEquals = true;

    for (String file : referenceFiles) {
        File referenceFile = new File(reference, file);
        File actualFile = new File(actual, file);

        if (referenceFile.isDirectory()) {
            if (actualFile.isFile()) {
                getLog().warn("File " + file + " is a directory in the reference but a file in actual");
                contentEquals = false;
            }
        } else if (actualFile.isDirectory()) {
            if (referenceFile.isFile()) {
                getLog().warn("File " + file + " is a file in the reference but a directory in actual");
                contentEquals = false;
            }
        } else if (!contentEquals(referenceFile, actualFile)) {
            getLog().warn("Contents of file " + file + " are not equal");
            contentEquals = false;
        }
    }
    if (!contentEquals) {
        throw new IntegrationTestFailure("Some content are not equals");
    }
}

From source file:org.apache.phoenix.flume.serializer.JsonEventSerializer.java

/**
  * //from www .j  a  v a2 s  . co  m
  */
@Override
public void doConfigure(Context context) {
    final String jsonData = context.getString(CONFIG_COLUMNS_MAPPING, JSON_DEFAULT);
    try {
        jsonSchema = new JSONObject(jsonData);
        if (jsonSchema.length() == 0) {
            for (String colName : colNames) {
                jsonSchema.put(colName, colName);
            }
            isProperMapping = true;
        } else {
            Iterator<String> keys = jsonSchema.keys();
            List<String> keylist = new ArrayList<String>();
            while (keys.hasNext()) {
                keylist.add(keys.next());
            }
            isProperMapping = CollectionUtils.isEqualCollection(keylist, colNames);
        }
    } catch (JSONException e) {
        e.printStackTrace();
        logger.debug("json mapping not proper, verify the data {} ", jsonData);
    }
    partialSchema = context.getBoolean(CONFIG_PARTIAL_SCHEMA, false);
}

From source file:org.apache.ranger.plugin.policyresourcematcher.RangerDefaultPolicyResourceMatcher.java

@Override
public boolean isCompleteMatch(RangerAccessResource resource, Map<String, Object> evalContext) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> RangerDefaultPolicyResourceMatcher.isCompleteMatch(" + resource + ", " + evalContext
                + ")");
    }/*  w  w w  .ja v a2s  .  c  o  m*/

    boolean ret = false;

    if (serviceDef != null && serviceDef.getResources() != null) {
        Collection<String> resourceKeys = resource == null ? null : resource.getKeys();
        Collection<String> policyKeys = matchers == null ? null : matchers.keySet();

        boolean keysMatch = false;

        if (resourceKeys != null && policyKeys != null) {
            keysMatch = CollectionUtils.isEqualCollection(resourceKeys, policyKeys);
        }

        if (keysMatch) {
            for (RangerResourceDef resourceDef : serviceDef.getResources()) {
                String resourceName = resourceDef.getName();
                String resourceValue = resource == null ? null : resource.getValue(resourceName);
                RangerResourceMatcher matcher = matchers == null ? null : matchers.get(resourceName);

                if (StringUtils.isEmpty(resourceValue)) {
                    ret = matcher == null || matcher.isCompleteMatch(resourceValue, evalContext);
                } else {
                    ret = matcher != null && matcher.isCompleteMatch(resourceValue, evalContext);
                }

                if (!ret) {
                    break;
                }
            }
        } else {
            if (LOG.isDebugEnabled()) {
                LOG.debug("isCompleteMatch(): keysMatch=false. resourceKeys=" + resourceKeys + "; policyKeys="
                        + policyKeys);
            }
        }
    }

    if (LOG.isDebugEnabled()) {
        LOG.debug("<== RangerDefaultPolicyResourceMatcher.isCompleteMatch(" + resource + ", " + evalContext
                + "): " + ret);
    }

    return ret;
}

From source file:org.apache.ranger.plugin.policyresourcematcher.RangerDefaultPolicyResourceMatcher.java

@Override
public boolean isCompleteMatch(Map<String, RangerPolicyResource> resources, Map<String, Object> evalContext) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> RangerDefaultPolicyResourceMatcher.isCompleteMatch(" + resources + ", " + evalContext
                + ")");
    }/*  w  w  w .ja  v a  2 s. c om*/

    boolean ret = false;

    if (serviceDef != null && serviceDef.getResources() != null) {
        Collection<String> resourceKeys = resources == null ? null : resources.keySet();
        Collection<String> policyKeys = matchers == null ? null : matchers.keySet();

        boolean keysMatch = false;

        if (resourceKeys != null && policyKeys != null) {
            keysMatch = CollectionUtils.isEqualCollection(resourceKeys, policyKeys);
        }

        if (keysMatch) {
            for (RangerResourceDef resourceDef : serviceDef.getResources()) {
                String resourceName = resourceDef.getName();
                RangerPolicyResource resourceValues = resources == null ? null : resources.get(resourceName);
                RangerPolicyResource policyValues = policyResources == null ? null
                        : policyResources.get(resourceName);

                if (resourceValues == null || CollectionUtils.isEmpty(resourceValues.getValues())) {
                    ret = (policyValues == null || CollectionUtils.isEmpty(policyValues.getValues()));
                } else if (policyValues != null && CollectionUtils.isNotEmpty(policyValues.getValues())) {
                    ret = CollectionUtils.isEqualCollection(resourceValues.getValues(),
                            policyValues.getValues());
                }

                if (!ret) {
                    break;
                }
            }
        } else {
            if (LOG.isDebugEnabled()) {
                LOG.debug("isCompleteMatch(): keysMatch=false. resourceKeys=" + resourceKeys + "; policyKeys="
                        + policyKeys);
            }
        }
    }

    if (LOG.isDebugEnabled()) {
        LOG.debug("<== RangerDefaultPolicyResourceMatcher.isCompleteMatch(" + resources + ", " + evalContext
                + "): " + ret);
    }

    return ret;
}

From source file:org.apache.ranger.rest.ServiceTagsProcessor.java

private RangerTag findMatchingTag(RangerTag incomingTag, List<RangerTag> existingTags) throws Exception {

    RangerTag ret = null;/*w w  w.  j  av  a 2  s . co m*/

    if (StringUtils.isNotEmpty(incomingTag.getGuid())) {
        ret = tagStore.getTagByGuid(incomingTag.getGuid());
    }

    if (ret == null) {

        if (isResourcePrivateTag(incomingTag)) {

            for (RangerTag existingTag : existingTags) {

                if (StringUtils.equals(incomingTag.getType(), existingTag.getType())) {

                    // Check attribute values
                    Map<String, String> incomingTagAttributes = incomingTag.getAttributes();
                    Map<String, String> existingTagAttributes = existingTag.getAttributes();

                    if (CollectionUtils.isEqualCollection(incomingTagAttributes.keySet(),
                            existingTagAttributes.keySet())) {

                        boolean matched = true;

                        for (Map.Entry<String, String> entry : incomingTagAttributes.entrySet()) {

                            String key = entry.getKey();
                            String value = entry.getValue();

                            if (!StringUtils.equals(value, existingTagAttributes.get(key))) {
                                matched = false;
                                break;
                            }

                        }
                        if (matched) {
                            ret = existingTag;
                            break;
                        }
                    }

                }
            }
        }

    }

    return ret;
}

From source file:org.apache.sling.api.wrappers.CompositeValueMapTest.java

private void verifyResults(CompositeValueMap valueMap, Set<CompositeValueMapTestResult> expectations) {
    Map<String, Object> expectedMap = new HashMap<String, Object>();

    int expectedSize = 0;
    for (CompositeValueMapTestResult testResult : expectations) {
        String property = testResult.propertyName;

        if (testResult.doesNotExist()) {
            Assert.assertFalse("Property '" + property + "' should NOT exist", valueMap.containsKey(property));

        } else if (testResult.shouldBeDeleted()) {
            Assert.assertFalse("Property '" + property + "' should NOT be part of the final map",
                    valueMap.containsKey(property));
            Assert.assertNull("Property '" + property + "' should be null", valueMap.get(property));

        } else {/* w  w w .  j  a  va  2 s  . co m*/
            Assert.assertTrue("Property '" + property + "' should be part of the final map",
                    valueMap.containsKey(property));
            expectedSize++;

            if (testResult.shouldBeUnchanged()) {
                Assert.assertEquals("Property '" + property + "' should NOT have changed",
                        testResult.defaultValue, valueMap.get(property));
                expectedMap.put(property, testResult.defaultValue);
            }

            if (testResult.shouldBeOverriden()) {
                Assert.assertEquals("Property '" + property + "' should have changed", testResult.extendedValue,
                        valueMap.get(property));
                expectedMap.put(property, testResult.extendedValue);
            }

            if (testResult.shouldHaveNewType()) {
                Assert.assertTrue("Type of property '" + property + "' should have changed",
                        valueMap.get(property).getClass().equals(testResult.expectedNewType));
                expectedMap.put(property, testResult.extendedValue);
            }

            if (testResult.shouldBeAdded()) {
                Assert.assertEquals("Property '" + property + "' should have been added",
                        testResult.extendedValue, valueMap.get(property));
                expectedMap.put(property, testResult.extendedValue);
            }
        }
    }

    Assert.assertEquals("Final map size does NOT match", expectedSize, valueMap.size());
    Assert.assertEquals("Final map entries do NOT match", expectedMap.entrySet(), valueMap.entrySet());
    Assert.assertEquals("Final map keys do NOT match", expectedMap.keySet(), valueMap.keySet());
    Assert.assertTrue(
            "Final map values do NOT match expected: <" + expectedMap.values() + "> but was: <"
                    + valueMap.values() + ">",
            CollectionUtils.isEqualCollection(expectedMap.values(), valueMap.values()));
}