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:edu.cmu.lti.oaqa.baseqa.answer.CavUtil.java

public static List<Token> getPath(Token src, Token dst) {
    if (src == null || dst == null) {
        return null;
    }//from w  ww  .ja va2  s.  co m
    List<Token> srcPathFromRoot = Lists.reverse(getPathToRoot(src));
    List<Token> dstPathFromRoot = Lists.reverse(getPathToRoot(dst));
    int commonLen = Math.min(srcPathFromRoot.size(), dstPathFromRoot.size());
    int firstDiffIndex = IntStream.range(0, commonLen)
            .filter(i -> !srcPathFromRoot.get(i).equals(dstPathFromRoot.get(i))).findFirst().orElse(commonLen);
    // different root: src and dst may be from different sentences
    if (firstDiffIndex == 0) {
        return null;
    }
    ImmutableList.Builder<Token> builder = ImmutableList.builder();
    builder.addAll(Lists.reverse(srcPathFromRoot.subList(firstDiffIndex, srcPathFromRoot.size())));
    builder.add(srcPathFromRoot.get(firstDiffIndex - 1));
    builder.addAll(dstPathFromRoot.subList(firstDiffIndex, dstPathFromRoot.size()));
    return builder.build();
}

From source file:com.google.devtools.build.java.turbine.TurbineOptionsParser.java

private static ImmutableList<String> splitClasspath(Iterable<String> paths) {
    ImmutableList.Builder<String> classpath = ImmutableList.builder();
    for (String path : paths) {
        classpath.addAll(CLASSPATH_SPLITTER.split(path));
    }/*from   w  w w  .  jav a  2 s .com*/
    return classpath.build();
}

From source file:com.spotify.heroic.suggest.WriteSuggest.java

public static Collector<WriteSuggest, WriteSuggest> reduce() {
    return requests -> {
        final ImmutableList.Builder<RequestError> errors = ImmutableList.builder();
        final ImmutableList.Builder<Long> times = ImmutableList.builder();

        for (final WriteSuggest r : requests) {
            errors.addAll(r.getErrors());
            times.addAll(r.getTimes());//  w  w w.jav a2s .c  o  m
        }

        return new WriteSuggest(errors.build(), times.build(), ImmutableList.of());
    };
}

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

/**
 * Combine, in order, several {@link NativeLinkableInput} objects into a single one.
 *///w ww.ja v a 2 s  .  c  om
public static NativeLinkableInput concat(Iterable<NativeLinkableInput> items) {
    ImmutableList.Builder<SourcePath> inputs = ImmutableList.builder();
    ImmutableList.Builder<String> args = ImmutableList.builder();

    for (NativeLinkableInput item : items) {
        inputs.addAll(item.getInputs());
        args.addAll(item.getArgs());
    }

    return new NativeLinkableInput(inputs.build(), args.build());
}

From source file:com.netflix.metacat.common.server.connectors.ConnectorUtils.java

/**
 * If the user desires pagination this method will take the list and break it up into the correct chunk. If not it
 * will return the whole list./*from  w w w.  j  ava2  s  . com*/
 *
 * @param <T>      The type of elements to paginate
 * @param elements The elements to paginate
 * @param pageable The pagination parameters or null if no pagination required
 * @return The final list of qualified names
 */
public static <T> List<T> paginate(final List<T> elements, @Nullable final Pageable pageable) {
    final ImmutableList.Builder<T> results = ImmutableList.builder();
    if (pageable != null && pageable.isPageable()) {
        results.addAll(elements.stream().skip(pageable.getOffset()).limit(pageable.getLimit())
                .collect(Collectors.toList()));
    } else {
        results.addAll(elements);
    }

    return results.build();
}

From source file:com.google.devtools.build.lib.syntax.SelectorList.java

