Example usage for java.util Collections disjoint

List of usage examples for java.util Collections disjoint

Introduction

In this page you can find the example usage for java.util Collections disjoint.

Prototype

public static boolean disjoint(Collection<?> c1, Collection<?> c2) 

Source Link

Document

Returns true if the two specified collections have no elements in common.

Usage

From source file:es.upv.grc.grcbox.server.GrcBoxServerApplication.java

/**
 * Launches the application with an HTTP server.
 * /*from   www  . j  a va 2  s  .  co m*/
 * @param args
 *            The arguments.
 * @throws Exception
 */
public static void main(String[] args) throws Exception {
    //Load Config File
    LOG.info("Working Directory = " + System.getProperty("user.dir"));
    File file = new File("./config.json");
    ObjectMapper mapper = new ObjectMapper();
    config = mapper.readValue(file, GrcBoxConfig.class);
    if (!Collections.disjoint(config.getInnerInterfaces(), config.getOuterInterfaces())) {
        System.err.print("InnerInterfaces and Outerinterfaces has elements in common. Aborting execution.");
        System.exit(-1);
    }

    LinkedList<String> innerInterfaces = config.getInnerInterfaces();
    RulesDB.setInnerInterfaces(innerInterfaces);
    RulesDB.initialize();
    for (String string : innerInterfaces) {
        startServer(string);
    }
}

From source file:Main.java

/**
 * Checks whether any element of a collection is present in another one.
 *
 * @param <A> Key type//from w  w w. j  ava  2  s.c om
 * @param collection1 Container collection
 * @param collection2 Collection with elements to be checked
 * @return {@code true} if any element in {@code collection} is present in {@code container}, and {@code false} otherwise. If {@code container} is empty, it will return {@code false}
 */
public static <A> boolean containsAny(Collection<A> collection1, Collection<A> collection2) {
    return !Collections.disjoint(collection1, collection2);
}

From source file:Main.java

/**
 * Returns <code>true</code> if <code>source</code> contains at least one
 * element in <code>target</code>.
 * /*from  ww  w  . j  ava  2 s  .c  o  m*/
 * @param source the source <code>Collection</code>
 * @param target the target <code>Collection</code>
 * @return <code>true</code> if <code>source</code> contains at least one
 *         element in <code>target</code> and <code>false</code> otherwise
 */
public static boolean containsSome(Collection<?> source, Collection<?> target) {
    if (source == target)
        return true;
    if ((source == null) != (target == null))
        return false;
    return !Collections.disjoint(source, target);
}

From source file:org.apache.oodt.cas.crawl.action.MimeTypeCrawlerAction.java

@Override
public boolean performAction(File product, Metadata productMetadata) throws CrawlerActionException {
    List<String> mimeTypeHierarchy = productMetadata.getAllMetadata(MIME_TYPES_HIERARCHY);
    if (mimeTypeHierarchy == null) {
        mimeTypeHierarchy = new Vector<String>();
    }//  w ww .j a va2 s. c  o  m
    if (mimeTypes == null || (!Collections.disjoint(mimeTypes, mimeTypeHierarchy))) {
        return this.actionToCall.performAction(product, productMetadata);
    } else {
        LOG.log(Level.INFO, "Skipping action (id = " + this.getId() + " : description = "
                + this.getDescription() + " - doesn't apply to current product");
        return true;
    }
}

From source file:fm.pattern.tokamak.authorization.AuthorizationAdvisor.java

private void checkScopes(String input) {
    Set<String> scopes = StringTokenizer.tokenize(input);
    Set<String> grantedScopes = provider.getScopes();

    if (Collections.disjoint(scopes, grantedScopes)) {
        throw new AuthorizationException(new Reportable("auth.invalid.scope"));
    }//from   ww  w.  jav a  2  s  . c o m
}

From source file:org.joyrest.oauth2.interceptor.AuthorizationInterceptor.java

