List of usage examples for org.apache.commons.collections Predicate Predicate
Predicate
From source file:gov.nih.nci.ncicb.tcga.dcc.datareports.service.BamTelemetryReportServiceImpl.java
@Override public List<BamTelemetry> getFilteredBamTelemetryList(final List<BamTelemetry> list, final String aliquotUUID, final String aliquotId, final String dateFrom, final String dateTo, final List<String> disease, final List<String> center, final List<String> dataType, final List<String> analyteCode, final List<String> libraryStrategy) { final StringBuilder strLog = new StringBuilder(); final DateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT_US_STRING); strLog.append("Filter used: aliquotUUID:").append(aliquotUUID).append("aliquotID").append(aliquotId) .append(" disease:").append(disease).append(" center:").append(center).append(" dataType:") .append(dataType).append(" analyteCode:").append(analyteCode).append(" dateFrom:").append(dateFrom) .append(" dateTo:").append(dateTo).append(" libraryStrategy:").append(libraryStrategy); logger.debug(strLog);/* w w w . j a v a2s . com*/ if (aliquotId == null && aliquotUUID == null && disease == null && center == null && dataType == null && analyteCode == null && dateFrom == null && dateTo == null && libraryStrategy == null) { return list; } final List<Predicate> bamPredicateList = new LinkedList<Predicate>(); bamPredicateList.add(new Predicate() { public boolean evaluate(Object o) { boolean isValid = true; if (StringUtils.isNotEmpty(aliquotUUID)) { isValid = (((BamTelemetry) o).getAliquotUUID()).equalsIgnoreCase(aliquotUUID); } else if (StringUtils.isNotEmpty(aliquotId)) { isValid = (((BamTelemetry) o).getAliquotId()).startsWith(aliquotId); } else { return isValid; } return isValid; } }); bamPredicateList.add( commonService.genDatePredicate(BamTelemetry.class, "dateReceived", false, dateFrom, dateFormat)); bamPredicateList .add(commonService.genDatePredicate(BamTelemetry.class, "dateReceived", true, dateTo, dateFormat)); commonService.genORPredicateList(BamTelemetry.class, bamPredicateList, disease, DISEASE); commonService.genORPredicateList(BamTelemetry.class, bamPredicateList, center, CENTER); commonService.genORPredicateList(BamTelemetry.class, bamPredicateList, dataType, DATA_TYPE); commonService.genORPredicateList(BamTelemetry.class, bamPredicateList, analyteCode, ANALYTE_CODE); commonService.genORPredicateList(BamTelemetry.class, bamPredicateList, libraryStrategy, LIBRARY_STRATEGY); Predicate bamTelemetryPredicates = PredicateUtils.allPredicate(bamPredicateList); List<BamTelemetry> fList = (List<BamTelemetry>) CollectionUtils.select(list, bamTelemetryPredicates); return fList; }
From source file:fr.itinerennes.bundler.gtfs.GtfsAdvancedDao.java
public List<StopTime> getStopTimes(final Stop stop, final ServiceDate date) { final List<StopTime> stopTimes = new ArrayList<StopTime>(gtfs.getStopTimesForStop(stop)); CollectionUtils.filter(stopTimes, new Predicate() { @Override// w w w . ja va2 s . c o m public boolean evaluate(Object object) { final StopTime st = (StopTime) object; final AgencyAndId serviceId = st.getTrip().getServiceId(); final ServiceCalendar sc = gtfs.getCalendarForServiceId(serviceId); final ServiceDate start = sc.getStartDate(); final ServiceDate end = sc.getEndDate(); if (isAdditionalException(date, st.getTrip())) { return true; } else if (isRemovalException(date, sc)) { return false; } else if (start.compareTo(date) <= 0 && end.compareTo(date) >= 0) { final String agencyId = stop.getId().getAgencyId(); final TimeZone tz = GtfsAdvancedDao.this.getTimeZone(agencyId); return DayOfWeek.isSameDay(date.getAsCalendar(tz), sc); } else { return false; } } }); return stopTimes; }
From source file:ch.sentric.QueryFactory.java
public Query build(final String q) { if (null == q || "".equalsIgnoreCase(q)) { return new Query(); }/* w w w . j a v a 2 s . co m*/ final ArrayList<QueryKeyValuePair> list = new ArrayList<QueryKeyValuePair>(0); ParserState state = ParserState.START; final StringTokenizer tokenizer = new StringTokenizer(q, "=&", true); String key = null; while (tokenizer.hasMoreTokens()) { final String token = tokenizer.nextToken(); switch (state) { case DELIMITER: if (token.equals("&")) { state = ParserState.KEY; } break; case KEY: if (!token.equals("=") && !token.equals("&") && !token.equalsIgnoreCase("PHPSESSID") && !token.equalsIgnoreCase("JSESSIONID")) { key = token; state = ParserState.EQUAL; } break; case EQUAL: if (token.equals("=")) { state = ParserState.VALUE; } else if (token.equals("&")) { list.add(new QueryKeyValuePair(key, null)); state = ParserState.KEY; } break; case VALUE: if (!token.equals("=") && !token.equals("&")) { if (token.contains(";jsessionid") || token.contains(";JSESSIONID")) { list.add(new QueryKeyValuePair(key, token.substring(0, token.lastIndexOf(";")))); } else { list.add(new QueryKeyValuePair(key, token)); } state = ParserState.DELIMITER; } else if (token.equals("&")) { list.add(new QueryKeyValuePair(key, null)); state = ParserState.KEY; } break; case START: if (!token.equalsIgnoreCase("PHPSESSID") && !token.equalsIgnoreCase("JSESSIONID")) { key = token; state = ParserState.EQUAL; } break; default: break; } } CollectionUtils.filter(list, new Predicate() { @Override public boolean evaluate(final Object object) { boolean allowedQueryParameter = true; final QueryKeyValuePair queryKeyValuePair = (QueryKeyValuePair) object; for (final String filter : filters) { if (queryKeyValuePair.getKey().startsWith(filter)) { allowedQueryParameter = false; } } return allowedQueryParameter; } }); return new Query(list, '&'); }
From source file:net.sourceforge.fenixedu.applicationTier.Servico.masterDegree.administrativeOffice.candidate.ReadExecutionDegreeByDegreeCurricularPlanID.java
/** * @author <a href="mailto:shezad@ist.utl.pt">Shezad Anavarali</a> * /*from w w w . ja v a2s .c o m*/ * @param degreeCurricularPlanID * @param executionDegree * @return * @throws ExcepcaoPersistencia */ protected InfoExecutionDegree run(String degreeCurricularPlanID, final String executionYear) { DegreeCurricularPlan degreeCurricularPlan = FenixFramework.getDomainObject(degreeCurricularPlanID); if (executionYear.equals("")) { return InfoExecutionDegree .newInfoFromDomain(degreeCurricularPlan.getExecutionDegreesSet().iterator().next()); } ExecutionDegree executionDegree = (ExecutionDegree) CollectionUtils .find(degreeCurricularPlan.getExecutionDegreesSet(), new Predicate() { @Override public boolean evaluate(Object arg0) { ExecutionDegree executionDegree = (ExecutionDegree) arg0; if (executionDegree.getExecutionYear().getYear().equals(executionYear)) { return true; } return false; } }); return InfoExecutionDegree.newInfoFromDomain(executionDegree); }
From source file:au.com.jwatmuff.eventmanager.model.misc.PoolChecker.java
public static List<Player> findEligiblePlayers(final Pool pool, Database database) { final CompetitionInfo ci = database.get(CompetitionInfo.class, null); final ConfigurationFile configurationFile = ConfigurationFile.getConfiguration(ci.getDrawConfiguration()); List<Player> players = database.findAll(Player.class, PlayerDAO.ALL); CollectionUtils.filter(players, new Predicate() { public boolean evaluate(Object arg0) { return checkPlayer((Player) arg0, pool, ci.getAgeThresholdDate(), configurationFile); }/*from w w w . j av a2 s .com*/ }); return players; }
From source file:net.sourceforge.fenixedu.presentationTier.Action.teacher.candidacy.erasmus.ErasmusCandidacyProcessDA.java
@Override protected List<IndividualCandidacyProcess> getChildProcesses(final CandidacyProcess process, HttpServletRequest request) {//from w w w. j ava2s . co m Collection<IndividualCandidacyProcess> processes = super.getChildProcesses(process, request); List<IndividualCandidacyProcess> result = new ArrayList<IndividualCandidacyProcess>(); CollectionUtils.select(processes, new Predicate() { @Override public boolean evaluate(Object arg0) { IndividualCandidacyProcess child = (IndividualCandidacyProcess) arg0; return ((MobilityApplicationProcess) process) .getDegreesAssociatedToTeacherAsCoordinator(getTeacher()).contains( ((MobilityIndividualApplicationProcess) child).getCandidacy().getSelectedDegree()); } }, result); return result; }
From source file:net.sourceforge.fenixedu.dataTransferObject.InfoExecutionDegree.java
public static List buildLabelValueBeansForList(List executionDegrees, MessageResources messageResources) { List copyExecutionDegrees = new ArrayList(); copyExecutionDegrees.addAll(executionDegrees); List result = new ArrayList(); Iterator iter = executionDegrees.iterator(); while (iter.hasNext()) { final InfoExecutionDegree infoExecutionDegree = (InfoExecutionDegree) iter.next(); List equalDegrees = (List) CollectionUtils.select(copyExecutionDegrees, new Predicate() { @Override// w w w . java2 s. c o m public boolean evaluate(Object arg0) { InfoExecutionDegree infoExecutionDegreeElem = (InfoExecutionDegree) arg0; if (infoExecutionDegree.getInfoDegreeCurricularPlan().getInfoDegree().getSigla().equals( infoExecutionDegreeElem.getInfoDegreeCurricularPlan().getInfoDegree().getSigla())) { return true; } return false; } }); if (equalDegrees.size() == 1) { copyExecutionDegrees.remove(infoExecutionDegree); String degreeType = null; if (messageResources != null) { degreeType = messageResources.getMessage(infoExecutionDegree.getInfoDegreeCurricularPlan() .getInfoDegree().getDegreeType().toString()); } if (degreeType == null) { degreeType = infoExecutionDegree.getInfoDegreeCurricularPlan().getInfoDegree().getDegreeType() .toString(); } result.add(new LabelValueBean( degreeType + " " + infoExecutionDegree.getInfoDegreeCurricularPlan().getInfoDegree().getNome(), infoExecutionDegree.getExternalId().toString())); } else { String degreeType = null; if (messageResources != null) { degreeType = messageResources.getMessage(infoExecutionDegree.getInfoDegreeCurricularPlan() .getInfoDegree().getDegreeType().toString()); } if (degreeType == null) { degreeType = infoExecutionDegree.getInfoDegreeCurricularPlan().getInfoDegree().getDegreeType() .toString(); } result.add( new LabelValueBean( degreeType + " " + infoExecutionDegree.getInfoDegreeCurricularPlan().getInfoDegree() .getNome() + " - " + infoExecutionDegree.getInfoDegreeCurricularPlan().getName(), infoExecutionDegree.getExternalId().toString())); } } return result; }
From source file:net.sourceforge.fenixedu.dataTransferObject.degreeAdministrativeOffice.gradeSubmission.MarkSheetManagementCreateBean.java
@Atomic public MarkSheet createOldMarkSheet(Person person) { final Collection<MarkSheetEnrolmentEvaluationBean> enrolmentEvaluationBeanList = CollectionUtils .select(getAllEnrolmentEvalutionBeans(), new Predicate() { @Override//from ww w.ja v a2s .co m public boolean evaluate(Object arg0) { return ((MarkSheetEnrolmentEvaluationBean) arg0).hasAnyGradeValue(); } }); return getCurricularCourse().createOldNormalMarkSheet(getExecutionPeriod(), getTeacher(), getEvaluationDate(), getMarkSheetType(), enrolmentEvaluationBeanList, person); }
From source file:edu.scripps.fl.pubchem.db.PCAssayPanel.java
@Transient public XRef getTarget() { List<PCAssayXRef> list = new ArrayList(); 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; }//ww w . ja v a 2s. c o m }, list); return list.size() > 0 ? list.get(0).getXRef() : null; }
From source file:BackupService.java
/** * Main method to start backup action./*from w w w .java 2 s .c o m*/ * * @return Index ID of backup (technicaly name of create index file) * @throws Exception */ public String run() throws Exception { logger.info("Backup started for '{}', to repository '{}'", idBackup, repository.getFullPath()); Set<VOBackupFile> oldFileSet = repository.getOldBackupIndex(idBackup); logger.info("Found {} files in old indexes.", oldFileSet.size()); Map<VOBackupFile, VOBackupFile> oldFileIndex = new HashMap<>(oldFileSet.size()); for (VOBackupFile voBackupFile : oldFileSet) { oldFileIndex.put(voBackupFile, voBackupFile); } logger.trace("Index prepared"); // explore source paths List<VOBackupFile> newFileList = exploreBackupFiles(); sumary.setFounded(newFileList.size()); logger.trace("finding directories."); sumary.setDirs(CollectionUtils.select(newFileList, new Predicate() { @Override public boolean evaluate(Object object) { return (((VOBackupFile) object).isDirectory()); } }).size()); logger.trace("finding empty files."); sumary.setEmptyFiles(CollectionUtils.select(newFileList, new Predicate() { @Override public boolean evaluate(Object object) { return (((VOBackupFile) object).getSize() == 0) && !((VOBackupFile) object).isDirectory(); } }).size()); logger.trace("start comparing."); // find unchanged items int cnt = 0; for (VOBackupFile voBackupFile : newFileList) { if (voBackupFile.unPrepared() && oldFileIndex.containsKey(voBackupFile)) { VOBackupFile voBackupFileOld = oldFileIndex.get(voBackupFile); // (VOBackupFile) CollectionUtils.find(oldFileSet, PredicateUtils.equalPredicate(voBackupFile)); if (voBackupFileOld != null) { voBackupFile.setFileHash(voBackupFileOld.getFileHash()); voBackupFile.setCheckSumBck(voBackupFileOld.getCheckSumBck()); cnt++; } else { logger.trace("Wrog finding old object."); } } } sumary.setNonChanged(cnt); logger.info("Found {} unchanged files.", cnt); // for unprepared items do backup cnt = 0; for (VOBackupFile voBackupFile : newFileList) { if (voBackupFile.unPrepared()) { try { repository.saveContentToRepo(voBackupFile, oldFileSet); cnt++; } catch (Exception e) { sumary.getErrors().add(voBackupFile.getPath() + " - " + e.getMessage()); logger.error("Unable to backup " + voBackupFile.getPath() + ": ", e); } } } sumary.setProcessed(cnt); logger.info("Processed {} changed or new files.", cnt); // store index in repository meta VOBackupIndex backupIndex = new VOBackupIndex(newFileList); backupIndex.setConfig(cfg); backupIndex.setSummary(sumary); // check before save VOCheckIndex voCheckIndex = repository.checkIndex(backupIndex, false, false); if (voCheckIndex.allOk()) { logger.info("check index: OK"); } else { logger.error("check index: {}", voCheckIndex.toString()); } backupIndex.setCheck(voCheckIndex); String indexFileName = repository.saveBackupIndex(backupIndex, idBackup); logger.info(sumary.toString()); logger.info("Backup ended"); return indexFileName; }