Example usage for org.apache.commons.collections4 CollectionUtils containsAll

List of usage examples for org.apache.commons.collections4 CollectionUtils containsAll

Introduction

In this page you can find the example usage for org.apache.commons.collections4 CollectionUtils containsAll.

Prototype

public static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2) 

Source Link

Document

Returns true iff all elements of coll2 are also contained in coll1 .

Usage

From source file:com.norconex.collector.http.url.impl.HtmlLinkExtractor.java

@Override
public boolean equals(final Object other) {
    if (!(other instanceof HtmlLinkExtractor)) {
        return false;
    }//w w w.ja v  a  2s  .  c o  m

    HtmlLinkExtractor castOther = (HtmlLinkExtractor) other;
    return new EqualsBuilder().append(contentTypes, castOther.contentTypes)
            .append(maxURLLength, castOther.maxURLLength).append(ignoreNofollow, castOther.ignoreNofollow)
            .append(keepReferrerData, castOther.keepReferrerData).isEquals()
            && CollectionUtils.containsAll(tagAttribs.entrySet(), castOther.tagAttribs.entrySet());
}

From source file:org.apache.nutch.mapreduce.NutchCounter.java

private void registerCounters(ArrayList<String> names) {
    countersCount.set(names.size());//ww w . j a  v a 2 s . c  om

    for (int i = 0; i < countersCount.get(); ++i) {
        counterNames.add(names.get(i));
        counterIndexes.put(names.get(i), i);
        globalCounters.add(new AtomicInteger(0));
        nativeCounters.add(new AtomicInteger(0));
    }

    if (countersCount.get() == 0) {
        LOG.warn("No counters, will not run report thread");
    }

    Validate.isTrue(counterIndexes.size() == counterNames.size());
    Validate.isTrue(counterIndexes.size() == countersCount.get());
    Validate.isTrue(CollectionUtils.containsAll(counterIndexes.keySet(), counterNames));

    LOG.info("Registered counters : " + StringUtils.join(MapUtils.invertMap(counterIndexes).entrySet(), ", "));
}

From source file:org.cryptomator.frontend.webdav.WebDavServerTest.java

@Test
public void testPropfind() throws HttpException, IOException, ParserConfigurationException, SAXException,
        XPathException, DavException {
    final HttpClient client = new HttpClient();

    fs.folder("folder1").create();
    fs.folder("folder2").create();
    try (WritableFile w = fs.file("file1").openWritable()) {
        w.write(ByteBuffer.allocate(0));
    }// w  w w  .  ja va  2  s  . co  m

    // get directory listing of /:
    final DavMethodBase propfindMethod = new PropFindMethod(servletRoot + "/");
    final int statusCode = client.executeMethod(propfindMethod);
    Assert.assertEquals(207, statusCode);

    // get hrefs contained in dirlisting response:
    MultiStatus ms = propfindMethod.getResponseBodyAsMultiStatus();
    propfindMethod.releaseConnection();
    Collection<String> hrefs = Arrays.asList(ms.getResponses()).stream().map(MultiStatusResponse::getHref)
            .collect(Collectors.toSet());

    Assert.assertTrue(CollectionUtils.containsAll(hrefs,
            Arrays.asList(servletRoot + "/folder1/", servletRoot + "/folder2/", servletRoot + "/file1")));
}

From source file:org.sigmah.server.security.AccessRightsTest.java

/**
 * Tests the {@code contains} logic used with permissions collections.
 *///from ww  w .j a  v a  2s .co  m
@Test
public void testContainsPermissions() {

    final Set<GlobalPermissionEnum> permissions = new HashSet<GlobalPermissionEnum>();
    permissions.add(GlobalPermissionEnum.CREATE_PROJECT);
    permissions.add(GlobalPermissionEnum.EDIT_PROJECT);

    Assert.assertTrue(CollectionUtils.containsAll(permissions, set()));
    Assert.assertTrue(CollectionUtils.containsAll(permissions, set((GlobalPermissionEnum) null)));
    Assert.assertTrue(CollectionUtils.containsAll(permissions, set((GlobalPermissionEnum[]) null)));
    Assert.assertTrue(CollectionUtils.containsAll(permissions, set(GlobalPermissionEnum.CREATE_PROJECT)));
    Assert.assertTrue(CollectionUtils.containsAll(permissions, set(GlobalPermissionEnum.EDIT_PROJECT)));
    Assert.assertTrue(CollectionUtils.containsAll(permissions,
            set(GlobalPermissionEnum.CREATE_PROJECT, GlobalPermissionEnum.EDIT_PROJECT)));

    Assert.assertFalse(CollectionUtils.containsAll(permissions, set(GlobalPermissionEnum.CREATE_PROJECT,
            GlobalPermissionEnum.EDIT_PROJECT, GlobalPermissionEnum.DELETE_PROJECT)));

    Assert.assertFalse(CollectionUtils.containsAll(permissions, set(GlobalPermissionEnum.CREATE_PROJECT,
            GlobalPermissionEnum.DELETE_PROJECT, GlobalPermissionEnum.VIEW_ADMIN)));

    Assert.assertFalse(CollectionUtils.containsAll(permissions,
            set(GlobalPermissionEnum.DELETE_PROJECT, GlobalPermissionEnum.VIEW_ADMIN)));
}

From source file:org.sigmah.server.security.impl.AccessRights.java

/**
 * Grants or refuse {@code user} access to the given {@code token}.
 * /*w ww.ja  va2s. c o m*/
 * @param user
 *          The user (authenticated or anonymous).
 * @param token
 *          The resource token (page, command, servlet method, etc.).
 * @param originPageToken
 *          The origin page token <em>(TODO Not used yet)</em>.
 * @param mapper
 *          The mapper service.
 * @return {@code true} if the user is granted, {@code false} otherwise.
 */
static boolean isGranted(final User user, final String token, final String originPageToken,
        final Mapper mapper) {

    if (grantedTokens.contains(token)) {
        // Granted tokens ; avoids profile aggregation if user is authenticated.
        return true;
    }

    if (!permissions.containsKey(token)) {
        if (LOG.isWarnEnabled()) {
            LOG.warn(
                    "No security permission can be found for token '{}'. Did you forget to declare corresponding 'sperm'?",
                    token);
        }
        return isGranted(user, MISSING_TOKEN, originPageToken, mapper);
    }

    final Pair<GrantType, Set<GlobalPermissionEnum>> grantData = permissions.get(token);
    final GrantType grantType = grantData.left;

    final boolean granted;

    if (user == null || ServletExecutionContext.ANONYMOUS_USER.equals(user)) {
        // Anonymous user.
        granted = grantType != null && grantType != GrantType.AUTHENTICATED_ONLY;

    } else {
        // Authenticated user.
        if (grantType != null && grantType == GrantType.ANONYMOUS_ONLY) {
            granted = false;

        } else {
            final ProfileDTO aggregatedProfile = Handlers.aggregateProfiles(user, mapper);
            granted = CollectionUtils.containsAll(aggregatedProfile.getGlobalPermissions(), grantData.right);
        }
    }

    return granted;
}