@Override
public InternalResponse<Object> around(InterceptorChain chain, InternalRequest<Object> req,
        InternalResponse<Object> resp) throws Exception {
    InternalRoute route = chain.getRoute();
    if (!route.isSecured()) {
        return chain.proceed(req, resp);
    }/*from w  ww . j  ava2 s .  co m*/

    Authentication authentication = req.getPrincipal().filter(principal -> principal instanceof Authentication)
            .map(principal -> (Authentication) principal).orElseThrow(
                    () -> new InvalidConfigurationException("Principal object is not Authentication type."));

    List<String> authorities = authentication.getAuthorities().stream().map(GrantedAuthority::getAuthority)
            .collect(toList());

    if (Collections.disjoint(authorities, route.getRoles())) {
        throw new UserDeniedAuthorizationException("User denied access");
    }

    return chain.proceed(req, resp);
}

From source file:fm.pattern.tokamak.authorization.AuthorizationAdvisor.java

private void checkRoles(String input) {
    Set<String> roles = StringTokenizer.tokenize(input);
    Set<String> grantedRoles = provider.getRoles();

    if (Collections.disjoint(roles, grantedRoles)) {
        throw new AuthorizationException(new Reportable("auth.invalid.role"));
    }//from   w  w  w . j a  va 2  s .c om
}

From source file:org.jboss.tools.ws.ui.bot.test.websocket.StubMethodsHelper.java

/**
 * Stub proposal should be in current proposals if and only if
 * collection shouldBe contains it.//from   w  ww  .  j a  v a 2s  . c o  m
 *
 * @param editor   
 * @param shouldBe
 */
static void assertThereAreOnlySpecifiedStubProposals(TextEditor editor, Collection<String> shouldBe) {

    //Preparing collections
    List<String> proposals = new ArrayList<>(EXPECTED_PROPOSALS);
    proposals.removeAll(shouldBe);
    List<String> shouldNotBe = proposals;

    ContentAssistant contentAssistant = openContentAssistant(editor);
    List<String> actualProposals = contentAssistant.getProposals();
    contentAssistant.close();

    //check
    assertTrue("There are not all expected proposals!", actualProposals.containsAll(shouldBe));
    assertTrue("There are proposals those should not be there!",
            Collections.disjoint(actualProposals, shouldNotBe));
}

From source file:org.pentaho.platform.web.http.api.resources.utils.SystemUtils.java

public static boolean canDownload(String downloadDir) {
    IAuthorizationPolicy policy = PentahoSystem.get(IAuthorizationPolicy.class);

    IUserRoleListService userRoleListService = PentahoSystem.get(IUserRoleListService.class);
    String tenantedUserName = PentahoSessionHolder.getSession().getName();
    List<String> tenantedUserRoles = userRoleListService
            .getRolesForUser(JcrTenantUtils.getUserNameUtils().getTenant(tenantedUserName), tenantedUserName);

    //check if we are admin or have download-roles
    boolean isAdminOrHaveDownloadActionRole = policy.isAllowed(RepositoryReadAction.NAME)
            && policy.isAllowed(RepositoryCreateAction.NAME) && (policy.isAllowed(AdministerSecurityAction.NAME)
                    || !Collections.disjoint(tenantedUserRoles, PentahoSystem.getDownloadRolesList()));

    //the user does not have admin or download-roles assigned, so we will check if the user downloads from their home folder
    if (!isAdminOrHaveDownloadActionRole && !StringUtils.isEmpty(downloadDir)) {
        return validateAccessToHomeFolder(downloadDir);
    }/* ww w .ja  va  2s.  c  o  m*/

    return isAdminOrHaveDownloadActionRole;
}

From source file:fm.pattern.tokamak.authorization.AuthorizationAdvisor.java

private void checkAuthorities(String input) {
    Set<String> authorities = StringTokenizer.tokenize(input);
    Set<String> grantedAuthorities = provider.getAuthorities();

    if (Collections.disjoint(authorities, grantedAuthorities)) {
        throw new AuthorizationException(new Reportable("auth.invalid.authority"));
    }/*  ww w. ja v a 2  s . c o  m*/
}