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

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

Introduction

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

Prototype

public static Collection select(Collection inputCollection, Predicate predicate) 

Source Link

Document

Selects all elements from input collection which match the given predicate into an output collection.

Usage

From source file:org.sipfoundry.sipxconfig.tunnel.TunnelArchitect.java

@SuppressWarnings("unchecked")
public Collection<RemoteOutgoingTunnel> getRemoteOutgoingTunnels(final Location l) {
    Predicate remoteOnly = new Predicate() {
        @Override//from   w w w  .j a va2 s . co m
        public boolean evaluate(Object o) {
            return !((RemoteOutgoingTunnel) o).getRemoteMachineAddress().equals(l.getAddress());
        }
    };
    return CollectionUtils.select(m_client, remoteOnly);
}

From source file:org.sonar.jpa.dao.MeasuresDao.java

public Collection<Metric> getEnabledMetrics() {
    return CollectionUtils.select(getMetricsByName().values(), new Predicate() {
        public boolean evaluate(Object o) {
            return ((Metric) o).getEnabled();
        }// ww w  . ja v  a 2  s. c o  m
    });
}

From source file:org.sonar.jpa.dao.MeasuresDao.java

public Collection<Metric> getUserDefinedMetrics() {
    return CollectionUtils.select(getMetricsByName().values(), new Predicate() {
        public boolean evaluate(Object o) {
            Metric m = (Metric) o;//from w  ww. j a v  a 2 s  .  c  om
            return (m.getEnabled() && m.getOrigin() != Metric.Origin.JAV);
        }
    });
}

From source file:org.squashtest.tm.web.internal.controller.generic.WorkspaceController.java

/**
 * @param wizards/*  w  ww.  jav a2s.co  m*/
 * @return
 */
@SuppressWarnings("all")
private MenuItem[] menuItems(Collection<WorkspaceWizard> wizards) {
    Collection<WorkspaceWizard> effective = CollectionUtils.select(wizards, new Predicate() {
        @Override
        public boolean evaluate(Object object) {
            return (((WorkspaceWizard) object).getWizardMenu() != null);
        }
    });

    MenuItem[] res = new MenuItem[effective.size()];
    int i = 0;

    for (WorkspaceWizard wizard : wizards) {
        if (wizard.getWizardMenu() != null) {
            res[i] = createMenuItem(wizard);
            i++;
        }
    }

    return res;
}

From source file:org.squashtest.tm.web.internal.interceptor.ExcludeRequestInterceptorWrapper.java

/**
 * @param excludedExtensions/*from   www  .j  av a2 s . co  m*/
 *            the excludedExtensions to set
 */
@SuppressWarnings("unchecked")
public void setExcludedExtensions(String[] excludedExtensions) {
    Assert.parameterNotNull(excludedExtensions, "excludedExtensions");

    LOGGER.debug("Excluded extensions : {} ({} excluded extensions)", excludedExtensions,
            excludedExtensions.length); // had to cast to call the right method

    Collection<String> nonNullExtensions = CollectionUtils.select(Arrays.asList(excludedExtensions),
            NotNullPredicate.getInstance());

    this.excludedExtensions = CollectionUtils.collect(nonNullExtensions, new Transformer() {
        @Override
        public Object transform(Object input) {
            return ((String) input).trim().toLowerCase();
        }
    });
}

From source file:org.tonguetied.keywordmanagement.KeywordServiceStub.java

public PaginatedList<Keyword> findKeywords(final Keyword keyword, boolean ignoreCase, Order order,
        Integer firstResult, Integer maxResults) {
    final Predicate keywordFilter = new KeywordFilter(keyword);
    List<Keyword> results = (List<Keyword>) CollectionUtils.select(keywords.values(), keywordFilter);
    return new PaginatedList<Keyword>(results, results.size());
}

From source file:org.tonguetied.keywordmanagement.KeywordServiceStub.java

