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:edu.northwestern.bioinformatics.studycalendar.service.StudySiteService.java

@SuppressWarnings({ "unchecked" })
public List<List<StudySite>> refreshStudySitesForSites(final List<Site> sites) {
    if (sites == null) {
        throw new IllegalArgumentException(SITE_IS_NULL);
    }//  www  . j ava2  s . co  m

    List<List<StudySite>> refreshed = new ArrayList<List<StudySite>>();

    final Map<String, List<Study>> studies = buildProvidedStudyMap();
    final List<List<StudySite>> allProvided = studySiteConsumer.refreshStudies(sites);

    for (int i = 0; i < sites.size(); i++) {
        final Site site = sites.get(i);
        List<StudySite> provided = allProvided.get(i);
        if (provided == null) {
            provided = EMPTY_LIST;
        }

        Collection<StudySite> qualifying = CollectionUtils.select(provided, new Predicate() {
            public boolean evaluate(Object o) {
                StudySite potential = (StudySite) o;

                // Verify Provider for existing Site is equal to StudySite Provider
                if (site.getProvider() == null || !site.getProvider().equals(potential.getProvider())) {
                    return false;
                }

                // Verify Provider for existing Study is equal to StudySite Provider (And Study Exists)
                List<Study> providerSpecific = studies.get(potential.getProvider());
                if (providerSpecific == null || CollectionUtilsPlus.matching(asList(potential.getStudy()),
                        providerSpecific, StudySecondaryIdentifierMatcher.instance()).size() == 0) {
                    return false;
                }

                // Verify new study site
                Study study = (Study) CollectionUtilsPlus.matching(asList(potential.getStudy()),
                        providerSpecific, StudySecondaryIdentifierMatcher.instance()).iterator().next();
                if (StudySite.findStudySite(study, site) != null) {
                    return false;
                }

                return true;
            }
        });

        logger.debug("Found " + qualifying.size() + " new study sites from the provider.");
        for (StudySite u : qualifying) {
            logger.debug("- " + u);
        }

        // StudySites returned from provider are proxied by CGLIB.  This causes problems when saving,
        // so we want to create a fresh StudySite instance. Also, we want to populate the site with a
        // valid Site from SiteService.
        Collection<StudySite> enhanced = CollectionUtils.collect(qualifying, new Transformer() {
            public Object transform(Object o) {
                StudySite s = (StudySite) o;

                List<Study> providerSpecific = studies.get(s.getProvider());
                Study study = (Study) CollectionUtilsPlus.matching(asList(s.getStudy()), providerSpecific,
                        StudySecondaryIdentifierMatcher.instance()).iterator().next();

                StudySite e = new StudySite(study, site);
                e.getStudy().addStudySite(e);
                e.getSite().addStudySite(e);
                e.setProvider(s.getProvider());
                e.setLastRefresh(s.getLastRefresh());
                return e;
            }
        });

        for (StudySite s : enhanced) {
            studySiteDao.save(s);
        }

        refreshed.add(site.getStudySites());
    }

    return refreshed;
}

From source file:net.sourceforge.fenixedu.domain.teacher.TeacherService.java

public List<DegreeProjectTutorialService> getDegreeProjectTutorialServices() {
    return (List<DegreeProjectTutorialService>) CollectionUtils.select(getServiceItemsSet(), new Predicate() {
        @Override// w ww.  java2 s .  co  m
        public boolean evaluate(Object arg0) {
            return arg0 instanceof DegreeProjectTutorialService;
        }
    });
}

From source file:net.sourceforge.fenixedu.domain.teacher.TeacherService.java

public List<TeacherMasterDegreeService> getMasterDegreeServices() {
    return (List<TeacherMasterDegreeService>) CollectionUtils.select(getServiceItemsSet(), new Predicate() {
        @Override//  w w w.j  a v a2 s.  c om
        public boolean evaluate(Object arg0) {
            return arg0 instanceof TeacherMasterDegreeService;
        }
    });
}

