List of usage examples for com.google.common.collect Iterables removeIf
public static <T> boolean removeIf(Iterable<T> removeFrom, Predicate<? super T> predicate)
From source file:org.apache.drill.exec.schema.ListSchema.java
@Override public Iterable<? extends Field> removeUnreadFields() { final List<Field> removedFields = Lists.newArrayList(); Iterables.removeIf(fields, new Predicate<Field>() { @Override//from w w w .j av a 2 s . c o m public boolean apply(Field field) { if (!field.isRead()) { removedFields.add(field); return true; } else if (field.hasSchema()) { Iterables.addAll(removedFields, field.getAssignedSchema().removeUnreadFields()); } return false; } }); return removedFields; }
From source file:com.twitter.aurora.scheduler.async.TaskGroup.java
void remove(String taskId) { Iterables.removeIf(tasks, Predicates.compose(Predicates.equalTo(taskId), TO_TASK_ID)); }
From source file:com.eucalyptus.reporting.domain.ReportingUserDao.java
private List<ReportingUser> searchReportingUser(final ReportingUser searchUser) { List<ReportingUser> reportingUserList = Lists.newArrayList(); EntityTransaction db = Entities.get(ReportingUser.class); try {//w ww. j a v a2s . c o m reportingUserList = (List<ReportingUser>) Entities.query(searchUser, true); db.commit(); } catch (Exception ex) { LOG.error(ex, ex); reportingUserList.clear(); } finally { if (db.isActive()) db.rollback(); } Iterables.removeIf(reportingUserList, Predicates.isNull()); if (!reportingUserList.isEmpty()) { return reportingUserList; } else { return null; } }
From source file:de.cosmocode.commons.validation.AbstractRule.java
@Override public boolean removeIf(Iterable<? extends T> removeFrom) { Preconditions.checkNotNull(removeFrom, "RemoveFrom"); return Iterables.removeIf(removeFrom, this); }
From source file:org.pentaho.di.trans.dataservice.optimization.cache.CachedServiceLoader.java
ListenableFuture<Integer> replay(DataServiceExecutor dataServiceExecutor) throws KettleException { final Trans serviceTrans = dataServiceExecutor.getServiceTrans(), genTrans = dataServiceExecutor.getGenTrans(); final CountDownLatch startReplay = new CountDownLatch(1); final RowProducer rowProducer = dataServiceExecutor.addRowProducer(); List<Runnable> startTrans = dataServiceExecutor.getListenerMap() .get(DataServiceExecutor.ExecutionPoint.START), postOptimization = dataServiceExecutor.getListenerMap() .get(DataServiceExecutor.ExecutionPoint.READY); Iterables.removeIf(postOptimization, Predicates.instanceOf(DefaultTransWiring.class)); Iterables.removeIf(startTrans, new Predicate<Runnable>() { @Override// w ww . j a v a 2 s. c o m public boolean apply(Runnable runnable) { return runnable instanceof TransStarter && ((TransStarter) runnable).getTrans().equals(serviceTrans); } }); postOptimization.add(new Runnable() { @Override public void run() { serviceTrans.stopAll(); for (StepMetaDataCombi stepMetaDataCombi : serviceTrans.getSteps()) { stepMetaDataCombi.step.setOutputDone(); stepMetaDataCombi.step.dispose(stepMetaDataCombi.meta, stepMetaDataCombi.data); stepMetaDataCombi.step.markStop(); } } }); startTrans.add(new Runnable() { @Override public void run() { startReplay.countDown(); } }); ListenableFutureTask<Integer> replay = ListenableFutureTask.create(new Callable<Integer>() { @Override public Integer call() throws Exception { Preconditions.checkState(startReplay.await(30, TimeUnit.SECONDS), "Cache replay did not start"); int rowCount = 0; for (Iterator<RowMetaAndData> iterator = rowSupplier.get(); iterator.hasNext() && genTrans.isRunning();) { RowMetaAndData metaAndData = iterator.next(); boolean rowAdded = false; RowMetaInterface rowMeta = metaAndData.getRowMeta(); Object[] rowData = rowMeta.cloneRow(metaAndData.getData()); while (!rowAdded && genTrans.isRunning()) { rowAdded = rowProducer.putRowWait(rowMeta, rowData, 10, TimeUnit.SECONDS); } if (rowAdded) { rowCount += 1; } } rowProducer.finished(); return rowCount; } }); executor.execute(replay); return replay; }
From source file:org.syncany.gui.tray.RecentFileChanges.java
private synchronized void replaceEntry(final RecentFileEntry recentFileEntry) { // Remove old entry Iterables.removeIf(recentFileChanges, new Predicate<RecentFileEntry>() { @Override// w ww. j ava 2 s . c o m public boolean apply(RecentFileEntry aRecentFileEntry) { return aRecentFileEntry.file.equals(recentFileEntry.file); } }); // Add new entry recentFileChanges.add(recentFileEntry); }
From source file:eu.interedition.collatex.medite.MediteAlgorithm.java
@Override public void collate(VariantGraph graph, Iterable<Token> witness) { final VariantGraph.Vertex[][] vertices = VariantGraphRanking.of(graph).asArray(); final Token[] tokens = Iterables.toArray(witness, Token.class); final SuffixTree<Token> suffixTree = SuffixTree.build(comparator, tokens); final MatchEvaluatorWrapper matchEvaluator = new MatchEvaluatorWrapper(this.matchEvaluator, tokens); final Matches matchCandidates = Matches.between(vertices, suffixTree, matchEvaluator); final SortedSet<SortedSet<VertexMatch.WithTokenIndex>> matches = Sets .newTreeSet(VertexMatch.<VertexMatch.WithTokenIndex>setComparator()); while (true) { final SortedSet<SortedSet<VertexMatch.WithTokenIndex>> maximalUniqueMatches = matchCandidates .findMaximalUniqueMatches(); if (maximalUniqueMatches.isEmpty()) { break; }//from w w w .j ava 2s. com final IntegerRangeSet rankFilter = new IntegerRangeSet(); final IntegerRangeSet tokenFilter = new IntegerRangeSet(); for (SortedSet<VertexMatch.WithTokenIndex> phrase : AlignmentDecisionGraph.filter(maximalUniqueMatches, matchEvaluator)) { final VertexMatch.WithTokenIndex firstMatch = phrase.first(); final VertexMatch.WithTokenIndex lastMatch = phrase.last(); matches.add(phrase); rankFilter.add(Range.closed(firstMatch.vertexRank, lastMatch.vertexRank)); tokenFilter.add(Range.closed(firstMatch.token, lastMatch.token)); } Iterables.removeIf(matchCandidates, VertexMatch.filter(rankFilter, tokenFilter)); } merge(graph, vertices, tokens, matches); }
From source file:org.lenskit.rerank.GreedyRerankingItemRecommender.java
@Override protected ResultList recommendWithDetails(long user, int n, @Nullable LongSet candidateItems, @Nullable LongSet exclude) {//from ww w.j a v a 2 s . co m List<Result> candidates = baseRecommender.recommendWithDetails(user, -1, candidateItems, exclude); //modifiable copy candidates = new ArrayList<>(candidates); if (n < 0) { n = candidates.size(); } List<Result> results = new ArrayList<>(n); for (int i = 0; i < n; i++) { final Result nextItem = strategy.nextItem(user, n, results, candidates); if (nextItem == null) { break; } else { Iterables.removeIf(candidates, new Predicate<Result>() { @Override public boolean apply(@Nullable Result input) { return input != null && input.getId() == nextItem.getId(); } }); results.add(nextItem); } } return Results.newResultList(results); }
From source file:org.splevo.ui.refinementbrowser.RefinementTreeContentProviderBase.java
private void removeChangeListeningAdapterFromEObject(EObject obj) { Iterables.removeIf(obj.eAdapters(), new Predicate<Adapter>() { @Override//from w ww . j av a 2s . c o m public boolean apply(Adapter arg0) { if (!(arg0 instanceof EObjectChangedAdapter)) { return false; } return ((EObjectChangedAdapter) arg0).getOwnerId() == hashCode(); } }); }
From source file:oncue.scheduler.UnscheduledJobs.java
/** * Remove a job from anywhere in the queue * /*from www . j ava 2 s . com*/ * @return a boolean, indicating if the removal was successful */ public boolean removeJobById(final long jobId) { boolean removed = Iterables.removeIf(unscheduledJobs, new Predicate<Job>() { @Override public boolean apply(Job input) { return input.getId() == jobId; } }); if (removed) backingStore.removeUnscheduledJobById(jobId); return removed; }