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:org.apache.james.transport.mailets.remote.delivery.DelaysAndMaxRetry.java
private static DelaysAndMaxRetry addExtraAttemptToLastDelay(int intendedMaxRetries, int extra, List<Delay> delayTimesList) throws MessagingException { if (delayTimesList.size() != 0) { Delay lastDelay = delayTimesList.get(delayTimesList.size() - 1); LOGGER.warn("Delay of {} msecs is now attempted: {} times", lastDelay.getDelayTimeInMs(), lastDelay.getAttempts()); return new DelaysAndMaxRetry(intendedMaxRetries, ImmutableList.copyOf(Iterables.concat( Iterables.limit(delayTimesList, delayTimesList.size() - 1), ImmutableList.of(new Delay(lastDelay.getAttempts() + extra, lastDelay.getDelayTimeInMs()))))); } else {/* ww w.java 2 s . co m*/ throw new MessagingException("No delaytimes, cannot continue"); } }
From source file:org.zanata.client.commands.init.TransConfigPrompt.java
public TransConfigPrompt(ConsoleInteractor console, ConfigurableProjectOptions opts, Set<String> srcFiles) { this.console = console; this.opts = opts; this.srcFilesSample = ImmutableSet.copyOf(Iterables.limit(srcFiles, 5)); remainingFileNumber = srcFiles.size() - srcFilesSample.size(); pullOptions = new PullOptionsImpl(); // copy over options pullOptions.setUrl(opts.getUrl());/*from ww w . j a va 2s . c o m*/ pullOptions.setUsername(opts.getUsername()); pullOptions.setKey(opts.getKey()); pullOptions.setProj(opts.getProj()); pullOptions.setProjectVersion(opts.getProjectVersion()); pullOptions.setProjectType(opts.getProjectType()); pullOptions.setLocaleMapList(opts.getLocaleMapList()); transFilePathFinder = makeTransFilePathFinder(pullOptions); }
From source file:com.facebook.presto.tests.QueryAssertions.java
public static void assertContains(MaterializedResult actual, MaterializedResult expected) { for (MaterializedRow row : expected.getMaterializedRows()) { if (!actual.getMaterializedRows().contains(row)) { fail(format("expected row missing: %s\nActual %s rows:\n %s\nExpected %s rows:\n %s\n", row, actual.getMaterializedRows().size(), Joiner.on("\n ").join(Iterables.limit(actual, 100)), expected.getMaterializedRows().size(), Joiner.on("\n ").join(Iterables.limit(expected, 100)))); }//from w ww . j a v a2s . c om } }
From source file:com.brighttag.agathon.service.impl.PerDataCenterSeedService.java
/** * Return the first {@code numSeeds} seeds from the {@code instancesInDC} collection * for the given {@code dataCenter}./*from www . jav a 2s. c om*/ * * @param dataCenter the data center name * @param instancesInDC a collection of instances in the data center * @return the public DNS names or IP addresses of the first {@code numSeeds} hosts */ private Iterable<String> getSeeds(String dataCenter, ImmutableSet<CassandraInstance> instancesInDC) { int size = instancesInDC.size(); if (size < numSeeds) { LOG.warn("Too few seeds for data center '{}'. Continuing with {} seeds.", dataCenter, size); } return Iterables.transform(Iterables.limit(instancesInDC, numSeeds), INSTANCE_TO_SEED); }
From source file:eu.esdihumboldt.cst.functions.groovy.helper.Category.java
/** * Get the parent category.//from w ww. ja v a2 s. c o m * * @return the parent category */ @Nullable public Category getParent() { if (path == null || path.isEmpty()) { // no parent return null; } else if (path.size() == 1) { return Category.ROOT; } else { return new Category(Iterables.limit(path, path.size() - 1)); } }
From source file:org.obm.push.bean.change.hierarchy.MailboxPath.java
public Iterable<MailboxPath> reducingPaths() { Builder<MailboxPath> paths = ImmutableList.builder(); List<String> pieces = Splitter.on(separator).omitEmptyStrings().splitToList(path); for (int index = pieces.size() - 1; index > 0; index--) { String path = Joiner.on(separator).join(Iterables.limit(pieces, index)); paths.add(MailboxPath.of(path, separator)); }//from ww w .ja va2 s . c om return paths.build(); }
From source file:org.apache.streams.data.util.PropertyUtil.java
public static ObjectNode unflattenObjectNode(ObjectNode flatObject, char seperator) { ObjectNode root = mapper.createObjectNode(); Iterator<Map.Entry<String, JsonNode>> iter = flatObject.fields(); while (iter.hasNext()) { Map.Entry<String, JsonNode> item = iter.next(); String fullKey = item.getKey(); if (!fullKey.contains(Character.valueOf(seperator).toString())) { root.put(item.getKey(), item.getValue()); } else {// w w w . ja v a 2 s. c om ObjectNode currentNode = root; List<String> keyParts = new ArrayList<>(); Iterables.addAll(keyParts, Splitter.on(seperator).split(item.getKey())); for (String part : Iterables.limit(Splitter.on(seperator).split(item.getKey()), keyParts.size() - 1)) { if (currentNode.has(part) && currentNode.get(part).isObject()) { currentNode = (ObjectNode) currentNode.get(part); } else { ObjectNode newNode = mapper.createObjectNode(); currentNode.put(part, newNode); currentNode = newNode; } } currentNode.put(keyParts.get(keyParts.size() - 1), item.getValue()); } } return root; }
From source file:com.palantir.common.collect.IterableView.java
public IterableView<T> limit(int limitSize) { return of(Iterables.limit(delegate(), limitSize)); }
From source file:com.google.errorprone.apply.DiffApplier.java
private final void decrementTasks() { if (runState.decrementAndGet() == 0) { workerService.shutdown();// ww w. java2s . com try { destination.flush(); notifyStopped(); } catch (Exception e) { notifyFailed(e); } logger.log(Level.INFO, String.format("Completed %d files in %s", completedFiles.get(), stopwatch)); if (!diffsFailedPaths.isEmpty()) { logger.log(Level.SEVERE, String.format("Diffs failed to apply to %d files: %s", diffsFailedPaths.size(), Iterables.limit(diffsFailedPaths, 30))); } } }
From source file:org.apache.solr.analytics.facet.SortableFacet.java
/** * Apply the sorting options to the given facet results. * /* w ww. j ava 2 s .co m*/ * @param facetResults to apply sorting options to * @return the sorted results */ @SuppressWarnings({ "unchecked", "rawtypes" }) protected Iterable<FacetBucket> applyOptions(List<FacetBucket> facetResults) { // Sorting the buckets if a sort specification is provided if (sort == null || facetResults.isEmpty()) { return facetResults; } Comparator comp = sort.getComparator(); Collections.sort(facetResults, comp); Iterable<FacetBucket> facetResultsIter = facetResults; // apply the limit if (sort.getLimit() > 0) { if (sort.getOffset() > 0) { facetResultsIter = Iterables.skip(facetResultsIter, sort.getOffset()); } facetResultsIter = Iterables.limit(facetResultsIter, sort.getLimit()); } else if (sort.getLimit() == 0) { return new LinkedList<FacetBucket>(); } return facetResultsIter; }