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:tool.Lst.java
public static <T> Iterable<T> cdr(Iterable<T> lst) { return Iterables.skip(lst, 1); }
From source file:org.renjin.primitives.special.SwitchFunction.java
private static SEXP doApply(Context context, Environment rho, FunctionCall call, PairList args) { EvalException.check(call.length() > 1, "argument \"EXPR\" is missing"); SEXP expr = context.evaluate(args.getElementAsSEXP(0), rho); EvalException.check(expr.length() == 1, "EXPR must return a length 1 vector"); Iterable<PairList.Node> branches = Iterables.skip(args.nodes(), 1); if (expr instanceof StringVector) { String name = ((StringVector) expr).getElementAsString(0); if (StringVector.isNA(name)) { context.setInvisibleFlag();//from ww w . j a v a 2 s .com return Null.INSTANCE; } SEXP partialMatch = null; int partialMatchCount = 0; for (PairList.Node node : branches) { if (node.hasTag()) { String branchName = node.getTag().getPrintName(); if (branchName.equals(name)) { return context.evaluate(nextNonMissing(node), rho); } else if (branchName.startsWith(name)) { partialMatch = nextNonMissing(node); partialMatchCount++; } } } if (partialMatchCount == 1) { return context.evaluate(partialMatch, rho); } else if (Iterables.size(branches) > 0) { PairList.Node last = Iterables.getLast(branches); if (!last.hasTag()) { return context.evaluate(last.getValue(), rho); } } } else if (expr instanceof AtomicVector) { int branchIndex = ((AtomicVector) expr).getElementAsInt(0); if (branchIndex >= 1 && branchIndex <= Iterables.size(branches)) { return context.evaluate(Iterables.get(branches, branchIndex - 1).getValue(), rho); } } // no match return Null.INSTANCE; }
From source file:com.madvay.tools.android.perf.common.TraceTransformers.java
public static TT pruneAbove(final Predicate<StackTraceElement> spec) { return new TT() { @Override/*from w w w. j a va 2 s.c om*/ public List<StackTraceElement> apply(List<StackTraceElement> input) { int matchIdx = Iterables.indexOf(input, spec); if (matchIdx == -1) { return Lists.newArrayList(); } return Lists.newArrayList(Iterables.skip(input, matchIdx)); } }; }
From source file:io.bazel.rules.closure.ClosureUberAlles.java
@Override public Integer apply(Iterable<String> args) { String head = Iterables.getFirst(args, ""); Iterable<String> tail = Iterables.skip(args, 1); // TODO(jart): Include Closure Templates and Stylesheets. switch (head) { case "JsChecker": return new JsChecker.Program().apply(tail); case "JsCompiler": return new JsCompiler().apply(tail); default://from w w w . j av a 2s . com System.err.println("\nERROR: First flag to ClosureUberAlles should be specific compiler to run, " + "e.g. JsChecker\n"); return 1; } }
From source file:org.apache.provisionr.amazon.core.ImageTable.java
/** * Load the list of AMIs from a resource file (csv format) * <p/>// w w w .j a v a2s . c om * Note: the parser is doing only split by comma. There is no * support for escaping line components * * @param resource path to resource * @return an instance of {@see ImageTable} * @throws IOException */ public static ImageTable fromCsvResource(String resource) throws IOException { checkNotNull(resource, "resource is null"); List<String> lines = Resources.readLines(Resources.getResource(ImageTable.class, resource), Charsets.UTF_8); checkArgument(!lines.isEmpty(), "the resource is an empty file"); final ImmutableTable.Builder<String, String, String> table = ImmutableTable.builder(); final Iterable<String> headers = extractHeaders(lines); int index = 0; for (String line : Iterables.skip(lines, 1)) { final Iterable<Table.Cell<String, String, String>> cells = combineHeadersWithLinePartsAsTableCells( index, headers, COMMA.split(line)); for (Table.Cell<String, String, String> cell : cells) { table.put(cell); } index++; } return new ImageTable(table.build()); }
From source file:see.util.Reduce.java
/** * Fold a sequence without an initial value. * * @param values sequence to fold/*from ww w . j a v a 2 s . c o m*/ * @param func reducing function * @param <T> input and result type * @return reduce result */ public static <T> T reduce(Iterable<? extends T> values, FoldFunction<? super T, T> func) { Preconditions.checkArgument(!Iterables.isEmpty(values), "Cannot reduce empty list"); return fold(Iterables.getFirst(values, null), Iterables.skip(values, 1), func); }
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); }/*from ww w. j a v a2 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(); }/*from w ww. ja va2 s .com*/ 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.dcache.sf.StageTask.java
private SfException throwError(List<String> lines) throws SfException { String error;//from ww w. jav a2s .c o m int errorCode; if (lines.isEmpty()) { errorCode = 1; error = "Sf ??? reported a stage failure without providing a reason."; } else { try { errorCode = Integer.parseInt(lines.get(0)); error = Joiner.on("\n").join(Iterables.skip(lines, 1)); } catch (NumberFormatException e) { errorCode = 1; error = Joiner.on("\n").join(lines); } } throw new SfException(errorCode, error); }