List of usage examples for com.google.common.collect ImmutableList builder
public static <E> Builder<E> builder()
From source file:com.facebook.buck.graph.TopologicalSort.java
public static <T> ImmutableList<T> sort(TraversableGraph<T> graph, final Predicate<T> inclusionPredicate) { AbstractBottomUpTraversal<T, ImmutableList<T>> traversal = new AbstractBottomUpTraversal<T, ImmutableList<T>>( graph) {/* w ww . j a v a 2 s. co m*/ final ImmutableList.Builder<T> builder = ImmutableList.builder(); @Override public void visit(T node) { if (inclusionPredicate.apply(node)) { builder.add(node); } } @Override public ImmutableList<T> getResult() { return builder.build(); } }; traversal.traverse(); return traversal.getResult(); }
From source file:co.cask.cdap.metrics.query.TimeSeriesResponse.java
public static Builder builder(final long start, final long end) { final ImmutableList.Builder<TimeValue> timeValues = ImmutableList.builder(); return new Builder() { @Override/*from w w w. ja v a2 s . c o m*/ public Builder addData(long timestamp, long value) { timeValues.add(new TimeValue(timestamp, value)); return this; } @Override public TimeSeriesResponse build() { return new TimeSeriesResponse(start, end, timeValues.build()); } }; }
From source file:com.facebook.buck.util.MoreIterables.java
private static <T> ImmutableList<Iterator<T>> iterators(Iterable<T> inputs[]) { ImmutableList.Builder<Iterator<T>> iterators = ImmutableList.builder(); for (Iterable<T> input : inputs) { iterators.add(input.iterator()); }/*from w w w . j a v a 2 s . co m*/ return iterators.build(); }
From source file:io.crate.core.collections.Collectors.java
public static <T> Collector<T, ImmutableList.Builder<T>, ImmutableList<T>> toImmutableList() { return Collector.of(ImmutableList.Builder::new, ImmutableList.Builder::add, (b1, b2) -> b1.addAll(b2.build()), ImmutableList.Builder::build); }
From source file:com.facebook.buck.cxx.elf.ElfDynamicSection.java
public static ElfDynamicSection parse(ElfHeader.EIClass eiClass, ByteBuffer buffer) { ImmutableList.Builder<Entry> entries = ImmutableList.builder(); while (buffer.hasRemaining()) { entries.add(Entry.parse(eiClass, buffer)); }/*from w ww .j a v a 2s. c o m*/ return new ElfDynamicSection(entries.build()); }
From source file:com.google.devtools.build.lib.skyframe.CycleUtils.java
static <S> Pair<ImmutableList<S>, ImmutableList<S>> splitIntoPathAndChain(Predicate<S> startOfCycle, Iterable<S> pathAndCycle) { boolean inPathToCycle = true; ImmutableList.Builder<S> pathToCycleBuilder = ImmutableList.builder(); ImmutableList.Builder<S> cycleBuilder = ImmutableList.builder(); for (S elt : pathAndCycle) { if (startOfCycle.apply(elt)) { inPathToCycle = false;/*from ww w . j av a2 s . c om*/ } if (inPathToCycle) { pathToCycleBuilder.add(elt); } else { cycleBuilder.add(elt); } } return Pair.of(pathToCycleBuilder.build(), cycleBuilder.build()); }
From source file:org.retrostore.util.DropdownValueForClient.java
public static List<DropdownValueForClient> from(Enum[] enums) { ImmutableList.Builder<DropdownValueForClient> builder = ImmutableList.builder(); for (Enum e : enums) { builder.add(from(e));//from ww w .j a va2 s. c o m } return builder.build(); }
From source file:com.spectralogic.ds3autogen.utils.collections.GuavaCollectors.java
/** Collect a stream of elements into an {@link ImmutableList}. */ public static <T> Collector<T, ImmutableList.Builder<T>, ImmutableList<T>> immutableList() { return Collector.of(ImmutableList.Builder::new, ImmutableList.Builder::add, (l, r) -> l.addAll(r.build()), ImmutableList.Builder<T>::build); }
From source file:org.prebake.html.InlineText.java
static TextChunk make(List<TextChunk> chunks) { if (chunks.isEmpty()) { return new SimpleTextChunk(""); }//from w w w . java 2 s.c o m if (chunks.size() == 1 && !chunks.get(0).breaks()) { return chunks.get(0); } ImmutableList.Builder<TextChunk> parts = ImmutableList.builder(); for (TextChunk c : chunks) { if (c instanceof InlineText) { parts.addAll(((InlineText) c).parts); } else { parts.add(c); } } return new InlineText(parts.build()); }
From source file:com.spotify.heroic.lifecycle.ManyLifeCycle.java
public static LifeCycle of(final Iterable<LifeCycle> many) { final ImmutableList.Builder<LifeCycle> flattened = ImmutableList.builder(); for (final LifeCycle l : many) { if (l.equals(LifeCycle.EMPTY)) { continue; }//from w ww. jav a2 s .c o m if (l instanceof ManyLifeCycle) { flattened.addAll(((ManyLifeCycle) l).lifeCycles); continue; } flattened.add(l); } return new ManyLifeCycle(flattened.build()); }