List of usage examples for com.google.common.collect ImmutableList builder
public static <E> Builder<E> builder()
From source file:com.opengamma.integration.regression.ServerProcess.java
/** * Creates a new process that runs {@link OpenGammaComponentServer}. * @param workingDir The working directory for the process * @param classpath The classpath argument for the process * @param configFile The location of the server configuration file * @param propertyOverrides Properties to override values in the configuration * @param logbackConfig Property to set the logback configuration * @return The process/*from ww w . ja v a2s .c o m*/ */ public static ServerProcess start(String workingDir, String classpath, String configFile, Properties propertyOverrides, String logbackConfig) { ImmutableList.Builder<String> commandBuilder = ImmutableList.builder(); commandBuilder.add("java", logbackConfig, "-cp", classpath, "-Xmx2g", "-XX:MaxPermSize=256M", "com.opengamma.component.OpenGammaComponentServer", configFile); // can override properties in the config on the command line with prop1=value1 prop2=value2 ... for (Map.Entry<Object, Object> entry : propertyOverrides.entrySet()) { commandBuilder.add(entry.getKey() + "=" + entry.getValue()); } ProcessBuilder processBuilder = new ProcessBuilder(commandBuilder.build()).directory(new File(workingDir)); Process process; try { process = processBuilder.start(); } catch (IOException e) { throw new OpenGammaRuntimeException("Failed to start server process", e); } BlockingQueue<Boolean> startupQueue = new ArrayBlockingQueue<>(1); consumeStream(process.getInputStream(), OpenGammaComponentServer.STARTUP_COMPLETE_MESSAGE, startupQueue, true, System.out); consumeStream(process.getErrorStream(), OpenGammaComponentServer.STARTUP_FAILED_MESSAGE, startupQueue, false, System.err); Boolean startupSuccess; try { // TODO timeout mechanism in case the server dies and doesn't log correctly. timer task that interrupts this thread? startupSuccess = startupQueue.take(); } catch (InterruptedException e) { // not going to happen throw new OpenGammaRuntimeException("unexpected exception", e); } if (!startupSuccess) { throw new OpenGammaRuntimeException("startup failed, aborting"); } return new ServerProcess(process); }
From source file:com.facebook.presto.block.uncompressed.UncompressedTupleInfoSerde.java
public static TupleInfo deserialize(SliceInput sliceInput) { checkNotNull(sliceInput, "slice is null"); int fieldCount = sliceInput.readUnsignedByte(); ImmutableList.Builder<TupleInfo.Type> builder = ImmutableList.builder(); for (int i = 0; i < fieldCount; i++) { builder.add(TupleInfo.Type.values()[sliceInput.readUnsignedByte()]); }//w w w . j av a 2 s . c o m return new TupleInfo(builder.build()); }
From source file:net.maciekmm.personalTaxi.DestinationManagement.java
public static DestinationManagement fromConfig(ConfigurationSection section) { World world = Bukkit.getWorld(section.getString("world")); if (world == null) { throw new IllegalArgumentException( String.format("World %s is not available.", section.getString("world"))); }// ww w. j av a2 s . c o m List<Map<?, ?>> destinations = section.getMapList("destinations"); ImmutableList.Builder<DestinationEntry> builder = new ImmutableList.Builder<>(); for (Map<?, ?> destination : destinations) { builder.add(DestinationEntry.fromConfig(world, new MemoryConfiguration().createSection("temporary", destination))); } return new DestinationManagement(world, builder.build()); }
From source file:com.android.build.gradle.internal2.transforms.TransformInputUtil.java
private static Collection<File> getAllFiles(Collection<TransformInput> transformInputs, boolean includeDirectoryInput, boolean includeJarInput) { ImmutableList.Builder<File> inputFiles = ImmutableList.builder(); for (TransformInput input : transformInputs) { if (includeDirectoryInput) { for (DirectoryInput directoryInput : input.getDirectoryInputs()) { inputFiles.add(directoryInput.getFile()); }//from ww w. j a va2s . c om } if (includeJarInput) { for (JarInput jarInput : input.getJarInputs()) { inputFiles.add(jarInput.getFile()); } } } return inputFiles.build(); }
From source file:com.outerspacecat.cassandra.Cassandra.java
/** * Creates a list of mutations based on {@code columns}. * //ww w.j av a 2s . c om * @param columns the columns to update. Must be non {@code null}, all * elements must be non {@code null}, may be empty. * @return a list of mutations. Never {@code null}. */ public static ImmutableList<Mutation> mutations(final Column... columns) { Preconditions.checkNotNull(columns, "columns required"); for (Column column : columns) Preconditions.checkNotNull(column, "all columns must be non null"); ImmutableList.Builder<Mutation> b = ImmutableList.builder(); for (Column c : columns) b.add(new Mutation().setColumn_or_supercolumn(new ColumnOrSuperColumn().setColumn(c))); return b.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();//from w w w . j a va 2 s . co 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:org.objectweb.proactive.extensions.p2p.structured.runners.EachRoutingAlgorithm.java
private static List<Runner> extractAndCreateRunners(Class<?> klass) throws InitializationError { Builder<Runner> runners = new ImmutableList.Builder<Runner>(); for (RoutingAlgorithm routingAlgorithm : RoutingAlgorithm.values()) { runners.add(new RoutingAlgorithmRunner(klass, routingAlgorithm.toString())); }/* w w w .j ava2 s. c o m*/ return runners.build(); }
From source file:com.palantir.common.streams.MoreCollectors.java
public static <T> Collector<T, ?, List<T>> toImmutableList() { return Collector.of(ImmutableList::<T>builder, ImmutableList.Builder::<T>add, (left, right) -> left.addAll(right.build()), ImmutableList.Builder::build); }
From source file:com.facebook.presto.sql.planner.DependencyExtractor.java
public static List<Symbol> extractAll(Expression expression) { ImmutableList.Builder<Symbol> builder = ImmutableList.builder(); new SymbolBuilderVisitor().process(expression, builder); return builder.build(); }
From source file:com.facebook.buck.util.MoreIterables.java
/** * Combine the given iterables by peeling off items one at a time from each of the input * iterables until any one of the iterables are exhausted. *//*from w ww .j ava 2 s . c o m*/ @SafeVarargs public static <T> Iterable<T> zipAndConcat(Iterable<T>... inputs) { // If no inputs were seen, just return an empty list. if (inputs.length == 0) { return ImmutableList.of(); } ImmutableList.Builder<T> result = ImmutableList.builder(); ImmutableList<Iterator<T>> iterators = iterators(inputs); // Keep grabbing rounds from the input iterators until we've exhausted one // of them, then return. List<T> round = Lists.newArrayListWithCapacity(inputs.length); while (true) { for (Iterator<T> iterator : iterators) { if (!iterator.hasNext()) { return result.build(); } round.add(iterator.next()); } result.addAll(round); round.clear(); } }