private static Class<?> addValue(Object value, ImmutableList.Builder<Object> builder) {
    if (value instanceof SelectorList) {
        SelectorList selectorList = (SelectorList) value;
        builder.addAll(selectorList.getElements());
        return selectorList.getType();
    } else if (value instanceof SelectorValue) {
        builder.add(value);//from w ww  . ja v a  2  s.  com
        return ((SelectorValue) value).getType();
    } else {
        builder.add(value);
        return value.getClass();
    }
}

From source file:com.spotify.heroic.metric.WriteMetric.java

public static Collector<WriteMetric, WriteMetric> reduce() {
    return results -> {
        final ImmutableList.Builder<RequestError> errors = ImmutableList.builder();
        final ImmutableList.Builder<Long> times = ImmutableList.builder();

        for (final WriteMetric r : results) {
            errors.addAll(r.getErrors());
            times.addAll(r.getTimes());//from   w  ww .ja va2  s  .c  om
        }

        return new WriteMetric(errors.build(), times.build());
    };
}

From source file:com.spotify.heroic.metadata.WriteMetadata.java

public static Collector<WriteMetadata, WriteMetadata> reduce() {
    return requests -> {
        final ImmutableList.Builder<RequestError> errors = ImmutableList.builder();
        final ImmutableList.Builder<Long> times = ImmutableList.builder();

        for (final WriteMetadata r : requests) {
            errors.addAll(r.getErrors());
            times.addAll(r.getTimes());/*from  ww  w. j ava  2  s  .  c om*/
        }

        return new WriteMetadata(errors.build(), times.build());
    };
}

From source file:com.google.template.soy.jssrc.dsl.SoyJsPluginUtils.java

/**
 * Applies the given print directive to {@code expr} and returns the result.
 *
 * @param generator The CodeChunk generator to use.
 * @param expr The expression to apply the print directive to.
 * @param directive The print directive to apply.
 * @param args Print directive args, if any.
 *///from  w w w  . j  ava 2 s  . co  m
public static CodeChunk.WithValue applyDirective(CodeChunk.Generator generator, CodeChunk.WithValue expr,
        SoyJsSrcPrintDirective directive, List<CodeChunk.WithValue> args) {
    List<JsExpr> argExprs = Lists.transform(args, TO_JS_EXPR);
    JsExpr applied = directive.applyForJsSrc(expr.singleExprOrName(), argExprs);
    RequiresCollector.IntoImmutableSet collector = new RequiresCollector.IntoImmutableSet();
    expr.collectRequires(collector);
    for (CodeChunk.WithValue arg : args) {
        arg.collectRequires(collector);
    }
    if (directive instanceof SoyLibraryAssistedJsSrcPrintDirective) {
        for (String name : ((SoyLibraryAssistedJsSrcPrintDirective) directive).getRequiredJsLibNames()) {
            collector.add(GoogRequire.create(name));
        }
    }

    ImmutableList.Builder<CodeChunk> initialStatements = ImmutableList.<CodeChunk>builder()
            .addAll(expr.initialStatements());
    for (CodeChunk.WithValue arg : args) {
        initialStatements.addAll(arg.initialStatements());
    }
    return fromExpr(applied, collector.get()).withInitialStatements(initialStatements.build());
}

From source file:org.spongepowered.common.data.property.SpongePropertyRegistry.java

@SuppressWarnings({ "unchecked", "rawtypes" })
public static void completeRegistration() {
    allowRegistrations = false;//w w  w  . jav  a 2  s.c  o m
    final SpongePropertyRegistry registry = getInstance();
    for (Map.Entry<Class<? extends Property<?, ?>>, List<PropertyStore<?>>> entry : registry.propertyStoreMap
            .entrySet()) {
        ImmutableList.Builder<PropertyStore<?>> propertyStoreBuilder = ImmutableList.builder();
        Collections.sort(entry.getValue(), ComparatorUtil.PROPERTY_STORE_COMPARATOR);
        propertyStoreBuilder.addAll(entry.getValue());
        final PropertyStoreDelegate<?> delegate = new PropertyStoreDelegate(propertyStoreBuilder.build());
        registry.delegateMap.put(entry.getKey(), delegate);
    }
    registry.propertyStoreMap.clear();
}