public List<Bundle> findBundles(final String name, final String resourceName) {
    final Predicate bundleFilter = new BundleNamesFilter(name, resourceName);
    List<Bundle> results = (List<Bundle>) CollectionUtils.select(bundles.values(), bundleFilter);
    return results;
}

From source file:org.tonguetied.web.KeywordValidator.java

/**
 * This validation method checks if the set of {@link Translation}s for a 
 * {@link Keyword} contains duplicate entries of the business key.
 * /* w  ww .ja v  a 2  s  .c om*/
 * @param translations the set of {@link Translation}s to validate
 * @param errors contextual state about the validation process (never null)
 */
protected void validateDuplicates(SortedSet<Translation> translations, Errors errors) {
    Collection<Translation> output;
    TranslationPredicate predicate;
    List<FieldError> fieldErrors;
    if (translations.size() > 1) {
        for (Translation translation : translations) {
            predicate = new TranslationPredicate(translation.getBundle(), translation.getCountry(),
                    translation.getLanguage());
            output = CollectionUtils.select(translations, predicate);
            if (output.size() > 1) {
                final String[] errorArgs = new String[] { getLanguageName(translation.getLanguage()),
                        getCountryName(translation.getCountry()), getBundleName(translation.getBundle()) };
                fieldErrors = errors.getFieldErrors(FIELD_TRANSLATIONS);
                boolean containsError = false;
                for (FieldError error : fieldErrors) {
                    containsError = containsError || Arrays.equals(error.getArguments(), errorArgs);
                }
                if (!containsError) {
                    errors.rejectValue(FIELD_TRANSLATIONS, "error.duplicate.translations", errorArgs,
                            "default");
                }
            }
        }
    }
}

From source file:org.tonguetied.web.KeywordValidator.java

/**
 * This validation method checks if the set of {@link Translation}s for a 
 * {@link Keyword} contains duplicate entries for new values of the 
 * business key./*from  w  w  w . j a v a2 s.c  o m*/
 * 
 * @param translations the set of {@link Translation}s to validate
 * @param predicate the predicate to evaluate
 * @param errors contextual state about the validation process (never null)
 */
protected void validateDuplicates(SortedSet<Translation> translations, final TranslationPredicate predicate,
        Errors errors) {
    Collection<Translation> output;
    if (translations.size() > 1) {
        output = CollectionUtils.select(translations, predicate);
        if (output.size() > 0) {
            final String[] errorArgs = new String[] { getLanguageName(predicate.getLanguage()),
                    getCountryName(predicate.getCountry()), getBundleName(predicate.getBundle()) };
            errors.rejectValue(FIELD_TRANSLATIONS, "error.duplicate.translations", errorArgs, "default");
        }
    }
}

From source file:org.xlcloud.console.entitlements.utils.EntitlementDictionaryCollectionUtil.java

/**
 * Collects explicit entitlement dictionaries wrapped by TreeNode objects
 * @param treeNodes tree nodes//from   ww w . j  a v  a  2  s .c om
 * @return the list of explicit entitlement dictionaries
 */
@SuppressWarnings("unchecked")
public static List<ExplicitEntitlementDictionary> collectExplicitEntitlementDictionaries(TreeNode treeNodes[]) {
    List<ExplicitEntitlementDictionary> explicitEntitlements = new ArrayList<ExplicitEntitlementDictionary>();

    Collection<TreeNode> leafNodes = CollectionUtils.select(Arrays.asList(treeNodes), new Predicate() {
        @Override
        public boolean evaluate(Object object) {
            TreeNode node = (TreeNode) object;
            return (node.getData() instanceof ExplicitEntitlementDictionary);
        }
    });

    CollectionUtils.collect(leafNodes, new Transformer() {
        @Override
        public Object transform(Object input) {
            TreeNode node = (TreeNode) input;
            return (ExplicitEntitlementDictionary) node.getData();
        }
    }, explicitEntitlements);

    return explicitEntitlements;
}