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

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

Introduction

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

Prototype

public static boolean containsAny(final Collection coll1, final Collection coll2) 

Source Link

Document

Returns true iff at least one element is in both collections.

Usage

From source file:com.opengamma.engine.view.compilation.CompiledViewDefinitionImpl.java

/**
 * Equivalent to getMarketDataRequirements().keySet().containsAny(requirements), but faster
 * @param requirements The requirements to match
 * @return Whether any of the provider requirements are market data requirements of this view definition 
 *//*from w  ww  . j a  v  a 2  s  .  c  om*/
public boolean hasAnyMarketDataRequirements(Collection<ValueRequirement> requirements) {
    for (CompiledViewCalculationConfiguration compiledCalcConfig : getCompiledCalculationConfigurations()) {
        if (CollectionUtils.containsAny(compiledCalcConfig.getMarketDataRequirements().keySet(),
                requirements)) {
            return true;
        }
    }
    return false;
}

From source file:com.dgtlrepublic.anitomyj.Token.java

/**
 * Validates a token against the {@code flags}. The {@code flags} is used as a search parameter.
 *
 * @param token the token/*from   w  w  w  .  ja  v a  2 s.c  o  m*/
 * @param flags the flags the token must conform against
 * @return true if the token conforms to the set of {@code flags}; false otherwise
 */
public static boolean checkTokenFlags(Token token, EnumSet<TokenFlag> flags) {
    /** simple alias to check if flag is a part of the set */
    Function<TokenFlag, Boolean> checkFlag = flags::contains;

    /** make sure token is the correct closure */
    if (CollectionUtils.containsAny(flags, kFlagMaskEnclosed)) {
        boolean success = checkFlag.apply(kFlagEnclosed) == token.enclosed;
        if (!success)
            return false; /** not enclosed correctly (e.g enclosed when we're looking for non-enclosed) */
    }

    /** make sure token is the correct category */
    if (CollectionUtils.containsAny(flags, kFlagMaskCategories)) {
        AtomicBoolean success = new AtomicBoolean(false);
        TriConsumer<TokenFlag, TokenFlag, TokenCategory> checkCategory = (fe, fn, c) -> {
            if (!success.get()) {
                boolean result = checkFlag.apply(fe) ? token.category == c
                        : checkFlag.apply(fn) && token.category != c;
                success.set(result);
            }
        };

        checkCategory.accept(kFlagBracket, kFlagNotBracket, kBracket);
        checkCategory.accept(kFlagDelimiter, kFlagNotDelimiter, kDelimiter);
        checkCategory.accept(kFlagIdentifier, kFlagNotIdentifier, kIdentifier);
        checkCategory.accept(kFlagUnknown, kFlagNotUnknown, kUnknown);
        checkCategory.accept(kFlagNotValid, kFlagValid, kInvalid);
        if (!success.get())
            return false;
    }

    return true;
}

From source file:com.adobe.acs.commons.httpcache.config.impl.ResourcePropertiesHttpCacheConfigExtension.java

@Override
public boolean accepts(SlingHttpServletRequest request, HttpCacheConfig cacheConfig,
        Map<String, String[]> allowedKeyValues) {
    for (final Map.Entry<String, String[]> entry : allowedKeyValues.entrySet()) {
        final ValueMap properties = request.getResource().getValueMap();

        if (properties.containsKey(entry.getKey())) {
            final String[] propertyValues = properties.get(entry.getKey(), String[].class);

            if (ArrayUtils.isEmpty(propertyValues)) {
                // If no values were specified, then assume ANY and ALL values are acceptable, and were are merely looking for the existence of the property
                return true;
            } else if (CollectionUtils.containsAny(Arrays.asList(entry.getValue()),
                    Arrays.asList(propertyValues))) {
                // The resource property value matched one of the allowed values
                return true;
            }//from w w  w  .  j  a v a2s  . c om
            // No matches found for this row; continue looking through the allowed list
        }
    }

    // No valid resource property could be found.
    return false;
}

From source file:com.adobe.acs.commons.httpcache.config.impl.RequestParameterHttpCacheConfigExtension.java

