Example usage for com.google.common.collect ImmutableList builder

List of usage examples for com.google.common.collect ImmutableList builder

Introduction

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

Prototype

public static <E> Builder<E> builder() 

Source Link

Usage

From source file:io.github.bktlib.collect.CustomCollectors.java

public static <T> Collector<T, ImmutableList.Builder<T>, ImmutableList<T>> toImmutableList() {
    return new ImmutableListCollector<>();
}

From source file:org.prebake.html.TextBlock.java

static TextChunk make(List<TextChunk> chunks) {
    if (chunks.isEmpty()) {
        return new SimpleTextChunk("");
    }/*from w ww .jav  a2 s .c  o m*/
    if (chunks.size() == 1 && chunks.get(0).breaks()) {
        return chunks.get(0);
    }
    ImmutableList.Builder<TextChunk> parts = ImmutableList.builder();
    List<TextChunk> inlineParts = Lists.newArrayList();
    for (TextChunk c : chunks) {
        if (!c.breaks()) {
            inlineParts.add(c);
        } else {
            switch (inlineParts.size()) {
            case 0:
                break;
            case 1:
                parts.add(inlineParts.get(0));
                break;
            default:
                parts.add(InlineText.make(inlineParts));
                break;
            }
            inlineParts.clear();
            if (c instanceof TextBlock) {
                parts.addAll(((TextBlock) c).parts);
            } else {
                parts.add(c);
            }
        }
    }
    switch (inlineParts.size()) {
    case 0:
        break;
    case 1:
        parts.add(inlineParts.get(0));
        break;
    default:
        parts.add(InlineText.make(inlineParts));
        break;
    }
    return new TextBlock(parts.build());
}

From source file:de.flapdoodle.guava.Merger.java

public static <T> ImmutableList<T> merge(Iterable<? extends T> left, Iterable<? extends T> right,
        Equivalence<? super T> matcher, Foldleft<? super T, T> fold) {
    ImmutableList.Builder<T> builder = ImmutableList.builder();
    Iterable<? extends T> notMerged = right;
    for (T l : left) {
        Iterable<? extends T> matching = Iterables.filter(notMerged, matcher.equivalentTo(l));
        notMerged = Iterables.filter(notMerged, Predicates.not(matcher.equivalentTo(l)));

        boolean noMatching = true;
        for (T r : matching) {
            builder.add(fold.apply(l, r));
            noMatching = false;// w w  w  .  j a  va  2 s .c  o  m
        }
        if (noMatching) {
            builder.add(l);
        }
    }
    builder.addAll(notMerged);
    return builder.build();
}

From source file:com.facebook.presto.execution.buffer.PageSplitterUtil.java

public static List<Page> splitPage(Page page, long maxPageSizeInBytes) {
    checkArgument(page.getPositionCount() > 0, "page is empty");
    checkArgument(maxPageSizeInBytes > 0, "maxPageSizeInBytes must be > 0");

    if (page.getSizeInBytes() <= maxPageSizeInBytes || page.getPositionCount() == 1) {
        return ImmutableList.of(page);
    }/*from  w ww .  jav a2 s  .c  o m*/

    ImmutableList.Builder<Page> outputPages = ImmutableList.builder();
    int positionCount = page.getPositionCount();
    int half = positionCount / 2;

    Page splitPage1 = page.getRegion(0, half);
    outputPages.addAll(splitPage(splitPage1, maxPageSizeInBytes));

    Page splitPage2 = page.getRegion(half, positionCount - half);
    outputPages.addAll(splitPage(splitPage2, maxPageSizeInBytes));

    return outputPages.build();
}

From source file:com.facebook.presto.sql.planner.SchedulingOrderVisitor.java

public static List<PlanNodeId> scheduleOrder(PlanNode root) {
    ImmutableList.Builder<PlanNodeId> schedulingOrder = ImmutableList.builder();
    root.accept(new Visitor(), schedulingOrder::add);
    return schedulingOrder.build();
}

From source file:org.sonar.plugins.gosu.jacoco.JaCoCoExtensions.java

public static List<Object> getExtensions() {
    ImmutableList.Builder<Object> extensions = ImmutableList.builder();

    extensions.addAll(JaCoCoConfiguration.getPropertyDefinitions());
    extensions.add(JaCoCoConfiguration.class,
            // Unit tests
            JaCoCoSensor.class,
            // Integration tests
            JaCoCoItSensor.class, JaCoCoOverallSensor.class);

    return extensions.build();
}