From source file:net.sourceforge.fenixedu.domain.teacher.TeacherService.java

public List<OtherService> getOtherServices() {
    return (List<OtherService>) CollectionUtils.select(getServiceItemsSet(), new Predicate() {
        @Override//from  w  ww  .ja v  a 2 s.  co  m
        public boolean evaluate(Object arg0) {
            return arg0 instanceof OtherService;
        }
    });
}

From source file:net.sf.wickedshell.ui.shell.ShellView.java

/**
 * Initializes the menubar of this <code>ShellView</code>.
 *//*w w  w .j  a v a 2  s  .co m*/
private void initMenuBar() {
    IMenuManager manager = getViewSite().getActionBars().getMenuManager();
    manager.add(new Separator(ShellID.SHELL_VIEW_MENU_GROUP_MANAGE_INTERNAL));
    final IMenuManager subMenuManager = new MenuManager("Active Shell",
            ShellID.SHELL_VIEW_SUBMENU_ACTIVE_SHELL);
    manager.add(subMenuManager);
    manager.addMenuListener(new IMenuListener() {
        /**
         * @see org.eclipse.jface.action.IMenuListener#menuAboutToShow(org.eclipse.jface.action.IMenuManager)
         */
        @SuppressWarnings("unchecked")
        public void menuAboutToShow(IMenuManager manager) {
            subMenuManager.removeAll();
            subMenuManager.add(new GroupMarker(ShellID.SHELL_VIEW_SUBMENU_GROUP_AVAILABLE_SHELLS));
            Collection<IShellDescriptor> availableOSShellDescriptors = CollectionUtils
                    .select(IShellDescriptor.Manager.getKnownShellDescriptors(), new Predicate() {
                        /**
                         * @see org.apache.commons.collections.Predicate#evaluate(java.lang.Object)
                         */
                        public boolean evaluate(Object object) {
                            IShellDescriptor shellDescriptor = (IShellDescriptor) object;
                            return shellDescriptor.isCurrentOSSupported();
                        }
                    });
            for (Iterator descriptorIterator = availableOSShellDescriptors.iterator(); descriptorIterator
                    .hasNext();) {
                SetShellDescriptorAction setShellDescriptorAction = new SetShellDescriptorAction(
                        (IShellDescriptor) descriptorIterator.next());
                setShellDescriptorAction.setChecked(setShellDescriptorAction.getShellDescriptor().getId()
                        .equals(getShellViewer().getShellFacade().getShellDescriptor().getId()));
                subMenuManager.appendToGroup(ShellID.SHELL_VIEW_SUBMENU_GROUP_AVAILABLE_SHELLS,
                        setShellDescriptorAction);

            }
        }
    });
    manager.add(new RenameShellAction());
    manager.add(new Separator(ShellID.SHELL_VIEW_MENU_GROUP_MANAGE_EXTERNAL));
    manager.add(new Separator(ShellID.SHELL_VIEW_MENU_GROUP_EXPORT));
    manager.add(new Separator(ShellID.SHELL_VIEW_MENU_GROUP_GENERAL));
    manager.add(new OpenShellErrorDisplayAction(errorDisplay));
    getViewSite().getActionBars().updateActionBars();
}

From source file:net.sourceforge.fenixedu.domain.teacher.TeacherService.java

public List<InstitutionWorkTime> getInstitutionWorkTimes() {
    return (List<InstitutionWorkTime>) CollectionUtils.select(getServiceItemsSet(), new Predicate() {
        @Override//from   ww  w .  ja v a2  s  .co  m
        public boolean evaluate(Object arg0) {
            return arg0 instanceof InstitutionWorkTime;
        }
    });
}

From source file:com.jaspersoft.jasperserver.api.security.externalAuth.processors.ExternalUserSetupProcessor.java

