List of usage examples for com.google.common.collect Iterables limit
public static <T> Iterable<T> limit(final Iterable<T> iterable, final int limitSize)
From source file:cosmos.results.PagedResults.java
public PagedResults(CloseableIterable<T> results, Paging limits) { checkNotNull(results);/*from w w w . ja v a2s . c om*/ checkNotNull(limits); source = results; pagedLimitedResults = Iterables.partition(Iterables.limit(results, limits.maxResults()), limits.pageSize()); }
From source file:org.opendaylight.protocol.bgp.rib.impl.IdentifierUtils.java
private static YangInstanceIdentifier firstIdentifierOf(final YangInstanceIdentifier id, final Predicate<PathArgument> match) { final int idx = Iterables.indexOf(id.getPathArguments(), match); Preconditions.checkArgument(idx != -1, "Failed to find %s in %s", match, id); // we want the element at index idx to be included in the list return YangInstanceIdentifier.create(Iterables.limit(id.getPathArguments(), idx + 1)); }
From source file:com.madvay.tools.android.perf.common.TraceTransformers.java
public static TT pruneBelow(final Predicate<StackTraceElement> spec) { return new TT() { @Override//w w w . j av a 2 s. c om public List<StackTraceElement> apply(List<StackTraceElement> input) { int last = -1; for (int i = input.size() - 1; i >= 0; i--) { if (spec.apply(input.get(i))) { last = i; break; } } return Lists.newArrayList(Iterables.limit(input, last + 1)); } }; }
From source file:com.yahoo.yqlplus.engine.internal.java.sequences.Sequences.java
public static <ROW> Iterable<ROW> doSlice(Iterable<ROW> source, int limit, int offset) { Preconditions.checkArgument(offset >= 0, "offset >= 0"); if (offset > 0) { source = Iterables.skip(source, offset); }// w ww. j a v a 2 s . c o m if (limit >= 0) { source = Iterables.limit(source, limit); } return source; }
From source file:clocker.docker.location.strategy.basic.BreadthFirstPlacementStrategy.java
@Override public List<DockerHostLocation> filterLocations(List<DockerHostLocation> locations, Entity context) { if (locations == null || locations.isEmpty()) { return ImmutableList.of(); }/*ww w. j a v a 2 s .c om*/ int size = Iterables.size(locations); int next = counter.incrementAndGet() % size; if (LOG.isDebugEnabled()) { LOG.debug("Breadth first strategy using {} of {}", next, size); } return ImmutableList .copyOf(Iterables.concat(Iterables.skip(locations, next), Iterables.limit(locations, next))); }
From source file:org.apache.drill.exec.testing.store.NoWriteLocalStore.java
@Override public Iterator<Map.Entry<String, V>> getRange(final int skip, final int take) { return Iterables.limit(Iterables.skip(store.entrySet(), skip), take).iterator(); }
From source file:org.matsim.contrib.taxi.optimizer.mip.MIPRequestData.java
MIPRequestData(TaxiOptimizerContext optimContext, SortedSet<TaxiRequest> unplannedRequests, int planningHorizon) { dimension = Math.min(planningHorizon, unplannedRequests.size()); requests = Iterables.toArray(Iterables.limit(unplannedRequests, dimension), TaxiRequest.class); for (int i = 0; i < dimension; i++) { reqIdToIdx.put(requests[i].getId(), i); }/* w ww . j a va 2 s. co m*/ }
From source file:playground.michalm.taxi.optimizer.mip.MIPRequestData.java
MIPRequestData(TaxiOptimizerConfiguration optimConfig, SortedSet<TaxiRequest> unplannedRequests, int planningHorizon) { dimension = Math.min(planningHorizon, unplannedRequests.size()); requests = Iterables.toArray(Iterables.limit(unplannedRequests, dimension), TaxiRequest.class); for (int i = 0; i < dimension; i++) { reqIdToIdx.put(requests[i].getId(), i); }//from www.j a v a2 s .com }
From source file:org.apache.mahout.knn.means.ThreadedKmeans.java
public Searcher cluster(final DistanceMeasure distance, List<Iterable<MatrixSlice>> data, final int maxClusters, final int threads, final StreamingKmeans.CentroidFactory centroidFactory) throws InterruptedException, ExecutionException { // initialize scale int i = 0;/*from w w w.ja va2 s .c o m*/ final int width = data.get(0).iterator().next().vector().size(); Matrix sample = new DenseMatrix(100, width); for (Iterable<MatrixSlice> split : data) { sample = sampleRows(sample, i, Iterables.limit(split, 1000), 100); i += 100; } List<Callable<Searcher>> tasks = Lists.newArrayList(); ExecutorService pool = Executors.newFixedThreadPool(threads); for (final Iterable<MatrixSlice> split : data) { tasks.add(new Callable<Searcher>() { @Override public Searcher call() { return new StreamingKmeans().cluster(split, maxClusters, centroidFactory); } }); } List<Future<Searcher>> results = pool.invokeAll(tasks); pool.shutdown(); List<MatrixSlice> raw = Lists.newArrayList(); for (Future<Searcher> result : results) { Iterables.addAll(raw, result.get()); } return new StreamingKmeans().cluster(raw, data.size() * maxClusters, centroidFactory); }
From source file:eu.lp0.cursus.scoring.scores.impl.GenericRaceDiscardsData.java
@Override protected List<Race> calculateDiscardedRaces(Pilot pilot) { if (discards > 0) { final Map<Race, Integer> racePoints = scores.getRacePoints(pilot); // Discard the highest scoring races return Lists.newArrayList(Iterables.limit(Ordering.from(new Comparator<Race>() { @Override/*from w w w.j av a2 s .c o m*/ public int compare(Race o1, Race o2) { return ComparisonChain.start().compare(racePoints.get(o2), racePoints.get(o1)).compare(o1, o2) .result(); } // Use all races where the score is not null }).immutableSortedCopy(Maps.filterValues(racePoints, Predicates.notNull()).keySet()), discards)); } return Collections.emptyList(); }