List of usage examples for com.google.common.collect Iterables skip
public static <T> Iterable<T> skip(final Iterable<T> iterable, final int numberToSkip)
From source file:dagger.internal.codegen.Formatter.java
/** * Formats {@code items}, one per line. Stops after {@code limit} items. *//* w w w . j ava2 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.sonar.java.checks.xml.struts.ActionNumberCheck.java
@Override public void scanFileWithXPathExpressions(XmlCheckContext context) { for (Node action : context.evaluateOnDocument(actionsExpression)) { Iterable<Node> extraForwards = Iterables.skip(context.evaluate(forwardsFromActionExpression, action), maximumForwards);// w w w .j a v a2s . c o m if (!Iterables.isEmpty(extraForwards)) { List<XmlCheckContext.XmlDocumentLocation> secondaries = new LinkedList<>(); for (Node forward : extraForwards) { secondaries.add(new XmlCheckContext.XmlDocumentLocation("Move this forward to another action.", forward)); } int cost = secondaries.size(); int numberForward = maximumForwards + cost; String message = "Reduce the number of forwards in this action from " + numberForward + " to at most " + maximumForwards + "."; context.reportIssue(this, action, message, secondaries, cost); } } }
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);//from w ww . ja v a 2 s . c o m } return r; }
From source file:io.jare.tk.TkRelay.java
/** * The request to send.//from ww w. jav a 2 s .c om * @param req Original request * @param path Destination path * @return Request */ private static Request request(final Request req, final String path) { return new Request() { @Override public Iterable<String> head() throws IOException { return Iterables.concat(Collections.singleton(String.format("GET %s HTTP/1.1", path)), Iterables.skip(req.head(), 1)); } @Override public InputStream body() throws IOException { return req.body(); } }; }
From source file:com.sk89q.worldedit.spout.SpoutEntity.java
@Override public boolean spawn(Location loc) { World world = ((SpoutWorld) loc.getWorld()).getWorld(); Point pos = SpoutUtil.toPoint(world, loc.getPosition()); Class<? extends Component> mainComponent = null; if (components.size() > 0) { mainComponent = components.get(0); }//from w ww. j a v a2 s.c om if (mainComponent == null) { return false; } Entity e = world.createAndSpawnEntity(pos, mainComponent, LoadOption.LOAD_ONLY); // Blocks should already be pasted by time entitieos are brought in if (e != null) { e.getTransform().setPitch(loc.getPitch()); e.getTransform().setYaw(loc.getYaw()); for (Class<? extends Component> clazz : Iterables.skip(components, 1)) { e.add(clazz); } try { e.getData().deserialize(datatableBytes, true); } catch (IOException e1) { return false; } return true; } return false; }
From source file:org.jon.ivmark.graphit.core.graph.traversal.Traversable.java
/** * Returns a new instance discarding the first 'skip' elements. *///from ww w . jav a 2 s. co m public Traversable<E> skip(int skip) { return create(Iterables.skip(iterable, skip)); }
From source file:nextmethod.web.razor.parser.internal.WhiteSpaceRewriter.java
@Override protected SyntaxTreeNode rewriteBlock(@Nonnull final BlockBuilder parent, @Nonnull final Block block) { final BlockBuilder newBlock = new BlockBuilder(checkNotNull(block)); newBlock.getChildren().clear();/* ww w.jav a 2 s . com*/ final Span ws = typeAs(Iterables.getFirst(block.getChildren(), null), Span.class); Collection<SyntaxTreeNode> newNodes = block.getChildren(); if (ws != null && ParserHelpers.isAllOfString(ws.getContent(), ParserHelpers::isWhitespace)) { // Add this node to the parent final SpanBuilder builder = new SpanBuilder(ws); builder.clearSymbols(); fillSpan(builder, ws.getStart(), ws.getContent()); parent.getChildren().add(builder.build()); // Remove the old whitespace node newNodes = Lists.newArrayList(Iterables.skip(block.getChildren(), 1)); } for (SyntaxTreeNode node : newNodes) { newBlock.getChildren().add(node); } return newBlock.build(); }
From source file:com.madvay.tools.android.perf.common.TraceTransformers.java
public static TT keepBelow(final Predicate<StackTraceElement> spec) { return new TT() { @Override/* w ww .j av a 2s .c o m*/ 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.skip(input, last + 1)); } }; }
From source file:org.apache.james.utils.FileConfigurationProvider.java
@Override public HierarchicalConfiguration getConfiguration(String component) throws ConfigurationException { Preconditions.checkNotNull(component); List<String> configPathParts = Splitter.on(".").splitToList(component); Preconditions.checkArgument(!configPathParts.isEmpty()); HierarchicalConfiguration config = getConfig(retrieveConfigInputStream(configPathParts.get(0))); return selectHierarchicalConfigPart(config, Iterables.skip(configPathParts, 1)); }
From source file:org.apache.james.mailrepository.api.MailRepositoryUrl.java
private MailRepositoryUrl(String value) { Preconditions.checkNotNull(value);// w w w . j a va 2s . c o m Preconditions.checkArgument(value.contains(PROTOCOL_SEPARATOR), "The expected format is: <protocol> \"" + PROTOCOL_SEPARATOR + "\" <path>"); this.value = value; List<String> urlParts = Splitter.on(PROTOCOL_SEPARATOR).splitToList(value); this.protocol = new Protocol(urlParts.get(PROTOCOL_PART)); this.path = MailRepositoryPath .from(Joiner.on(PROTOCOL_SEPARATOR).join(Iterables.skip(urlParts, SKIP_PROTOCOL))); }