protected void alignInternalAndExternalUser(Set remoteExternalUserRoles, User user) {
    Set<Role> jrsUserRoles = user.getRoles();
    logger.info("Starting align for user: " + user.getFullName() + " with remoteExternalUserRoles at size of "
            + remoteExternalUserRoles.size());

    Collection jrsInternalUserRoles = CollectionUtils.select(jrsUserRoles, new Predicate() {
        public boolean evaluate(Object input) {
            if (!(input instanceof Role)) {
                return false;
            }/*from ww w  . j a va  2 s  . co m*/
            return !((Role) input).isExternallyDefined();
        }
    });

    if (logger.isDebugEnabled()) {
        logger.debug("jrsInternalUserRoles: " + roleCollectionToString(jrsInternalUserRoles));
    }

    Collection<Role> jrsInternalRolesNotInRoleMap = CollectionUtils.select(jrsInternalUserRoles,
            new Predicate() {
                public boolean evaluate(Object input) {
                    return !getOrganizationRoleMap().containsValue(((Role) input).getRoleName())
                            && !getOrganizationRoleMap()
                                    .containsValue(((Role) input).getRoleName() + ROLE_SUFFIX);
                }
            });

    if (logger.isDebugEnabled()) {
        logger.debug("jrsInternalRolesNotInRoleMap: " + roleCollectionToString(jrsInternalRolesNotInRoleMap));
    }

    //assign default internal roles if needed
    Collection<Role> defaultInternalRolesToAdd = CollectionUtils
            .subtract(getNewDefaultInternalRoles(user.getUsername()), jrsInternalRolesNotInRoleMap);
    jrsInternalRolesNotInRoleMap.addAll(defaultInternalRolesToAdd);

    Collection<Role> newUserRoles = remoteExternalUserRoles;
    newUserRoles.addAll(jrsInternalRolesNotInRoleMap);

    if (logger.isDebugEnabled()) {
        logger.debug("internal and external roles to persist: " + roleCollectionToString(newUserRoles));
    }

    persistRoles(new HashSet<Role>(newUserRoles));
    user.setRoles(new HashSet<Role>(newUserRoles));
    updateUserAttributes(user);
    getUserAuthorityService().putUser(new ExecutionContextImpl(), user);

}

From source file:com.frank.search.solr.core.query.FacetOptions.java

@SuppressWarnings("unchecked")
public Collection<FieldWithFacetParameters> getFieldsWithParameters() {
    return (Collection<FieldWithFacetParameters>) CollectionUtils.select(this.facetOnFields,
            new IsFieldWithFacetParametersInstancePredicate());
}

From source file:net.sourceforge.fenixedu.presentationTier.Action.candidacy.CandidacyProcessDA.java

private List<PublicCandidacyHashCode> getIndividualCandidacyHashCodesNotBounded() {
    List<PublicCandidacyHashCode> publicCandidacyHashCodeList = new ArrayList<PublicCandidacyHashCode>(
            CollectionUtils.select(Bennu.getInstance().getCandidacyHashCodesSet(),
                    new org.apache.commons.collections.Predicate() {

                        @Override
                        public boolean evaluate(Object arg0) {
                            final PublicCandidacyHashCode hashCode = (PublicCandidacyHashCode) arg0;
                            return hashCode.isFromDegreeOffice() && !hashCode.hasCandidacyProcess();
                        }//from  ww  w.  jav a 2s.  com
                    }));

    return publicCandidacyHashCodeList;
}

From source file:com.likya.myra.jef.utils.JobQueueOperations.java

@SuppressWarnings("unchecked")
public static Collection<AbstractJobType> getJobList(HashMap<String, AbstractJobType> abstractJobTypeList,
        Predicate predicate) {//from w w w  . ja v a  2 s .c o  m

    Collection<AbstractJobType> filteredList = CollectionUtils.select(abstractJobTypeList.values(), predicate);

    return filteredList;
}