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

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

Introduction

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

Prototype

boolean addAll(Collection<? extends E> c);

Source Link

Document

Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator (optional operation).

Usage

From source file:com.facebook.presto.orc.writer.DecimalColumnWriter.java

private static List<Integer> createDecimalColumnPositionList(boolean compressed,
        DecimalStreamCheckpoint dataCheckpoint, LongStreamCheckpoint scaleCheckpoint,
        Optional<BooleanStreamCheckpoint> presentCheckpoint) {
    ImmutableList.Builder<Integer> positionList = ImmutableList.builder();
    presentCheckpoint.ifPresent(/*from  w w w.j a  va2  s . c  om*/
            booleanStreamCheckpoint -> positionList.addAll(booleanStreamCheckpoint.toPositionList(compressed)));
    positionList.addAll(dataCheckpoint.toPositionList(compressed));
    positionList.addAll(scaleCheckpoint.toPositionList(compressed));
    return positionList.build();
}

From source file:org.apache.curator.x.async.modeled.details.ZPathImpl.java

public static ZPath from(ZPath base, List<String> names) {
    names = Objects.requireNonNull(names, "names cannot be null");
    names.forEach(ZPathImpl::validate);//from  ww  w .  j  a v  a 2  s .  c  o m
    ImmutableList.Builder<String> builder = ImmutableList.builder();
    if (base != null) {
        if (base instanceof ZPathImpl) {
            builder.addAll(((ZPathImpl) base).nodes);
        } else {
            builder.addAll(Splitter.on(PATH_SEPARATOR).omitEmptyStrings().splitToList(base.fullPath()));
        }
    } else {
        builder.add(PATH_SEPARATOR);
    }
    List<String> nodes = builder.addAll(names).build();
    return new ZPathImpl(nodes, null);
}

From source file:com.facebook.buck.cxx.CxxSourceTypes.java

/**
 * @return the platform-specific compiler flags for the given {@link CxxPlatform}.
 *///from w  w  w .  ja  v a  2  s.c o  m
public static ImmutableList<String> getPlatformCompilerFlags(CxxPlatform cxxPlatform, CxxSource.Type type) {

    ImmutableList.Builder<String> flags = ImmutableList.builder();

    switch (type) {
    case ASSEMBLER:
        flags.addAll(cxxPlatform.getAsflags());
        break;
    case C_CPP_OUTPUT:
        flags.addAll(cxxPlatform.getCflags());
        break;
    case CXX_CPP_OUTPUT:
        flags.addAll(cxxPlatform.getCxxflags());
        break;
    case OBJC_CPP_OUTPUT:
        flags.addAll(cxxPlatform.getCflags());
        break;
    case OBJCXX_CPP_OUTPUT:
        flags.addAll(cxxPlatform.getCxxflags());
        break;
    case CUDA_CPP_OUTPUT:
        flags.addAll(cxxPlatform.getCudaflags());
        break;
    case ASM:
        flags.addAll(cxxPlatform.getAsmflags());
        break;
    // $CASES-OMITTED$
    default:
        throw new IllegalStateException(String.format("unexpected type: %s", type));
    }

    return flags.build();
}

From source file:com.spectralogic.ds3autogen.python.generators.request.BaseRequestGenerator.java

/**
 * Creates the list of non-optional query params assigned in the constructor
 *//*ww w  . jav  a  2s .  co  m*/
public static ImmutableList<QueryParam> toQueryParamList(final Operation operation,
        final ImmutableList<Ds3Param> requiredParams) {
    final ImmutableList.Builder<QueryParam> builder = ImmutableList.builder();
    if (operation != null) {
        builder.add(new OperationQueryParam(operation.toString().toLowerCase()));
    }
    builder.addAll(toRequiredQueryParamList(requiredParams));
    return builder.build();
}

From source file:com.spectralogic.ds3autogen.utils.Helper.java

/**
 * Creates a sorted comma separated list of response codes
 *///from  w  ww . ja  v  a  2  s.  co  m
public static String getResponseCodes(final ImmutableList<Ds3ResponseCode> responseCodes) {
    final List<String> sortable = new ArrayList<>();
    for (final Ds3ResponseCode responseCode : responseCodes) {
        sortable.add(Integer.toString(responseCode.getCode()));
    }
    Collections.sort(sortable);
    final ImmutableList.Builder<String> builder = ImmutableList.builder();
    builder.addAll(sortable);
    return builder.build().stream().map(i -> i).collect(Collectors.joining(", "));
}

From source file:com.spectralogic.ds3autogen.utils.Helper.java

/**
 * Sorts a list of Arguments by name.  Used for sorting constructor arguments for consistency.
 * @param arguments List of Arguments/*from  w w w .j  av  a  2  s.  c  o m*/
 * @return Sorted list of Arguments
 */
public static ImmutableList<Arguments> sortConstructorArgs(final ImmutableList<Arguments> arguments) {
    final List<Arguments> sortable = new ArrayList<>();
    sortable.addAll(arguments);
    Collections.sort(sortable, new CustomArgumentComparator());

    final ImmutableList.Builder<Arguments> builder = ImmutableList.builder();
    builder.addAll(sortable);
    return builder.build();
}

