Example usage for org.apache.commons.collections Predicate Predicate

List of usage examples for org.apache.commons.collections Predicate Predicate

Introduction

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

Prototype

Predicate

Source Link

Usage

From source file:com.prodyna.bmw.server.booking.service.BookingServiceBean.java

@Override
public List<Booking> readBookingsForMonth(final Integer month) {
    List<Booking> allBookings = em.createNamedQuery(Booking.QUERY_GET_ALL_BOOKINGS_PAGINATED, Booking.class)
            .getResultList();/*w  ww. j av  a2 s  . co  m*/
    final Calendar calendar = Calendar.getInstance();
    CollectionUtils.filter(allBookings, new Predicate() {
        @Override
        public boolean evaluate(Object arg0) {
            Booking booking = (Booking) arg0;
            calendar.setTime(booking.getStart());
            boolean startsInThisMonth = calendar.get(Calendar.MONTH) + 1 == month.intValue();
            calendar.setTime(booking.getEnd());
            boolean endsInThisMonth = calendar.get(Calendar.MONTH) + 1 == month.intValue();
            return startsInThisMonth || endsInThisMonth;
        }
    });

    return allBookings;
}

From source file:net.sourceforge.fenixedu.domain.ExecutionYear.java

public Collection<ExecutionDegree> getExecutionDegreesByType(final DegreeType degreeType) {
    return CollectionUtils.select(getExecutionDegreesSet(), new Predicate() {
        @Override//from   w ww.  ja  v  a2 s  .  c  o m
        public boolean evaluate(Object arg0) {
            ExecutionDegree executionDegree = (ExecutionDegree) arg0;
            return executionDegree.getDegreeCurricularPlan().getDegreeType() == degreeType;
        }
    });
}

From source file:net.sourceforge.fenixedu.presentationTier.Action.academicAdministration.executionCourseManagement.InsertExecutionCourseDispatchAction.java

@EntryPoint
public ActionForward prepareInsertExecutionCourse(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response) {

    List infoExecutionPeriods = null;
    infoExecutionPeriods = ReadExecutionPeriods.run();

    if (infoExecutionPeriods != null && !infoExecutionPeriods.isEmpty()) {
        // exclude closed execution periods
        infoExecutionPeriods = (List) CollectionUtils.select(infoExecutionPeriods, new Predicate() {
            @Override//from   w  w w .j  a  v  a2 s .co  m
            public boolean evaluate(Object input) {
                InfoExecutionPeriod infoExecutionPeriod = (InfoExecutionPeriod) input;
                if (!infoExecutionPeriod.getState().equals(PeriodState.CLOSED)) {
                    return true;
                }
                return false;
            }
        });

        ComparatorChain comparator = new ComparatorChain();
        comparator.addComparator(new BeanComparator("infoExecutionYear.year"), true);
        comparator.addComparator(new BeanComparator("name"), true);
        Collections.sort(infoExecutionPeriods, comparator);

        List<LabelValueBean> executionPeriodLabels = new ArrayList<LabelValueBean>();
        CollectionUtils.collect(infoExecutionPeriods, new Transformer() {
            @Override
            public Object transform(Object arg0) {
                InfoExecutionPeriod infoExecutionPeriod = (InfoExecutionPeriod) arg0;

                LabelValueBean executionPeriod = new LabelValueBean(
                        infoExecutionPeriod.getName() + " - "
                                + infoExecutionPeriod.getInfoExecutionYear().getYear(),
                        infoExecutionPeriod.getExternalId().toString());
                return executionPeriod;
            }
        }, executionPeriodLabels);

        request.setAttribute(PresentationConstants.LIST_EXECUTION_PERIODS, executionPeriodLabels);

        List<LabelValueBean> entryPhases = new ArrayList<LabelValueBean>();
        for (EntryPhase entryPhase : EntryPhase.values()) {
            LabelValueBean labelValueBean = new LabelValueBean(entryPhase.getLocalizedName(),
                    entryPhase.getName());
            entryPhases.add(labelValueBean);
        }
        request.setAttribute("entryPhases", entryPhases);

    }

    return mapping.findForward("insertExecutionCourse");
}

