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.google.template.soy.incrementaldomsrc.RemoveUnnecessaryEscapingDirectives.java

private static ImmutableList<SoyPrintDirective> filterEscapingDirectives(
        ImmutableList<SoyPrintDirective> escapingDirectives) {
    for (int i = 0; i < escapingDirectives.size(); i++) {
        SoyPrintDirective directive = escapingDirectives.get(i);
        if (canSkip(directive)) {
            ImmutableList.Builder<SoyPrintDirective> builder = ImmutableList.builder();
            builder.addAll(escapingDirectives.subList(0, i));
            for (; i < escapingDirectives.size(); i++) {
                directive = escapingDirectives.get(i);
                if (!canSkip(directive)) {
                    builder.add(directive);
                }/*from  www  .j  ava  2  s.  c  om*/
            }
            return builder.build();
        }
    }
    return escapingDirectives;
}

From source file:com.github.rinde.logistics.pdptw.solver.CheapestInsertionHeuristic.java

static <T> ImmutableList<ImmutableList<T>> modifySchedule(ImmutableList<ImmutableList<T>> originalSchedule,
        ImmutableList<T> vehicleSchedule, int vehicleIndex) {
    checkArgument(vehicleIndex >= 0 && vehicleIndex < originalSchedule.size(),
            "Vehicle index must be >= 0 && < %s, it is %s.", originalSchedule.size(), vehicleIndex);
    final ImmutableList.Builder<ImmutableList<T>> builder = ImmutableList.builder();
    builder.addAll(originalSchedule.subList(0, vehicleIndex));
    builder.add(vehicleSchedule);//from   ww w .j a v  a2  s. co m
    builder.addAll(originalSchedule.subList(vehicleIndex + 1, originalSchedule.size()));
    return builder.build();
}

From source file:com.google.devtools.build.lib.rules.AliasProvider.java

public static AliasProvider fromAliasRule(Label label, ConfiguredTarget actual) {
    ImmutableList.Builder<Label> chain = ImmutableList.builder();
    chain.add(label);//from   www. j  a  va  2s  .c o m
    AliasProvider dep = actual.getProvider(AliasProvider.class);
    if (dep != null) {
        chain.addAll(dep.getAliasChain());
    }

    return new AliasProvider(chain.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  w  w .  j a  va2 s .co  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.spotify.heroic.aggregation.Aggregations.java

private static List<Aggregation> flattenChain(final Iterable<Aggregation> chain) {
    final ImmutableList.Builder<Aggregation> c = ImmutableList.builder();

    for (final Aggregation a : chain) {
        if (a instanceof Chain) {
            c.addAll(flattenChain(Chain.class.cast(a).getChain()));
        } else {//from   ww  w . ja v a 2  s.  c  o  m
            c.add(a);
        }
    }

    return c.build();
}

From source file:com.google.idea.blaze.base.run.testlogs.BlazeTestXmlFinderStrategy.java

/**
 * Attempt to find all output test XML files associated with the given run configuration. Called
 * after the 'blaze test' process completes.
 *//*  w  ww. j a  v a  2s .c  o  m*/
static ImmutableList<CompletedTestTarget> locateTestXmlFiles(Project project) {
    BuildSystem buildSystem = Blaze.getBuildSystem(project);
    ImmutableList.Builder<CompletedTestTarget> output = ImmutableList.builder();
    for (BlazeTestXmlFinderStrategy strategy : EP_NAME.getExtensions()) {
        if (strategy.handlesBuildSystem(buildSystem)) {
            output.addAll(strategy.findTestXmlFiles(project));
        }
    }
    return output.build();
}

From source file:org.apache.drill.exec.util.TSI.java

public static List<String> getAllNames() {
    ImmutableList.Builder<String> builder = ImmutableList.builder();
    for (TSI interval : TSI.values()) {
        builder.addAll(interval.names);
    }/*www.  ja v a 2  s  .  c om*/
    return builder.build();
}

From source file:org.jclouds.cleanup.DomainObjectDocletCleaner.java

private static List<File> listFiles(File file) throws IOException {
    ImmutableList.Builder<File> newOnes = ImmutableList.builder();
    if (file.isDirectory()) {
        newOnes.addAll(listFiles(file, new ArrayList<File>()));
    } else if (file.getName().endsWith(".java")) {
        newOnes.add(file);/*w  w w .  j  a v a  2s .  c om*/
    }
    return newOnes.build();
}

From source file:com.facebook.buck.cli.exceptions.handlers.ExceptionHandlerRegistryFactory.java

/** @return a new ExceptionHandlerRegistry with the default handlers */
public static ExceptionHandlerRegistry<ExitCode> create() {
    ImmutableList.Builder<ExceptionHandler<? extends Throwable, ExitCode>> handlerListBuilder = ImmutableList
            .builder();// w  ww. j av  a 2 s. c o  m

    handlerListBuilder.addAll(
            Arrays.asList(new ExceptionHandler<InterruptedException, ExitCode>(InterruptedException.class) {
                @Override
                public ExitCode handleException(InterruptedException e) {
                    return ExitCode.SIGNAL_INTERRUPT;
                }
            }, new ExceptionHandler<ClosedByInterruptException, ExitCode>(ClosedByInterruptException.class) {
                @Override
                public ExitCode handleException(ClosedByInterruptException e) {
                    return ExitCode.SIGNAL_INTERRUPT;
                }
            }, new ExceptionHandler<IOException, ExitCode>(IOException.class) {
                @Override
                public ExitCode handleException(IOException e) {
                    if (e instanceof FileSystemLoopException) {
                        return ExitCode.FATAL_GENERIC;
                    } else if (e.getMessage() != null && e.getMessage().startsWith("No space left on device")) {
                        return ExitCode.FATAL_DISK_FULL;
                    } else {
                        return ExitCode.FATAL_IO;
                    }
                }
            }, new ExceptionHandler<OutOfMemoryError, ExitCode>(OutOfMemoryError.class) {
                @Override
                public ExitCode handleException(OutOfMemoryError e) {
                    return ExitCode.FATAL_OOM;
                }
            }, new ExceptionHandler<BuildFileParseException, ExitCode>(BuildFileParseException.class) {
                @Override
                public ExitCode handleException(BuildFileParseException e) {
                    return ExitCode.PARSE_ERROR;
                }
            }, new ExceptionHandler<CommandLineException, ExitCode>(CommandLineException.class) {
                @Override
                public ExitCode handleException(CommandLineException e) {
                    return ExitCode.COMMANDLINE_ERROR;
                }
            }, new ExceptionHandler<HumanReadableException, ExitCode>(HumanReadableException.class) {
                @Override
                public ExitCode handleException(HumanReadableException e) {
                    return ExitCode.BUILD_ERROR;
                }
            }, new ExceptionHandler<BuckIsDyingException, ExitCode>(BuckIsDyingException.class) {
                @Override
                public ExitCode handleException(BuckIsDyingException e) {
                    return ExitCode.FATAL_GENERIC;
                }
            }));
    return new ExceptionHandlerRegistry<>(handlerListBuilder.build(),
            new ExceptionHandler<Throwable, ExitCode>(Throwable.class) {
                @Override
                public ExitCode handleException(Throwable t) {
                    return ExitCode.FATAL_GENERIC;
                }
            });
}

From source file:cuchaz.m3l.event.handler.ListenerNodeList.java

private synchronized static void addToTracker(ListenerNodeList inst) {
    ImmutableList.Builder<ListenerNodeList> builder = ImmutableList.builder();
    builder.addAll(listTracker);
    builder.add(inst);/*w w  w  .j av a2  s  . co  m*/
    listTracker = builder.build();
}