List of usage examples for org.apache.commons.collections Predicate Predicate
Predicate
From source file:net.sourceforge.fenixedu.dataTransferObject.CurricularCourseScopesForPrintDTO.java
private DegreeCurricularPlanForPrintDTO getSelectedCurricularPlan(final InfoCurricularCourseScope scope) { DegreeCurricularPlanForPrintDTO selectedCurricularPlan = (DegreeCurricularPlanForPrintDTO) CollectionUtils .find(getDegreeCurricularPlans(), new Predicate() { @Override/*from ww w . j a v a 2s . c o m*/ public boolean evaluate(Object arg0) { DegreeCurricularPlanForPrintDTO degreeCurricularPlanForPrintDTO = (DegreeCurricularPlanForPrintDTO) arg0; if (degreeCurricularPlanForPrintDTO.name .equals(scope.getInfoCurricularCourse().getInfoDegreeCurricularPlan().getName())) { return true; } return false; } }); if (selectedCurricularPlan == null) { InfoDegreeCurricularPlan degreeCurricularPlan = scope.getInfoCurricularCourse() .getInfoDegreeCurricularPlan(); selectedCurricularPlan = new DegreeCurricularPlanForPrintDTO(degreeCurricularPlan.getName(), degreeCurricularPlan.getInfoDegree().getNome(), degreeCurricularPlan.getAnotation()); this.getDegreeCurricularPlans().add(selectedCurricularPlan); } return selectedCurricularPlan; }
From source file:net.sourceforge.fenixedu.domain.student.importation.ExportDegreeCandidaciesByDegreeForPasswordGeneration.java
public static List<ExportDegreeCandidaciesByDegreeForPasswordGeneration> readPendingJobs( final ExecutionYear executionYear) { List<ExportDegreeCandidaciesByDegreeForPasswordGeneration> jobList = new ArrayList<ExportDegreeCandidaciesByDegreeForPasswordGeneration>(); CollectionUtils.select(executionYear.getDgesBaseProcessSet(), new Predicate() { @Override//from w w w. j a v a 2 s . c o m public boolean evaluate(Object arg0) { return (arg0 instanceof ExportDegreeCandidaciesByDegreeForPasswordGeneration) && ((QueueJob) arg0).getIsNotDoneAndNotCancelled(); } }, jobList); return jobList; }
From source file:gov.nih.nci.ncicb.tcga.dcc.datareports.service.DatareportsServiceImpl.java
public Predicate genDatePredicate(final Class clazz, final String getter, final boolean before, final String dateStr, final DateFormat dateFormat) { return new Predicate() { public boolean evaluate(Object o) { if (dateStr == null || "".equals(dateStr)) { return true; }/*w ww. ja v a 2 s.c o m*/ Date date; try { date = dateFormat.parse(dateStr); } catch (ParseException e) { return true; } if (date == null) { return true; } try { final Method m = GetterMethod.getGetter(clazz, getter); if (before) { return ((Date) m.invoke(clazz.cast(o))).before(date); } else { return ((Date) m.invoke(clazz.cast(o))).after(date); } } catch (Exception e) { logger.debug(FancyExceptionLogger.printException(e)); return true; } } }; }
From source file:au.com.jwatmuff.eventmanager.model.misc.PoolPlayerSequencer.java
public static List<PlayerPoolInfo> getPlayerSequence(Database database, int poolID) { int numPlayerPositions = getNumberOfPlayerPositions(database, poolID); List<PlayerPoolInfo> players = new ArrayList<PlayerPoolInfo>(PlayerPoolInfo.getForPool(database, poolID)); List<PlayerPoolInfo> newPlayers = new ArrayList<PlayerPoolInfo>(); CollectionUtils.filter(players, new Predicate() { @Override//w w w . java 2 s.com @SuppressWarnings("unchecked") public boolean evaluate(Object player) { return ((PlayerPoolInfo) player).getPlayerPool().isApproved(); } }); boolean repositionPlayers = false; for (PlayerPoolInfo player : players) { if (player.getPlayerPool().getPlayerPosition() > numPlayerPositions) { repositionPlayers = true; } } if (repositionPlayers) { Collections.sort(players, PLAYERS_COMPARATOR_POSITION); newPlayers.addAll(players); } else { Collections.sort(players, PLAYERS_COMPARATOR_POSITION); // create a new list with null entries so that player pool position reflects // the index of each player in the list int index = 1; for (PlayerPoolInfo player : players) { while (index < player.getPlayerPool().getPlayerPosition()) { newPlayers.add(null); index++; } newPlayers.add(player); index++; } } // finally, insert any additional nulls to make the length of the list // equal to the number of player positions in the pool for (int index = newPlayers.size() + 1; index <= numPlayerPositions; index++) newPlayers.add(null); return newPlayers; }
From source file:RestoreService.java
/** * execute restore process/*from ww w . jav a 2 s . c o m*/ * * @throws Exception */ public void run() throws Exception { // load index Collection<File> bckIdxCollection = FileUtils.listFiles(repository.getMetaPath(), new WildcardFileFilter(bckIdxName + "*"), TrueFileFilter.INSTANCE); // TODO Lebeda - check only one index file // find files ro restore Set<VOBackupFile> oldFileSet = repository.collectBackupedFilesFromIndex(bckIdxCollection); Set<VOBackupFile> restoreFileSet = new HashSet<>(); for (final String path : pathToRestoreList) { //noinspection unchecked restoreFileSet.addAll((Collection<VOBackupFile>) CollectionUtils.select(oldFileSet, new Predicate() { @Override public boolean evaluate(Object object) { VOBackupFile voBackupFile = (VOBackupFile) object; return StringUtils.startsWithIgnoreCase(voBackupFile.getPath(), path + File.separator); } })); } // create directory if not exists for (String pathForRestore : pathToRestoreList) { pathForRestore = changedPathToRestore(pathForRestore, targetPath); File baseFile = new File(pathForRestore); if (!baseFile.exists()) { //noinspection ResultOfMethodCallIgnored baseFile.mkdirs(); // TODO Lebeda - oetit hodnotu } } // find files in directory List<VOBackupFile> newFileList = new ArrayList<>(); for (String pathForRestore : pathToRestoreList) { pathForRestore = changedPathToRestore(pathForRestore, targetPath); //noinspection unchecked final Collection<File> fileColection = FileUtils.listFiles(new File(pathForRestore), TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE); for (File file : fileColection) { newFileList.add(new VOBackupFile(file)); } } // delete files not in index (new or changed) //noinspection unchecked final Collection<VOBackupFile> toDelete = (Collection<VOBackupFile>) CollectionUtils.subtract(newFileList, restoreFileSet); for (VOBackupFile voBackupFile : toDelete) { FileUtils.forceDelete(new File(voBackupFile.getPath())); logger.debug("deleted file: {}", voBackupFile.getPath()); } // restore files not in direcroty //noinspection unchecked final Collection<VOBackupFile> toRestore = (Collection<VOBackupFile>) CollectionUtils .subtract(restoreFileSet, newFileList); final Collection<VOBackupFile> toTime = new ArrayList<>(); for (VOBackupFile voBackupFile : toRestore) { String path = changedPathToRestore(voBackupFile.getPath(), targetPath); if (!voBackupFile.isSymLink()) { if (voBackupFile.isDirectory()) { File dir = new File(path); dir.mkdirs(); // TODO Lebeda - zajistit oeten toTime.add(voBackupFile); setAdvancedAttributes(voBackupFile, dir); } else if (voBackupFile.getSize() == 0) { File file = new File(path); file.createNewFile(); // TODO Lebeda - oetit file.setLastModified(voBackupFile.getModify().getTime()); setAdvancedAttributes(voBackupFile, file); } else if (StringUtils.isNotBlank(voBackupFile.getFileHash())) { repository.restoreFile(voBackupFile, path); } else { // TODO Lebeda - chyba // LoggerTools.log("unable to restore ${it}") } } } // symlinks restore at end for (VOBackupFile voBackupFile : toRestore) { String path = changedPathToRestore(voBackupFile.getPath(), targetPath); if (voBackupFile.isSymLink()) { Files.createSymbolicLink(Paths.get(path), Paths.get(voBackupFile.getSymlinkTarget())); } } for (VOBackupFile voBackupFile : toTime) { String path = changedPathToRestore(voBackupFile.getPath(), targetPath); File dir = new File(path); dir.setLastModified(voBackupFile.getModify().getTime()); } }
From source file:module.mailtracking.domain.MailTracking.java
static java.util.List<CorrespondenceEntry> filterEntriesByTypeAndState( final java.util.Collection<CorrespondenceEntry> entries, final CorrespondenceEntryState state, final CorrespondenceType type) { java.util.List<CorrespondenceEntry> activeEntries = new java.util.ArrayList<CorrespondenceEntry>(); CollectionUtils.select(entries, new Predicate() { @Override/*from www . j av a 2 s. co m*/ public boolean evaluate(Object arg0) { CorrespondenceEntry entry = (CorrespondenceEntry) arg0; return (state == null || state.equals(entry.getState())) && (type == null || type.equals(entry.getType())); } }, activeEntries); return activeEntries; }
From source file:net.sf.wickedshell.facade.descriptor.XMLShellDescriptor.java
/** * @see net.sf.wickedshell.facade.descriptor.IShellDescriptor#isCurrentOSSupported() *///www . ja va 2 s. c o m public boolean isCurrentOSSupported() { final String operatingSystem = System.getProperty(ShellID.OS_KEY); return CollectionUtils.exists(Arrays.asList(getOperatingSystems()), new Predicate() { /** * @see org.apache.commons.collections.Predicate#evaluate(java.lang.Object) */ public boolean evaluate(Object object) { String supportingOperatingSystem = (String) object; return supportingOperatingSystem.equalsIgnoreCase(operatingSystem); } }); }
From source file:com.cyberway.issue.crawler.extractor.JerichoExtractorHTMLTest.java
/** * Test a POST FORM ACTION being properly ignored * /*from w ww . j a v a 2 s . co m*/ * @throws URIException */ public void testFormsLinkIgnorePost() throws URIException { CrawlURI curi = new CrawlURI(UURIFactory.getInstance("http://www.example.org")); CharSequence cs = "<form name=\"testform\" method=\"POST\" action=\"redirect_me?form=true\"> " + " <INPUT TYPE=CHECKBOX NAME=\"checked[]\" VALUE=\"1\" CHECKED> " + " <INPUT TYPE=CHECKBOX NAME=\"unchecked[]\" VALUE=\"1\"> " + " <select name=\"selectBox\">" + " <option value=\"selectedOption\" selected>option1</option>" + " <option value=\"nonselectedOption\">option2</option>" + " </select>" + " <input type=\"submit\" name=\"test\" value=\"Go\">" + "</form>"; this.extractor.extract(curi, cs); curi.getOutLinks(); assertTrue(!CollectionUtils.exists(curi.getOutLinks(), new Predicate() { public boolean evaluate(Object object) { return ((Link) object).getDestination().toString().indexOf( "/redirect_me?form=true&checked[]=1&unchecked[]=&selectBox=selectedOption&test=Go") >= 0; } })); }
From source file:com.linkedin.pinot.common.data.Schema.java
@JsonIgnore(true) public MetricFieldSpec getMetricSpec(final String metricName) { return (MetricFieldSpec) CollectionUtils.find(metricFieldSpecs, new Predicate() { @Override// www .ja va 2 s . c o m public boolean evaluate(Object object) { if (object instanceof MetricFieldSpec) { MetricFieldSpec spec = (MetricFieldSpec) object; return spec.getName().equals(metricName); } return false; } }); }
From source file:com.projity.pm.graphic.spreadsheet.common.transfer.NodeListTransferHandler.java
protected Transferable createTransferable(JComponent c, int action) { SpreadSheet spreadSheet = getSpreadSheet(c); if (spreadSheet == null) return null; ArrayList nodes = (ArrayList) spreadSheet.getSelectedNodes().clone(); ArrayList fields = spreadSheet.getSelectedFields(); boolean nodeSelection = (fields == null); if (fields == null) fields = spreadSheet.getSelectableFields(); if (action == TransferHandler.COPY) { if (nodeSelection) { SpreadSheet.SpreadSheetAction a = getNodeListCopyAction().getSpreadSheetAction(); a.execute(nodes);//from w w w . j av a2 s . c o m } return new NodeListTransferable(nodes, fields, spreadSheet, spreadSheet.getSelectedRows(), spreadSheet.getSelectedColumns(), nodeSelection); } else if (action == TransferHandler.MOVE) {//cut if (nodeSelection) { SpreadSheet.SpreadSheetAction a = ((nodeSelection) ? getNodeListCutAction() : getNodeListCopyAction()).getSpreadSheetAction(); for (Iterator i = nodes.iterator(); i.hasNext();) { Node node = (Node) i.next(); final boolean[] okForAll = new boolean[] { false }; if (!transformSubprojectBranches(node, spreadSheet.getCache().getModel().getDataFactory(), new Predicate() { public boolean evaluate(Object arg0) { if (okForAll[0]) return true; Node parent = (Node) arg0; boolean r = Alert.okCancel(Messages.getString("Message.subprojectCut")); if (r) okForAll[0] = true; return r; } })) return null; } a.execute(nodes); } return new NodeListTransferable(nodes, fields, spreadSheet, spreadSheet.getSelectedRows(), spreadSheet.getSelectedColumns(), nodeSelection); } else return null; }