@Override
public boolean accepts(SlingHttpServletRequest request, HttpCacheConfig cacheConfig,
        Map<String, String[]> allowedKeyValues) {
    for (final Map.Entry<String, String[]> entry : allowedKeyValues.entrySet()) {

        if (request.getParameterMap().keySet().contains(entry.getKey())) {
            final String[] parameterValues = request.getParameterMap().get(entry.getKey());

            if (ArrayUtils.isEmpty(entry.getValue())) {
                // If no values were specified, then assume ANY and ALL values are acceptable, and were are merely looking for the existence of the request parameter
                return true;
            } else if (CollectionUtils.containsAny(Arrays.asList(entry.getValue()),
                    Arrays.asList(parameterValues))) {
                // The request parameter value matched one of the allowed values
                return true;
            }//  ww w  . ja v a  2  s.  com
            // No matches found for this row; continue looking through the allowed list
        }
    }

    // No valid request parameter could be found.
    return false;
}

From source file:com.michelin.cio.hudson.plugins.rolegroupstrategy.Role.java

/**
 * Checks if the role holds any of the given {@link Permission}.
 * @param permissions A {@link Permission}s set
 * @return True if the role holds any of the given {@link Permission}s
 *//*from w ww . j a  va  2s  .com*/
public final Boolean hasAnyPermission(Set<Permission> permissions) {
    return CollectionUtils.containsAny(this.permissions, permissions);
}

From source file:io.brooklyn.ambari.service.AbstractExtraService.java

/**
 * Utility method that will execute the given function on the given nodes, only if they have one of the given components
 * installed on them. The executions will be done in a parallel.
 * @param nodes the nodes to execute the function on.
 * @param fn the function to execute.//from  w  w w.j a v a  2 s.c o  m
 * @param components the list of components for which we want to function to be executed.
 * @return a new pool of tasks.
 */
// TODO: Pass the task's name and description as parameter
protected Task<List<?>> parallelListenerTask(final Iterable<AmbariAgent> nodes,
        final Function<AmbariAgent, ?> fn, List<String> components) {
    Preconditions.checkNotNull(components);

    List<Task<?>> tasks = Lists.newArrayList();
    for (final AmbariAgent ambariAgent : nodes) {
        Preconditions.checkNotNull(ambariAgent.getAttribute(AmbariAgent.COMPONENTS));
        if (!CollectionUtils.containsAny(ambariAgent.getAttribute(AmbariAgent.COMPONENTS), components)) {
            continue;
        }

        Task<?> t = Tasks.builder().name(ambariAgent.toString())
                .description("Invocation on " + ambariAgent.toString())
                .body(new FunctionRunningCallable<AmbariAgent>(ambariAgent, fn))
                .tag(BrooklynTaskTags.NON_TRANSIENT_TASK_TAG).build();
        tasks.add(t);
    }
    return Tasks.parallel("Parallel invocation of " + fn + " on ambari agents", tasks);
}

From source file:com.agiletec.plugins.jpcrowdsourcing.aps.system.services.idea.ApiIdeaInterface.java

/**
 * GET http://localhost:8080/<portal>/api/rs/en/ideaInstances?
 * @param properties/*from  www. jav  a 2  s. c  o  m*/
 * @return
 * @throws Throwable
 */