From source file:com.facebook.buck.android.resources.ChunkUtils.java

/**
 * Finds all chunks in the buffer with the requested type. This is useful for tests to find chunks
 * of a certain type without needing to understand all the other encountered chunks.
 *
 * @return A list of offsets in the buffer to chunks of the requested type.
 *///from   w  w  w  . ja  v a2s .  co m
static List<Integer> findChunks(ByteBuffer data, int wantedType) {
    ByteBuffer buf = ResChunk.slice(data, 0);
    ImmutableList.Builder<Integer> offsetsBuilder = ImmutableList.builder();
    int offset = 0;
    while (offset < buf.limit()) {
        int type = buf.getShort(offset);
        if (type == wantedType) {
            offsetsBuilder.add(offset);
        }
        int headerSize = buf.getShort(offset + 2);
        int chunkSize = buf.getInt(offset + 4);
        // These chunks consist of lists of sub-chunks after their headers.
        if (type == ResChunk.CHUNK_RESOURCE_TABLE || type == ResChunk.CHUNK_RES_TABLE_PACKAGE
                || type == ResChunk.CHUNK_XML_TREE) {
            int subchunksStart = offset + headerSize;
            int subchunksLength = chunkSize - headerSize;
            for (int subOffset : findChunks(ResChunk.slice(buf, subchunksStart, subchunksLength), wantedType)) {
                offsetsBuilder.add(subchunksStart + subOffset);
            }
        }
        offset += chunkSize;
    }
    return offsetsBuilder.build();
}

From source file:net.minecraftforge.fml.common.CertificateHelper.java

public static ImmutableList<String> getFingerprints(Certificate[] certificates) {
    int len = 0;/*ww  w . j a v  a  2  s  .c  om*/
    if (certificates != null) {
        len = certificates.length;
    }
    ImmutableList.Builder<String> certBuilder = ImmutableList.builder();
    for (int i = 0; i < len; i++) {
        certBuilder.add(CertificateHelper.getFingerprint(certificates[i]));
    }
    return certBuilder.build();
}

From source file:org.attribyte.api.http.NamedValues.java

/**
 * Copies values from an array to an immutable list.
 * Empty or <code>null</code> values are ignored.
 * @param values The input values.//w  ww .j  a  v a  2  s . c o m
 * @return The internal values.
 */
static final ImmutableList<String> copyValues(final String[] values) {
    if (values == null || values.length == 0) {
        return ImmutableList.of();
    } else {
        ImmutableList.Builder<String> builder = ImmutableList.builder();
        for (final String value : values) {
            if (!Strings.isNullOrEmpty(value)) {
                builder.add(value);
            }
        }
        return builder.build();
    }
}

From source file:com.proofpoint.reporting.HealthBean.java

public static HealthBean forTarget(Object target) {
    requireNonNull(target, "target is null");

    ImmutableList.Builder<HealthBeanAttribute> attributes = ImmutableList.builder();

    for (Map.Entry<Method, Method> entry : AnnotationUtils.findAnnotatedMethods(target.getClass(),
            HealthCheck.class, HealthCheckRemoveFromRotation.class, HealthCheckRestartDesired.class)
            .entrySet()) {// w w  w  .  j a va 2 s.c o m
        Method concreteMethod = entry.getKey();
        Method annotatedMethod = entry.getValue();

        if (!isValidGetter(concreteMethod)) {
            throw new RuntimeException(
                    "healthcheck annotation on non-getter " + annotatedMethod.toGenericString());
        }

        attributes.addAll(new HealthBeanAttributeBuilder().onInstance(target).withConcreteGetter(concreteMethod)
                .withAnnotatedGetter(annotatedMethod).build());
    }

    for (Field field : AnnotationUtils.findAnnotatedFields(target.getClass(), HealthCheck.class,
            HealthCheckRemoveFromRotation.class, HealthCheckRestartDesired.class)) {
        if (!AtomicReference.class.isAssignableFrom(field.getType())) {
            throw new RuntimeException(
                    "healthcheck annotation on non-AtomicReference field " + field.toGenericString());
        }

        attributes.addAll(new HealthBeanAttributeBuilder().onInstance(target).withField(field).build());
    }

    return new AutoValue_HealthBean(attributes.build());
}