Example usage for com.google.common.collect ImmutableList.Builder add

List of usage examples for com.google.common.collect ImmutableList.Builder add

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableList.Builder add.

Prototype

boolean add(E e);

Source Link

Document

Appends the specified element to the end of this list (optional operation).

Usage

From source file:com.publictransitanalytics.scoregenerator.schedule.IntervalOfDay.java

public static List<IntervalOfDay> getIntervals(final LocalDateTime earliestTime,
        final LocalDateTime latestTime) {
    final ImmutableList.Builder<IntervalOfDay> intervals = ImmutableList.builder();

    if (earliestTime.toLocalDate().equals(latestTime.toLocalDate())) {
        intervals.add(new IntervalOfDay(earliestTime.toLocalDate(), earliestTime.toLocalTime(),
                latestTime.toLocalTime()));
    } else {//from   ww w  . ja v  a 2s . c  o m
        intervals.add(new IntervalOfDay(earliestTime.toLocalDate(), earliestTime.toLocalTime(), LocalTime.MAX));
        LocalDate date = earliestTime.toLocalDate().plusDays(1);
        while (date.isBefore(latestTime.toLocalDate())) {
            intervals.add(new IntervalOfDay(date, LocalTime.MIN, LocalTime.MAX));
            date = date.plusDays(1);
        }
        intervals.add(new IntervalOfDay(latestTime.toLocalDate(), LocalTime.MIN, latestTime.toLocalTime()));
    }
    return intervals.build();
}

From source file:com.google.devtools.build.lib.skyframe.ConfiguredTargetValue.java

static ImmutableList<SkyKey> keys(Iterable<ConfiguredTargetKey> lacs) {
    ImmutableList.Builder<SkyKey> keys = ImmutableList.builder();
    for (ConfiguredTargetKey lac : lacs) {
        keys.add(key(lac));
    }/*from w  ww .  j a v a  2 s  .c om*/
    return keys.build();
}

From source file:com.squareup.wire.schema.EnumConstant.java

static ImmutableList<EnumConstantElement> toElements(ImmutableList<EnumConstant> constants) {
    ImmutableList.Builder<EnumConstantElement> elements = new ImmutableList.Builder<>();
    for (EnumConstant constant : constants) {
        elements.add(constant.toElement());
    }//from  ww w . j  a va 2 s . c om
    return elements.build();
}

From source file:io.prestosql.execution.StageInfo.java

private static void addAllStages(Optional<StageInfo> stageInfo, ImmutableList.Builder<StageInfo> collector) {
    stageInfo.ifPresent(stage -> {/*from   ww  w  . j  a v a  2 s  .co m*/
        collector.add(stage);
        stage.getSubStages().stream()
                .forEach(subStage -> addAllStages(Optional.ofNullable(subStage), collector));
    });
}

From source file:io.github.karols.hocr4j.utils.CollectionUtils.java

/**
 * Creates a new immutable list with an element added to the end.
 * @param list original list/*from  w w w  .ja  va2  s. c  om*/
 * @param elem element to add
 * @param <T> element type
 * @return list with added element
 */
@Nonnull
public static <T> ImmutableList<T> pushBack(@Nonnull Iterable<T> list, T elem) {
    ImmutableList.Builder<T> b = ImmutableList.builder();
    b.addAll(list);
    b.add(elem);
    return b.build();
}

From source file:com.squareup.wire.schema.Rpc.java

static ImmutableList<Rpc> fromElements(ImmutableList<RpcElement> elements) {
    ImmutableList.Builder<Rpc> rpcs = new ImmutableList.Builder<>();
    for (RpcElement rpcElement : elements) {
        rpcs.add(new Rpc(rpcElement.location(), rpcElement.name(), rpcElement.documentation(),
                rpcElement.requestType(), rpcElement.responseType(),
                new Options(Options.METHOD_OPTIONS, rpcElement.options())));
    }/*from ww w .  j  ava 2s. c om*/
    return rpcs.build();
}

From source file:io.prometheus.client.metrics.histogram.buckets.Distributions.java

public static List<Float> equallySizedBucketsFor(final float lower, final float upper, final int count) {
    final ImmutableList.Builder<Float> builder = ImmutableList.builder();

    final float partitionSize = (upper - lower) / count;

    for (int i = 0; i < count; i++) {
        builder.add(lower + ((float) i * partitionSize));
    }//w ww  .j  a v a2 s  .c  om

    return builder.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 a2 s .  c  o m
    return iterators.build();
}

From source file:org.prebake.channel.Commands.java

public static Commands fromJson(Path clientRoot, JsonSource src, @Nullable OutputStream response)
        throws IOException {
    ImmutableList.Builder<Command> cmds = ImmutableList.builder();
    src.expect("[");
    if (!src.check("]")) {
        do {//from w  ww . j a v  a 2s .c  om
            cmds.add(Command.fromJson(src, clientRoot));
        } while (src.check(","));
        src.expect("]");
    }
    return new Commands(cmds.build(), response);
}

From source file:com.b2international.snowowl.snomed.datastore.request.SnomedBulkRequest.java

private static void collectNestedRequests(Request<?, ?> root,
        ImmutableList.Builder<SnomedComponentRequest<?>> requests,
        ImmutableList.Builder<DeleteRequest> deletions) {
    if (root instanceof DeleteRequest) {
        deletions.add((DeleteRequest) root);
    } else if (root instanceof SnomedComponentRequest<?>) {
        requests.add((SnomedComponentRequest<?>) root);
    } else if (root instanceof DelegatingRequest<?, ?, ?>) {
        collectNestedRequests(((DelegatingRequest<?, ?, ?>) root).next(), requests, deletions);
    } else if (root instanceof BulkRequest<?>) {
        ((BulkRequest<?>) root).getRequests().forEach(req -> {
            collectNestedRequests(req, requests, deletions);
        });/*from  w ww . j a  v  a  2 s .com*/
    }
}