From source file:com.facebook.buck.cxx.CxxSourceTypes.java

/**
 * @return the platform-specific preprocessor flags for the given {@link CxxPlatform}.
 *//*from   ww w. ja v a  2  s.  c  o  m*/
public static ImmutableList<String> getPlatformPreprocessFlags(CxxPlatform cxxPlatform, CxxSource.Type type) {

    ImmutableList.Builder<String> flags = ImmutableList.builder();

    switch (type) {
    case ASSEMBLER_WITH_CPP:
        flags.addAll(cxxPlatform.getAsppflags());
        break;
    case C:
        flags.addAll(cxxPlatform.getCppflags());
        break;
    case CXX:
        flags.addAll(cxxPlatform.getCxxppflags());
        break;
    case OBJC:
        flags.addAll(cxxPlatform.getCppflags());
        break;
    case OBJCXX:
        flags.addAll(cxxPlatform.getCxxppflags());
        break;
    case CUDA:
        flags.addAll(cxxPlatform.getCudappflags());
        break;
    case ASM_WITH_CPP:
        flags.addAll(cxxPlatform.getAsmppflags());
        break;
    // $CASES-OMITTED$
    default:
        throw new IllegalStateException(String.format("unexpected type: %s", type));
    }

    return flags.build();
}

From source file:com.facebook.buck.go.GoDescriptors.java

@VisibleForTesting
static ImmutableMap<Path, Path> getPackageImportMap(ImmutableList<Path> globalVendorPaths, Path basePackagePath,
        Iterable<Path> packageNameIter) {
    Map<Path, Path> importMapBuilder = Maps.newHashMap();
    ImmutableSortedSet<Path> packageNames = ImmutableSortedSet.copyOf(packageNameIter);

    ImmutableList.Builder<Path> vendorPathsBuilder = ImmutableList.builder();
    vendorPathsBuilder.addAll(globalVendorPaths);
    Path prefix = Paths.get("");
    for (Path component : FluentIterable.of(new Path[] { Paths.get("") }).append(basePackagePath)) {
        prefix = prefix.resolve(component);
        vendorPathsBuilder.add(prefix.resolve("vendor"));
    }/*  www.jav  a 2 s  . c o  m*/

    for (Path vendorPrefix : vendorPathsBuilder.build()) {
        for (Path vendoredPackage : packageNames.tailSet(vendorPrefix)) {
            if (!vendoredPackage.startsWith(vendorPrefix)) {
                break;
            }

            importMapBuilder.put(MorePaths.relativize(vendorPrefix, vendoredPackage), vendoredPackage);
        }
    }

    return ImmutableMap.copyOf(importMapBuilder);
}

From source file:com.facebook.presto.operator.aggregation.builder.InMemoryHashAggregationBuilder.java

public static List<Type> toTypes(List<? extends Type> groupByType, Step step,
        List<AccumulatorFactory> factories, Optional<Integer> hashChannel) {
    ImmutableList.Builder<Type> types = ImmutableList.builder();
    types.addAll(groupByType);
    if (hashChannel.isPresent()) {
        types.add(BIGINT);// www.  j a v a  2  s .  c  o m
    }
    for (AccumulatorFactory factory : factories) {
        types.add(new Aggregator(factory, step, Optional.empty()).getType());
    }
    return types.build();
}

From source file:io.prestosql.plugin.raptor.legacy.storage.organization.ShardOrganizerUtil.java

public static Collection<Collection<ShardIndexInfo>> getShardsByDaysBuckets(Table tableInfo,
        Collection<ShardIndexInfo> shards, TemporalFunction temporalFunction) {
    if (shards.isEmpty()) {
        return ImmutableList.of();
    }//from  w  ww. ja  v  a2  s  .  c o m

    // Neither bucketed nor temporal, no partitioning required
    if (!tableInfo.getBucketCount().isPresent() && !tableInfo.getTemporalColumnId().isPresent()) {
        return ImmutableList.of(shards);
    }

    // if only bucketed, partition by bucket number
    if (tableInfo.getBucketCount().isPresent() && !tableInfo.getTemporalColumnId().isPresent()) {
        return Multimaps.index(shards, shard -> shard.getBucketNumber().getAsInt()).asMap().values();
    }

    // if temporal, partition into days first
    ImmutableMultimap.Builder<Long, ShardIndexInfo> shardsByDaysBuilder = ImmutableMultimap.builder();
    shards.stream().filter(shard -> shard.getTemporalRange().isPresent()).forEach(shard -> {
        long day = temporalFunction.getDayFromRange(shard.getTemporalRange().get());
        shardsByDaysBuilder.put(day, shard);
    });

    Collection<Collection<ShardIndexInfo>> byDays = shardsByDaysBuilder.build().asMap().values();

    // if table is bucketed further partition by bucket number
    if (!tableInfo.getBucketCount().isPresent()) {
        return byDays;
    }

    ImmutableList.Builder<Collection<ShardIndexInfo>> sets = ImmutableList.builder();
    for (Collection<ShardIndexInfo> s : byDays) {
        sets.addAll(Multimaps.index(s, ShardIndexInfo::getBucketNumber).asMap().values());
    }
    return sets.build();
}