From source file:edu.kit.sharing.test.SharingTestService.java

@Override
public IEntityWrapper<? extends ISimpleGroupId> getReferencedGroups(String pDomain, String pDomainUniqueId,
        String pRole, String pGroupId, HttpContext hc) {
    final SecurableResourceId rid = new SecurableResourceId(pDomain, pDomainUniqueId);

    Collection gs = CollectionUtils.select(references, new Predicate() {

        @Override//from  w  ww.jav a  2 s. c om
        public boolean evaluate(Object o) {
            return ((ReferenceId) o).getResourceId().equals(rid);
        }
    });

    List<GroupId> groupIds = new LinkedList<>();
    for (Object r : gs) {
        groupIds.add(((ReferenceId) r).getGroupId());
    }

    return new GroupIdWrapper(groupIds);
}

From source file:net.sourceforge.fenixedu.dataTransferObject.CurricularCourseScopesForPrintDTO.java

private BranchForPrintDTO getSelectedBranch(final InfoCurricularCourseScope scope,
        CurricularYearForPrintDTO selectedCurricularYear) {
    BranchForPrintDTO selectedBranch = (BranchForPrintDTO) CollectionUtils
            .find(selectedCurricularYear.getBranches(), new Predicate() {

                @Override//from  w w w .  j av  a2 s.c  om
                public boolean evaluate(Object arg0) {
                    BranchForPrintDTO branchForPrintDTO = (BranchForPrintDTO) arg0;
                    if (branchForPrintDTO.getName().equals(scope.getInfoBranch().getName())) {
                        return true;
                    }

                    return false;
                }

            });

    if (selectedBranch == null) {
        selectedBranch = new BranchForPrintDTO(scope.getInfoBranch().getName());
        selectedCurricularYear.getBranches().add(selectedBranch);

    }

    return selectedBranch;
}

From source file:bard.pubchem.model.PCAssayPanel.java

public XRef getTarget() {
    List<PCAssayXRef> list = new ArrayList<PCAssayXRef>();
    CollectionUtils.select(assay.getAssayXRefs(), new Predicate() {
        public boolean evaluate(Object object) {
            PCAssayXRef xref = (PCAssayXRef) object;
            if (xref.getPanel() != null)
                if (xref.getPanel().getPanelNumber() == getPanelNumber() && xref.isTarget() == true)
                    return true;
            return false;
        }/*w  w  w . ja va  2 s.  com*/
    }, list);
    return list.size() > 0 ? list.get(0).getXRef() : null;
}

From source file:edu.kit.dama.mdm.admin.UserPropertyCollection.java

/**
 * Returns the value of the property with the provided key as string. If the
 * property is not found, the provided default value is returned.
 *
 * @param pKey The property key.//ww w .j  a v a2 s .  com
 * @param pDefaultValue The default value.
 *
 * @return The value of the property or the provided default value.
 */
public String getStringProperty(final String pKey, String pDefaultValue) {
    if (pKey == null) {
        throw new IllegalArgumentException("Argument pKey must not be null");
    }
    UserProperty existingProp = (UserProperty) CollectionUtils.find(properties, new Predicate() {
        @Override
        public boolean evaluate(Object o) {
            return ((UserProperty) o).getPropertyKey().equals(pKey);
        }
    });

    if (existingProp != null) {
        return existingProp.getPropertyValue();
    }
    return pDefaultValue;
}

From source file:net.sourceforge.fenixedu.domain.candidacyProcess.erasmus.ApprovedLearningAgreementDocumentFile.java

protected List<ApprovedLearningAgreementExecutedAction> getViewedLearningAgreementActions() {
    List<ApprovedLearningAgreementExecutedAction> executedActionList = new ArrayList<ApprovedLearningAgreementExecutedAction>();

    CollectionUtils.select(getExecutedActionsSet(), new Predicate() {

        @Override//from w  ww . ja v a 2 s  .c  o  m
        public boolean evaluate(Object arg0) {
            return ((ApprovedLearningAgreementExecutedAction) arg0).isViewedLearningAgreementAction();
        };

    }, executedActionList);

    Collections.sort(executedActionList, Collections.reverseOrder(ExecutedAction.WHEN_OCCURED_COMPARATOR));

    return executedActionList;
}