public List<String> getIdeaListForApi(Properties properties) throws Throwable {
    List<String> result = new ArrayList<String>();
    try {
        Collection<String> groupCodes = this.extractGroups(properties);
        //required params
        String codeParam = properties.getProperty("code");
        if (StringUtils.isNotBlank(codeParam))
            codeParam = URLDecoder.decode(codeParam, "UTF-8");
        IdeaInstance instance = this.getIdeaInstanceManager().getIdeaInstance(codeParam);
        if (null == instance) {
            _logger.warn("instance {} not found", codeParam);
            return null;
        }
        if (!CollectionUtils.containsAny(groupCodes, instance.getGroups())) {
            _logger.warn("the current user is not granted to any group required by instance {}", codeParam);
            return null;
        }
        //optional params
        String textParam = properties.getProperty("text");
        if (StringUtils.isNotBlank(textParam))
            textParam = URLDecoder.decode(codeParam, "UTF-8");
        String tagParam = properties.getProperty("tag");
        String orderParam = properties.getProperty("order");
        Integer order = null;
        if (StringUtils.isNotBlank(orderParam) && orderParam.equalsIgnoreCase("latest")) {
            order = IIdeaDAO.SORT_LATEST;
        } else if (StringUtils.isNotBlank(orderParam) && orderParam.equalsIgnoreCase("rated")) {
            order = IIdeaDAO.SORT_MOST_RATED;
        }
        result = this.getIdeaManager().searchIdeas(codeParam, IIdea.STATUS_APPROVED, textParam, tagParam,
                order);
    } catch (Throwable t) {
        _logger.error("Error loading idea list", t);
        throw new ApsSystemException("Error loading idea list", t);
    }
    return result;
}

From source file:com.silverpeas.sharing.model.NodeAccessControl.java

private boolean isPublicationReadable(WAPrimaryKey pk, String instanceId, Collection<NodePK> autorizedNodes)
        throws RemoteException, CreateException {
    if (pk.getInstanceId().equals(instanceId)) {
        Collection<NodePK> fathers = getPublicationFathers(pk);
        return CollectionUtils.containsAny(autorizedNodes, fathers);
    } else {/*www.  ja  va2 s  .c  o m*/
        // special case of an alias between two ECM applications
        // check if publication which contains attachment is an alias into this node
        Collection<Alias> aliases = getPublicationAliases(pk);
        for (Alias alias : aliases) {
            NodePK aliasPK = new NodePK(alias.getId(), alias.getInstanceId());
            if (autorizedNodes.contains(aliasPK)) {
                return true;
            }
        }
    }
    return false;
}

From source file:com.adobe.acs.commons.httpcache.config.impl.GroupHttpCacheConfigExtension.java

@Override
public boolean accepts(SlingHttpServletRequest request, HttpCacheConfig cacheConfig)
        throws HttpCacheRepositoryAccessException {

    // Match groups.
    if (UserUtils.isAnonymous(request.getResourceResolver().getUserID())) {
        // If the user is anonymous, no matching with groups required.
        return true;
    } else {/*from   w ww.  ja v a  2s  .co  m*/
        // Case of authenticated requests.
        if (userGroups.isEmpty()) {
            // In case custom attributes list is empty.
            if (log.isTraceEnabled()) {
                log.trace("GroupHttpCacheConfigExtension accepts request [ {} ]", request.getRequestURI());
            }
            return true;
        }

        try {
            List<String> requestUserGroupNames = UserUtils
                    .getUserGroupMembershipNames(request.getResourceResolver().adaptTo(User.class));

            // At least one of the group in config should match.
            boolean isGroupMatchFound = CollectionUtils.containsAny(userGroups, requestUserGroupNames);
            if (!isGroupMatchFound) {
                log.trace("Group didn't match and hence rejecting the cache config.");
            } else {
                if (log.isTraceEnabled()) {
                    log.trace("GroupHttpCacheConfigExtension accepts request [ {} ]", request.getRequestURI());
                }
            }
            return isGroupMatchFound;
        } catch (RepositoryException e) {
            throw new HttpCacheRepositoryAccessException("Unable to access group information of request user.",
                    e);
        }
    }
}

From source file:au.com.jwatmuff.genericdb.transaction.TransactionNotifier.java

private void notifyListeners() {
    Map<TransactionListener, Set<Class>> listenersCopy = new HashMap<>(listeners);

    for (Entry<TransactionListener, Set<Class>> entry : listenersCopy.entrySet()) {
        TransactionListener listener = entry.getKey();
        Set<Class> interestingClasses = entry.getValue();

        if (interestingClasses == null || CollectionUtils.containsAny(interestingClasses, classes)) {
            try {
                listener.handleTransactionEvents(events, classes);
            } catch (Exception e) {
                log.error("Error while notifying listener: " + listener, e);
            }/*from w w  w  .  j a  v a  2s. c o m*/
        }
    }
}