List of usage examples for org.apache.commons.collections Predicate Predicate
Predicate
From source file:com.assignmentone.util.persondb.AbstractDbManager.java
@SuppressWarnings("unchecked") public synchronized List<T> find(final String field, final Object v) { List<T> list = new ArrayList<>(entityList); CollectionUtils.filter(list, new Predicate() { @Override/* w ww .jav a 2s.c o m*/ public boolean evaluate(Object object) { try { return ObjectUtils.equals(v, PropertyUtils.getProperty(object, field)); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { throw new RuntimeException(e); } } }); return ListConvertUtil.transform(list, new RowConvertor<T, T>() { @Override public T convert(int rowIndex, T obj) { try { return (T) obj.clone(); } catch (CloneNotSupportedException e) { throw new RuntimeException(e); } } }); }
From source file:net.sourceforge.fenixedu.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 w w .j a va 2 s .c om 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().getIstUsername()); 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 = item.getActiveTutorship(); 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:net.sourceforge.fenixedu.applicationTier.Servico.teacher.DeleteProfessorshipWithPerson.java
@Atomic public static Boolean run(Person person, ExecutionCourse executionCourse) throws NotAuthorizedException { try {/* w ww . j a v a 2 s.c o m*/ final Person loggedPerson = AccessControl.getPerson(); Professorship selectedProfessorship = null; selectedProfessorship = person.getProfessorshipByExecutionCourse(executionCourse); if ((loggedPerson == null) || (selectedProfessorship == null) || !loggedPerson.hasRole(RoleType.TEACHER) || isSamePersonAsBeingRemoved(loggedPerson, selectedProfessorship.getPerson()) || selectedProfessorship.getResponsibleFor()) { throw new NotAuthorizedException(); } } catch (RuntimeException e) { throw new NotAuthorizedException(); } Professorship professorshipToDelete = person.getProfessorshipByExecutionCourse(executionCourse); Collection shiftProfessorshipList = professorshipToDelete.getAssociatedShiftProfessorshipSet(); boolean hasCredits = false; if (!shiftProfessorshipList.isEmpty()) { hasCredits = CollectionUtils.exists(shiftProfessorshipList, new Predicate() { @Override public boolean evaluate(Object arg0) { ShiftProfessorship shiftProfessorship = (ShiftProfessorship) arg0; return shiftProfessorship.getPercentage() != null && shiftProfessorship.getPercentage() != 0; } }); } if (!hasCredits && professorshipToDelete.getStudentInquiriesTeachingResultsSet().isEmpty()) { professorshipToDelete.delete(); } else { if (hasCredits) { throw new DomainException("error.remove.professorship"); } } return Boolean.TRUE; }
From source file:net.shopxx.controller.admin.ParameterController.java
@RequestMapping(value = "/save", method = RequestMethod.POST) public String save(Parameter parameter, Long productCategoryId, RedirectAttributes redirectAttributes) { CollectionUtils.filter(parameter.getNames(), new AndPredicate(new UniquePredicate(), new Predicate() { public boolean evaluate(Object object) { String name = (String) object; return StringUtils.isNotEmpty(name); }/*w w w .j a v a 2 s. com*/ })); parameter.setProductCategory(productCategoryService.find(productCategoryId)); if (!isValid(parameter, BaseEntity.Save.class)) { return ERROR_VIEW; } parameterService.save(parameter); addFlashMessage(redirectAttributes, SUCCESS_MESSAGE); return "redirect:list.jhtml"; }
From source file:net.shopxx.controller.admin.SpecificationController.java
@RequestMapping(value = "/save", method = RequestMethod.POST) public String save(Specification specification, Long productCategoryId, RedirectAttributes redirectAttributes) { CollectionUtils.filter(specification.getOptions(), new AndPredicate(new UniquePredicate(), new Predicate() { public boolean evaluate(Object object) { String option = (String) object; return StringUtils.isNotEmpty(option); }/*from ww w. j ava 2 s . com*/ })); specification.setProductCategory(productCategoryService.find(productCategoryId)); if (!isValid(specification, BaseEntity.Save.class)) { return ERROR_VIEW; } specificationService.save(specification); addFlashMessage(redirectAttributes, SUCCESS_MESSAGE); return "redirect:list.jhtml"; }
From source file:de.forsthaus.backend.dao.impl.LanguageDAOImpl.java
@Override public Language getLanguageById(final int lan_id) { return (Language) CollectionUtils.find(LANGUAGES, new Predicate() { @Override//ww w. j a v a 2 s . c o m public boolean evaluate(Object object) { return lan_id == ((Language) object).getId(); } }); }
From source file:com.redhat.rhn.frontend.security.BaseAuthenticationService.java
protected boolean requestRestrictedWhitelist(final HttpServletRequest request) { return CollectionUtils.exists(getRestrictedWhitelistURIs(), new Predicate() { public boolean evaluate(Object uri) { return request.getRequestURI().startsWith(uri.toString()); }//from w w w. ja v a 2s. c o m }); }
From source file:net.sourceforge.fenixedu.applicationTier.Servico.coordinator.ReadCurrentExecutionDegreeByDegreeCurricularPlanID.java
protected InfoExecutionDegree run(final String degreeCurricularPlanID) { final DegreeCurricularPlan degreeCurricularPlan = FenixFramework.getDomainObject(degreeCurricularPlanID); final Collection executionDegrees = degreeCurricularPlan.getExecutionDegreesSet(); final ExecutionDegree executionDegree = (ExecutionDegree) CollectionUtils.find(executionDegrees, new Predicate() { @Override/* www . ja va 2s.c om*/ public boolean evaluate(Object arg0) { final ExecutionDegree executionDegree = (ExecutionDegree) arg0; return executionDegree.getExecutionYear().isCurrent(); } }); return InfoExecutionDegree.newInfoFromDomain(executionDegree); }
From source file:com.ikon.servlet.frontend.ThesaurusServlet.java
@Override public List<String> getKeywords(final String filter) throws OKMException { log.debug("getKeywords({})", filter); List<String> keywordList = new ArrayList<String>(); List<String> keywords = RDFREpository.getInstance().getKeywords(); int index = -1; int size = keywords.size(); updateSessionManager();/*from ww w .jav a2s.com*/ // Keywords list is an ordered list String value = (String) CollectionUtils.find(keywords, new Predicate() { @Override public boolean evaluate(Object arg0) { String key = (String) arg0; if (key.toLowerCase().startsWith(filter)) { return true; } else { return false; } } }); if (value != null) { index = keywords.indexOf(value); } if (index >= 0) { while (size > index && keywords.get(index).toLowerCase().startsWith(filter)) { keywordList.add(keywords.get(index)); index++; } } log.debug("getKeywords: {}", keywordList); return keywordList; }
From source file:com.dp2345.service.impl.PluginServiceImpl.java
public List<StoragePlugin> getStoragePlugins(final boolean isEnabled) { List<StoragePlugin> result = new ArrayList<StoragePlugin>(); CollectionUtils.select(storagePlugins, new Predicate() { public boolean evaluate(Object object) { StoragePlugin storagePlugin = (StoragePlugin) object; return storagePlugin.getIsEnabled() == isEnabled; }/*w w w . ja v a2 s . c o m*/ }, result); Collections.sort(result); return result; }