List of usage examples for org.apache.commons.collections CollectionUtils select
public static Collection select(Collection inputCollection, Predicate predicate)
From source file:org.yes.cart.report.impl.ReportServiceImpl.java
/** * Get the list of report descriptors./*w w w. j a v a 2 s . co m*/ * * @return list of reports which visible on UI. */ @SuppressWarnings("unchecked") public List<ReportDescriptor> getReportDescriptors() { return (List<ReportDescriptor>) CollectionUtils.select(reportDescriptors, new Predicate() { public boolean evaluate(Object object) { return ((ReportDescriptor) object).isVisible(); } } ); }
From source file:pl.bristleback.server.bristle.security.UsersContainer.java
@SuppressWarnings("unchecked") private List<UserContext> getUsersMeetingCondition(List<UserContext> usersSubset, final SendCondition condition) { return (List<UserContext>) CollectionUtils.select(usersSubset, new Predicate() { @Override// w w w . j a v a2s .com public boolean evaluate(Object object) { return condition.isApplicable((UserContext) object); } }); }
From source file:pt.ist.fenix.ui.struts.action.messaging.SearchPerson.java
public CollectionPager<Person> run(SearchParameters searchParameters, Predicate predicate) { if (searchParameters.emptyParameters()) { return new CollectionPager<Person>(new ArrayList<Person>(), 25); }// w ww . ja va 2 s . co m final Collection<Person> persons; if (searchParameters.getUsername() != null && searchParameters.getUsername().length() > 0) { final Person person = Person.readPersonByUsername(searchParameters.getUsername()); persons = new ArrayList<Person>(); if (person != null) { persons.add(person); } } else if (searchParameters.getDocumentIdNumber() != null && searchParameters.getDocumentIdNumber().length() > 0) { persons = Person.findPersonByDocumentID(searchParameters.getDocumentIdNumber()); } else if (searchParameters.getStudentNumber() != null) { final Student student = Student.readStudentByNumber(searchParameters.getStudentNumber()); persons = new ArrayList<Person>(); if (student != null) { persons.add(student.getPerson()); } } else if (searchParameters.getEmail() != null && searchParameters.getEmail().length() > 0) { final Person person = Person.readPersonByEmailAddress(searchParameters.getEmail()); persons = new ArrayList<Person>(); if (person != null) { persons.add(person); } } else if (searchParameters.getMechanoGraphicalNumber() != null) { final Employee employee = Employee.readByNumber(searchParameters.getMechanoGraphicalNumber()); final Student student = Student.readStudentByNumber(searchParameters.getMechanoGraphicalNumber()); persons = new TreeSet<Person>(); if (employee != null) { persons.add(employee.getPerson()); } if (student != null) { persons.add(student.getPerson()); } } else if (searchParameters.getName() != null) { persons = new ArrayList<Person>(); persons.addAll(Person.findPerson(searchParameters.getName())); final String roleBd = searchParameters.getRole(); if (roleBd != null) { for (final Iterator<Person> peopleIterator = persons.iterator(); peopleIterator.hasNext();) { final Person person = peopleIterator.next(); if (!hasRole(person.getUser(), roleBd)) { peopleIterator.remove(); } } } final Department department = searchParameters.getDepartment(); if (department != null) { for (final Iterator<Person> peopleIterator = persons.iterator(); peopleIterator.hasNext();) { final Person person = peopleIterator.next(); final Teacher teacher = person.getTeacher(); if (teacher == null || teacher.getDepartment() != department) { peopleIterator.remove(); } } } } else if (!StringUtils.isEmpty(searchParameters.getPaymentCode())) { persons = new ArrayList<Person>(); PaymentCode paymentCode = PaymentCode.readByCode(searchParameters.getPaymentCode()); if (paymentCode != null && paymentCode.getPerson() != null) { persons.add(paymentCode.getPerson()); } } else { persons = new ArrayList<Person>(0); } TreeSet<Person> result = new TreeSet<Person>(Person.COMPARATOR_BY_NAME_AND_ID); result.addAll(CollectionUtils.select(persons, predicate)); return new CollectionPager<Person>(result, 25); }
From source file:pt.ist.fenixedu.tutorship.domain.StudentHighPerformanceQueueJob.java
@Override public QueueJobResult execute() throws Exception { final ExecutionSemester semester = (ExecutionSemester) ExecutionSemester .getExecutionInterval(getExecutionInterval()); Collection<Registration> highPerformants = CollectionUtils.select(Bennu.getInstance().getRegistrationsSet(), new Predicate() { @Override/*from w ww .j a va2 s . co m*/ public boolean evaluate(Object element) { Registration registration = (Registration) element; if (registration.hasActiveLastState(semester)) { Collection<Enrolment> enrols = registration.getEnrolments(semester); if (!enrols.isEmpty()) { for (Enrolment enrol : enrols) { if (!enrol.isApproved()) { return false; } } return true; } } return false; } }); SheetData<Registration> data = new SheetData<Registration>(highPerformants) { @Override protected void makeLine(Registration item) { addCell("istId", item.getPerson().getUsername()); addCell("Nome", item.getPerson().getName()); double totalEcts = 0; Collection<Enrolment> enrols = item.getEnrolments(semester); for (Enrolment enrolment : enrols) { totalEcts += enrolment.getEctsCredits(); } addCell("Crditos Inscritos", totalEcts); addCell("Curso", item.getDegree().getNameFor(semester)); CycleType cycleType = item.getCycleType(semester.getExecutionYear()); addCell("Ciclo", cycleType != null ? cycleType.getDescription() : null); addCell("Email", item.getPerson().getEmailForSendingEmails()); Tutorship activeTutorship = Tutorship.getActiveTutorship(item.getLastStudentCurricularPlan()); addCell("Tutor", activeTutorship != null ? activeTutorship.getPerson().getName() : null); addCell("Email Tutor", activeTutorship != null ? activeTutorship.getPerson().getEmailForSendingEmails() : null); } }; ByteArrayOutputStream stream = new ByteArrayOutputStream(); new SpreadsheetBuilder().addSheet("elevado rendimento", data).build(WorkbookExportFormat.EXCEL, stream); QueueJobResult result = new QueueJobResult(); result.setContentType("application/xls"); result.setContent(stream.toByteArray()); return result; }
From source file:pt.webdetails.cns.service.store.DefaultVolatileStorage.java
@SuppressWarnings("unchecked") public Notification getNextUnread(String user, String[] roles) { if (StringUtils.isEmpty(user)) { return null; } else {/*from w ww . java2 s. c om*/ List<Notification> unreadList = new LinkedList<Notification>(); List<Notification> publicList = (List) CollectionUtils.select(publicStorage, UNREAD_FILTER); if (publicList != null) { unreadList.addAll(publicList); } List<Notification> userList = (List) CollectionUtils.select(userStorage.get(user), UNREAD_FILTER); if (userList != null) { unreadList.addAll(userList); } if (roles != null) { List<Notification> roleList = null; for (String role : roles) { roleList = (List) CollectionUtils.select(roleStorage.get(role), UNREAD_FILTER); if (roleList != null) { unreadList.addAll(roleList); } } } if (unreadList.size() > 0) { Collections.sort(unreadList); // recall: Notification overrides compareTo(), now sorting by timestamp return unreadList.get(0); // the oldest unread entry ( read: lowest timestampMillis value ) } return null; } }
From source file:pt.webdetails.cns.service.store.DefaultVolatileStorage.java
@SuppressWarnings("unchecked") public List<Notification> getAll(String user, String[] roles, boolean unreadOnly) { if (StringUtils.isEmpty(user)) { return null; } else {//ww w . j a v a 2 s. c om List<Notification> all = new LinkedList<Notification>(); List<Notification> publicList = unreadOnly ? (List) CollectionUtils.select(publicStorage, UNREAD_FILTER) : publicStorage; if (publicList != null) { all.addAll(publicList); } List<Notification> userList = unreadOnly ? (List) CollectionUtils.select(userStorage.get(user), UNREAD_FILTER) : userStorage.get(user); if (userList != null) { all.addAll(userList); } if (roles != null) { List<Notification> roleList = null; for (String role : roles) { roleList = unreadOnly ? (List) CollectionUtils.select(roleStorage.get(role), UNREAD_FILTER) : roleStorage.get(role); if (roleList != null) { all.addAll(roleList); } } } if (all.size() > 0) { Collections.sort(all); // recall: Notification overrides compareTo(), now sorting by timestamp } return all; } }
From source file:qtiscoringengine.DEContainer.java
@Override public boolean equals(Object e) { if (!(e instanceof DataElement)) return false; DataElement d = (DataElement) e;/*from ww w. ja v a 2 s. c o m*/ if (!d.getIsContainer()) return false; if (d.getType() != this.getType()) return false; final DEContainer c = (DEContainer) d; if (c.getMemberCount() != this.getMemberCount()) return false; if (this._cardinality == Cardinality.Ordered) { for (int i = 0; i < getMemberCount(); i++) { if (!(_members.get(i).equals(c.getMember(i)))) return false; } } else { for (int i = 0; i < getMemberCount(); i++) { // if (_members.Find(x => x.Equals(c.getMember(i))) == null) // return false; final int idx = i; // if (_members.stream().filter(x -> x.equals(c.getMember(idx))).count() // == 0) // return false; if (CollectionUtils.select(_members, new Predicate() { @Override public boolean evaluate(Object x) { return x.equals(c.getMember(idx)); } }).size() == 0) { return false; } } } return true; }
From source file:tds.itemrenderer.data.apip.APIPXml.java
public APIPAccessElement getRelatedElementInfo(final String id) { /*/*from w w w . j a v a 2 s. c om*/ * return (from accessElement in AccessElements where * accessElement.ContentLinkInfo.ITSLinkIdentifierRef == id select * accessElement).FirstOrDefault(); */ return (APIPAccessElement) CollectionUtils .find(CollectionUtils.select(getAccessElements(), new Predicate() { @Override public boolean evaluate(Object accessElement) { return StringUtils.equals( ((APIPAccessElement) accessElement).getContentLinkInfo().getItsLinkIdentifierRef(), id); } }), new Predicate() { // this will make it return the first element. // TODO Shiva: would not it have been simpler to check using plain java // code. @Override public boolean evaluate(Object arg0) { return true; } }); }
From source file:TDS.Proctor.Web.presentation.backing.AbstractApprovedRequestsPresenter.java
/** * @return List<TesteeRequest>/*w w w . j ava 2 s . com*/ */ public List<TesteeRequest> findAll(UUID oppKey) { if (getTesteeRequests() == null) return null; return new ArrayList<TesteeRequest>( CollectionUtils.select(getTesteeRequests(), new OppKeyPredicate(oppKey))); }
From source file:tds.student.services.AccommodationsService.java
private void setTesteeDefaults(long testee, final String accFamily, Accommodations accommodations) throws ReturnStatusException { // get all accommodations from RTS that are preselected for this student List<RTSAccommodation> allRTSAccCodes = null; try {//from w ww . ja v a2 s . co m allRTSAccCodes = _testeeRepository.getAccommodations(testee); // get all the RTS accommodations that match this tests subject Collection<RTSAccommodation> subjectRTSAccCodes = (List<RTSAccommodation>) CollectionUtils .select(allRTSAccCodes, new Predicate() { @Override public boolean evaluate(Object object) { RTSAccommodation rtsAttr = (RTSAccommodation) object; return (rtsAttr.getAccFamily() == null || rtsAttr.getAccFamily().equalsIgnoreCase(accFamily)); } }); // get all the test accommodations for this subject's codes Collection<AccommodationValue> subjectAccValues = new ArrayList<AccommodationValue>(); if (subjectRTSAccCodes != null) for (RTSAccommodation subjectRTSAccCode : subjectRTSAccCodes) { AccommodationValue accValue = accommodations.getValue(subjectRTSAccCode.getAccCode()); if (accValue != null) subjectAccValues.add(accValue); } // TODO Transformer groupTransformer = new Transformer() { @Override public Object transform(Object itsDocument) { return ((AccommodationValue) itsDocument).getParentType(); } }; List<IGrouping<AccommodationType, AccommodationValue>> subjectAccValuesGroupedByType = IGrouping .<AccommodationType, AccommodationValue>createGroups(subjectAccValues, groupTransformer); Collections.sort(subjectAccValuesGroupedByType, new Comparator<IGrouping<AccommodationType, AccommodationValue>>() { @Override public int compare(IGrouping<AccommodationType, AccommodationValue> o1, IGrouping<AccommodationType, AccommodationValue> o2) { if (o1.getKey() == o2.getKey()) return 0; else return 1; // return o1.getKey ().Comparable (o2.getKey ()); } }); // group the test accommodations by type // var subjectAccValuesGroupedByType = subjectAccValues.GroupBy(value => // value.ParentType); // select the new defaults for this type for (IGrouping<AccommodationType, AccommodationValue> subjectAccValuesGroup : subjectAccValuesGroupedByType) { AccommodationType subjectAccType = subjectAccValuesGroup.getKey(); // deselect the current default value AccommodationValue defaultAccValue = subjectAccType.getDefault(); if (defaultAccValue != null) { defaultAccValue.setIsDefault(false); } // select new default values for (AccommodationValue accValue : subjectAccValuesGroup) { accValue.setIsDefault(true); } } } catch (ReturnStatusException e) { _logger.error(e.getMessage()); throw new ReturnStatusException(e); } }