From source file:net.hillsdon.reviki.search.impl.BasicAuthAwareSearchEngine.java

public Set<SearchMatch> search(final String query, final boolean provideExtracts, boolean singleWiki)
        throws IOException, QuerySyntaxException, PageStoreException {
    // Assuming that there are any restricted wikis configured then to avoid leaking any information we must either:
    // 1) Silently drop restricted results, or
    // 2) Ask the user to log in whether or not their query results in hits to a restricted wiki.
    // We implement option 1 for CTYPE_TEXT requests and option 2 otherwise.
    // None of this applies if the search is restricted to a single wiki (i.e. the current wiki, which occurs when using the SearchMacro, https://jira.int.corefiling.com/browse/REVIKI-654)
    if ((_request.get().getHeader("Authorization") == null) && !singleWiki
            && !ViewTypeConstants.is(_request.get(), CTYPE_TEXT)) {
        for (WikiConfiguration wiki : _config.getWikis()) {
            if (isRestrictedWiki(wiki)) {
                throw new PageStoreAuthenticationException("Log in to obtain search results");
            }//from  w  ww .  j  a  v  a2s  .  c  om
        }
    }
    final Map<String, Boolean> wikiAccessOkCache = new LinkedHashMap<String, Boolean>();
    Set<SearchMatch> results = new LinkedHashSet<SearchMatch>();
    results.addAll(_delegate.search(query, provideExtracts, singleWiki));
    CollectionUtils.filter(results, new Predicate() {
        @Override
        public boolean evaluate(final Object o) {
            final SearchMatch match = (SearchMatch) o;
            Boolean accessOk = wikiAccessOkCache.get(match.getWiki());
            if (accessOk == null) {
                // Determine if the user is allowed access to the matched wiki, based on:
                // * Whether or not a username and password are required to index the wiki, if not then assume everyone is allowed access 
                // * If a username is required then determine if the current user has access.  This is slower, hence the short circuit described in the first point.
                try {
                    WikiConfiguration configuration = _config.getConfiguration(match.getWiki());
                    if (isRestrictedWiki(configuration)) {
                        RequestScopedThreadLocalBasicSVNOperations operations = new RequestScopedThreadLocalBasicSVNOperations(
                                new BasicAuthPassThroughBasicSVNOperationsFactory(configuration.getUrl(),
                                        new AutoPropertiesApplierImpl(new AutoProperties() {
                                            public Map<String, String> read() {
                                                return new LinkedHashMap<String, String>();
                                            }
                                        })));
                        operations.create(_request.get());
                        try {
                            operations.checkPath(match.getPage(), -1);
                        } finally {
                            operations.destroy();
                        }
                    }
                    accessOk = true;
                } catch (PageStoreAuthenticationException ex) {
                    accessOk = false;
                } catch (PageStoreException ex) {
                    LOG.error("Exception determining access to wiki: " + match.getWiki(), ex);
                    return false;
                }
                wikiAccessOkCache.put(match.getWiki(), accessOk);
                LOG.debug("access to results in " + match.getWiki() + ": " + accessOk);
            }
            return accessOk;
        }
    });
    return results;
}

From source file:net.sourceforge.fenixedu.domain.student.importation.ExportExistingStudentsFromImportationProcess.java

public static List<ExportExistingStudentsFromImportationProcess> readDoneJobs(
        final ExecutionYear executionYear) {
    List<ExportExistingStudentsFromImportationProcess> jobList = new ArrayList<ExportExistingStudentsFromImportationProcess>();

    CollectionUtils.select(executionYear.getDgesBaseProcessSet(), new Predicate() {

        @Override//from   ww w  . jav  a  2  s. c  om
        public boolean evaluate(Object arg0) {
            return (arg0 instanceof ExportExistingStudentsFromImportationProcess)
                    && ((QueueJob) arg0).getDone();
        }
    }, jobList);

    return jobList;
}