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 void select(Collection inputCollection, Predicate predicate, Collection outputCollection) 

Source Link

Document

Selects all elements from input collection which match the given predicate and adds them to outputCollection.

Usage

From source file:org.sipfoundry.sipxconfig.admin.dialplan.DialPlan.java

/**
 * This function return all attendant rules contained in this plan.
 *
 * @return list of attendant rules, empty list if no attendant rules in this plan
 *//*from   ww w .j a  va  2  s  .  c  om*/
public List<AttendantRule> getAttendantRules() {
    List<AttendantRule> attendantRules = new ArrayList<AttendantRule>();
    Predicate isAttendantRule = InstanceofPredicate.getInstance(AttendantRule.class);
    CollectionUtils.select(m_rules, isAttendantRule, attendantRules);
    return attendantRules;
}

From source file:org.xlcloud.console.applications.controllers.editor.TagAutocompleteBean.java

/**
 * Returns the list of tags matching the given query. It finds matching tags
 * in all already defined tags, retrieved from existing public applications
 * Result list includes also the given query. Result list does not include
 * tags, which were already selected.//from   w ww  . jav  a 2  s  .  c om
 * 
 * @param query
 *            query, which should be used to match tags
 * @return result list of matching tags
 */
public List<String> completeTag(String query) {
    List<String> matchingTags = new ArrayList<String>();
    CollectionUtils.select(availableTags, new VirtualClusterDefinitionTagFilterPredicate(query, selectedTags),
            matchingTags);

    if (StringUtils.isNotBlank(query) && !matchingTags.contains(query) && !selectedTags.contains(query)) {
        matchingTags.add(query);
    }
    return matchingTags;
}

From source file:org.xlcloud.console.menu.MenuActivationBean.java

/**
 * Initializes bean and finds active menu item.
 *//*from  w  w  w  .  j a  va  2 s  .  co m*/
@PostConstruct
public void initialize() {
    String servletPath = getServletPathFromRequest();

    filteredGroups = new ArrayList<MenuGroup>();
    CollectionUtils.select(menuCollectorBean.getGroups(), new MenuGroupAllowancePredicate(entitlementEngine),
            filteredGroups);

    activeMenuItem = menuCollectorBean.getActiveMenuItem(servletPath);

    if (activeMenuItem != null) {
        activeMenuGroupIndex = getIndexOfMenuGroupByLabel(activeMenuItem.getGroupLabel());
    }
}

From source file:org.xlcloud.console.virtualClusters.controllers.wizard.utils.ApplicationsFilter.java

private void refreshMatchingApplications() {
    matchingApplications = new ArrayList<Application>();
    CollectionUtils.select(applications, new ApplicationByTypePredicate(applicationType), matchingApplications);
}

From source file:org.xlcloud.console.virtualClusters.controllers.wizard.VirtualClusterTypeBean.java

/**
 * This method is used by the autocomplete component to find all the tags that match a given pattern.
 * @param filter filter pattern//from  w w  w .ja v a 2s  .  c o  m
 * @return matching tags
 */
public List<String> completeVirtualClusterTag(String filter) {
    List<String> matchingTags = new ArrayList<String>();
    CollectionUtils.select(availableTags, new VirtualClusterDefinitionTagFilterPredicate(filter, tagsFilter),
            matchingTags);

    return matchingTags;
}

From source file:tinyequationscoringengine.MathMLParser.java

public static boolean applyMROWwithNoOperatorsFix(Document xml, XmlNamespaceManager nsMgr) {
    boolean docModified = false;
    List<Element> matchingNodes = new XmlElement(xml.getRootElement()).selectNodes("//m:mrow", nsMgr);

    for (Element mRowNode : matchingNodes) {
        // We dont want to mess with any mrows that are children of a complex
        // parent
        if (hasComplexParent(mRowNode))
            continue;

        if (new XmlElement(mRowNode).getChildNodes().size() == 0) {
            new XmlElement(mRowNode.getParentElement()).removeChild(mRowNode);
            continue;
        }//from  ww w.  j  a  va 2s  . c  o m

        // <mn>1</mn><mn>4</mn><mrow><mn>5</mn></mrow>
        boolean containsOnlyMnorMi = true;

        List<Element> filteredList = new ArrayList<Element>();
        CollectionUtils.select(new XmlElement(mRowNode).getChildNodes(), new Predicate() {

            @Override
            public boolean evaluate(Object object) {
                XmlElement child = new XmlElement((Element) object);
                return !("MN".equalsIgnoreCase(child.getLocalName())
                        || "MI".equalsIgnoreCase(child.getLocalName()));
            }
        }, filteredList);

        for (Element child : filteredList) {
            containsOnlyMnorMi = false;
        }

        if (containsOnlyMnorMi) {
            XmlElement mRowParentNode = new XmlElement(mRowNode.getParentElement());

            // Remove all the remaing mrow children and elevate them to be siblings
            // of the mrow
            XmlElement rowNodeElement = new XmlElement(mRowNode);
            while (rowNodeElement.hasChildNodes()) {

                XmlElement node = rowNodeElement.getFirstChild();
                rowNodeElement.removeChild(node.getContentNode());
                mRowParentNode.insertBefore(node.getContentNode(), rowNodeElement.getContentNode());
            }
            // remove the mrow all together and splice the new base node in as the
            // first child.

            mRowParentNode.removeChild(mRowNode);
            docModified = true;
        }
    }

    return docModified;
}