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:eu.itesla_project.modules.test.AutomaticContingenciesAndActionsDatabaseClient.java
@Override public List<Contingency> getContingencies(Network network) { List<Contingency> contingencies = new ArrayList<>(lineContigencyCount); for (Line l : Iterables.limit(network.getLines(), lineContigencyCount)) { contingencies.add(new ContingencyImpl(l.getId(), Arrays.<ContingencyElement>asList(new LineContingency(l.getId())))); }/*from w w w . java2 s . c o m*/ return contingencies; }
From source file:dagger.internal.codegen.Formatter.java
/** * Formats {@code items}, one per line. Stops after {@code limit} items. *//* w w w .ja v a 2 s. c o m*/ public void formatIndentedList(StringBuilder builder, Iterable<? extends T> items, int indentLevel, int limit) { formatIndentedList(builder, indentLevel, Iterables.limit(items, limit), Iterables.skip(items, limit)); }
From source file:org.jon.ivmark.graphit.core.graph.traversal.Traversable.java
/** * Returns a new instance only including the first 'limit' number of elements. *///from w ww. ja va 2 s . c o m public Traversable<E> head(int limit) { return create(Iterables.limit(iterable, limit)); }
From source file:org.apache.mahout.knn.means.ThreadedKmeans.java
public static List<Iterable<MatrixSlice>> split(Iterable<MatrixSlice> data, int threads) { List<Iterable<MatrixSlice>> r = Lists.newArrayList(); int size = Iterables.size(data); int block = (size + threads - 1) / threads; for (int start = 0; start < size; start += block) { final Iterable<MatrixSlice> split = Iterables.limit(Iterables.skip(data, start), (Math.min(start + block, size) - start)); r.add(split);/* w w w . j a va2s. c o m*/ } return r; }
From source file:de.kussm.direction.Directions.java
public Directions repeat(int n) { return new Directions(Iterables.concat(Iterables.limit(Iterables.cycle(directions), n))); }
From source file:com.madvay.tools.android.perf.common.TraceTransformers.java
public static TT keepAbove(final Predicate<StackTraceElement> spec) { return new TT() { @Override//from w w w. ja va 2 s . c o m public List<StackTraceElement> apply(List<StackTraceElement> input) { int matchIdx = Iterables.indexOf(input, spec); if (matchIdx == -1) { return input; } return Lists.newArrayList(Iterables.limit(input, matchIdx)); } }; }
From source file:uk.co.unclealex.executable.example.ExampleGuiceCommand.java
/** * Print a message to the user./*from w ww .j a v a 2 s . c o m*/ */ @Executable(GuiceModule.class) public void run(ExampleGuiceCommandLine exampleGuiceCommandLine) { Iterable<String> messages = Iterables.limit(Iterables.cycle(getMessageProvider().getMessage()), exampleGuiceCommandLine.getRepititions()); getStdout().println(Joiner.on('\n').join(messages)); }
From source file:org.apache.mahout.knn.means.StreamingKmeans.java
public static double estimateCutoff(Iterable<MatrixSlice> data, int sampleNum) { Iterable<MatrixSlice> top = Iterables.limit(data, sampleNum); // first we need to have a reasonable value for what a "small" distance is // so we find the shortest distance between any of the first hundred data points double distanceCutoff = Double.POSITIVE_INFINITY; for (List<WeightedVector> distances : new Brute(top).search(top, 2)) { if (distances.size() > 1) { final double x = distances.get(1).getWeight(); if (x != 0 && x < distanceCutoff) { distanceCutoff = x;/*w ww. ja v a2 s . c om*/ } } } return distanceCutoff; }
From source file:io.druid.query.search.SearchBinaryFn.java
@Override public Result<SearchResultValue> apply(Result<SearchResultValue> arg1, Result<SearchResultValue> arg2) { if (arg1 == null) { return arg2; }//from w ww .ja va2 s .com if (arg2 == null) { return arg1; } SearchResultValue arg1Vals = arg1.getValue(); SearchResultValue arg2Vals = arg2.getValue(); TreeSet<SearchHit> results = Sets.newTreeSet(searchSortSpec.getComparator()); results.addAll(Lists.newArrayList(arg1Vals)); results.addAll(Lists.newArrayList(arg2Vals)); return (gran instanceof AllGranularity) ? new Result<SearchResultValue>(arg1.getTimestamp(), new SearchResultValue(Lists.newArrayList(Iterables.limit(results, limit)))) : new Result<SearchResultValue>(gran.toDateTime(gran.truncate(arg1.getTimestamp().getMillis())), new SearchResultValue(Lists.newArrayList(results))); }
From source file:com.amazon.janusgraph.diskstorage.dynamodb.QueryWithLimitWorker.java
@Override protected List<Map<String, AttributeValue>> getFinalItemList() { Iterable<Map<String, AttributeValue>> limitedIter = Iterables.limit(super.getFinalItemList(), limit); return Lists.newArrayList(limitedIter); }