List of usage examples for com.google.common.collect ImmutableList builder
public static <E> Builder<E> builder()
From source file:garmintools.adapters.garmin.DataLengthGarminAdapter.java
@Override public List<Integer> read(DataLengthSection dataLengthSection, TableOfContentsEntry entry, ByteBuffer byteBuffer) {/* w ww . ja v a 2 s . c o m*/ ImmutableList.Builder<Integer> listBuilder = ImmutableList.builder(); Preconditions.checkArgument(entry.itemLength == 2); Preconditions.checkArgument(entry.itemQuantity <= 77, entry.toString()); for (int i = 0; i < entry.itemQuantity; ++i) { listBuilder.add(byteBuffer.getShort() & 0xffff); } return listBuilder.build(); }
From source file:com.yfiton.api.parameter.converters.ListStringConverter.java
@Override public List<String> convert(String parameterName, String parameterValue) { if (parameterValue.isEmpty()) { return ImmutableList.of(); }/*from w w w . j a v a 2 s.c o m*/ char[] chars = parameterValue.toCharArray(); ImmutableList.Builder<String> builder = ImmutableList.builder(); StringBuilder buffer = new StringBuilder(); for (int i = 0; i < chars.length; i++) { char c = chars[i]; if (c == ',') { builder.add(buffer.toString()); buffer.setLength(0); } else { buffer.append(c); } if (i == chars.length - 1) { if (c == ',') { buffer.setLength(0); } builder.add(buffer.toString()); } } return builder.build(); }
From source file:com.facebook.buck.util.concurrent.MoreFutures.java
/** * Invoke multiple callables on the provided executor and wait for all to return successfully. * An exception is thrown (immediately) if any callable fails. * @param executorService Executor service. * @param callables Callables to call.// w ww . j ava 2 s . c o m * @return List of values from each invoked callable in order if all callables execute without * throwing. * @throws ExecutionException If any callable throws an exception, the first of such is wrapped * in an ExecutionException and thrown. Access via * {@link java.util.concurrent.ExecutionException#getCause()}}. */ public static <V> List<V> getAllUninterruptibly(ListeningExecutorService executorService, Iterable<Callable<V>> callables) throws ExecutionException { // Invoke. ImmutableList.Builder<ListenableFuture<V>> futures = ImmutableList.builder(); for (Callable<V> callable : callables) { ListenableFuture<V> future = executorService.submit(callable); futures.add(future); } // Wait for completion. ListenableFuture<List<V>> allAsOne = Futures.allAsList(futures.build()); return Uninterruptibles.getUninterruptibly(allAsOne); }
From source file:ch.acanda.eclipse.pmd.v07tov08.RuleSetConfigurationSerializer.java
/** * Deserializes a String into a list of {@link RuleSetConfiguration}s. * * @param s The serialized configurations. May be {@code null} or empty. * @return Never returns {@code null}.// w w w .j av a 2 s. c om * @throws IllegalArgumentException Thrown when the provided String is not a valid serialization. * @see #serialize(ImmutableList) */ public static ImmutableList<RuleSetConfiguration> deserialize(final String s) { final Builder<RuleSetConfiguration> configs = ImmutableList.builder(); if (!Strings.isNullOrEmpty(s)) { for (final String serializedConfig : s.split(String.valueOf(CONFIGURATION_SEPARATOR))) { final String[] values = serializedConfig.split(String.valueOf(VALUE_SEPARATOR)); if (isWorkspaceRuleSetConfiguration(values)) { configs.add(deserializeWS(values)); } else if (isProjectRuleSetConfiguration(values)) { configs.add(deserializePJ(values)); } else if (isFileSystemRuleSetConfiguration(values)) { configs.add(deserializeFS(values)); } else if (isRemoteRuleSetConfiguration(values)) { configs.add(deserializeRM(values)); } else { throw new IllegalArgumentException( "Unexpected serialized rule set configuration: " + serializedConfig); } } } return configs.build(); }
From source file:org.eclipse.tracecompass.internal.tmf.core.parsers.custom.CustomEventAspects.java
/** * Build a set of event aspects for a given trace definition * * @param definition// w ww . j a v a2 s .c om * The {@link CustomTraceDefinition} of the trace for which you * want the aspects * @return The set of event aspects for the given trace */ public static @NonNull Iterable<ITmfEventAspect<?>> generateAspects(CustomTraceDefinition definition) { List<String> fieldNames = new ArrayList<>(); ImmutableList.Builder<ITmfEventAspect<?>> builder = new ImmutableList.Builder<>(); for (OutputColumn output : definition.outputs) { if (output.tag.equals(Tag.TIMESTAMP) && (definition.timeStampOutputFormat == null || definition.timeStampOutputFormat.isEmpty())) { builder.add(TmfBaseAspects.getTimestampAspect()); fieldNames.add(output.name); } else if (output.tag.equals(Tag.EVENT_TYPE)) { builder.add(TmfBaseAspects.getEventTypeAspect()); fieldNames.add(output.name); } else if (output.tag.equals(Tag.EXTRA_FIELD_NAME) || output.tag.equals(Tag.EXTRA_FIELD_VALUE)) { // These tags should have been substituted with Tag.EXTRA_FIELDS continue; } else if (output.tag.equals(Tag.EXTRA_FIELDS)) { builder.add(new CustomExtraFieldsAspect()); } else { builder.add(new TmfContentFieldAspect(output.name, output.name)); fieldNames.add(output.name); } } return builder.build(); }
From source file:co.cask.cdap.guides.PageRankApp.java
@Override public void configure() { setName("PageRankApp"); addSpark(new PageRankSpark()); addService("PageRankService", new ImmutableList.Builder<HttpServiceHandler>().add(new BackLinksHandler()) .add(new PageRankHandler()).build()); try {/*from w ww. j a va 2 s .c o m*/ ObjectStores.createObjectStore(getConfigurer(), "backLinks", String.class); ObjectStores.createObjectStore(getConfigurer(), "pageRanks", Double.class); } catch (UnsupportedTypeException e) { throw new RuntimeException("Will never happen: all classes above are supported", e); } }
From source file:com.facebook.presto.sql.planner.ExpressionExtractor.java
public static List<Expression> extractExpressionsNonRecursive(PlanNode plan) { ImmutableList.Builder<Expression> expressionsBuilder = ImmutableList.builder(); plan.accept(new Visitor(false, noLookup()), expressionsBuilder); return expressionsBuilder.build(); }
From source file:com.freiheit.fuava.simplebatch.MapBasedBatchDownloader.java
@Override public List<O> apply(final List<I> arg0) { final ImmutableList.Builder<O> b = ImmutableList.builder(); for (final I i : arg0) { b.add(map.get(i));/*from ww w.j av a 2 s . c o m*/ } return b.build(); }
From source file:org.quackbot.hooks.loaders.JavaHookLoader.java
public static ImmutableList<Command> loadCommands(CommandManager commandManager, Object command) { checkNotNull(commandManager, "Must specify command manager"); checkNotNull(command, "Must specify command object"); //Find any command annotations ImmutableList.Builder<Command> addedCommands = ImmutableList.builder(); for (Method curMethod : command.getClass().getMethods()) { JavaCommand commandAnnotation = curMethod.getAnnotation(JavaCommand.class); if (commandAnnotation == null) continue; //Parse arguments first ImmutableList.Builder<JavaMethodArgument> arguments = ImmutableList.builder(); for (JavaArgument curArgument : commandAnnotation.arguments()) arguments.add(new JavaMethodArgument(curArgument.name(), curArgument.argumentHelp(), curArgument.required())); //Build and add command to hookManager String minimumLevel = commandAnnotation.minimumLevel(); if (commandManager.isValidAdminLevel(minimumLevel)) throw new RuntimeException("Unknown level " + minimumLevel); JavaMethodCommand methodCommand = new JavaMethodCommand(commandAnnotation.name(), commandAnnotation.help(), minimumLevel, arguments.build(), command, curMethod); commandManager.addCommand(methodCommand); addedCommands.add(methodCommand); }/*from w ww. ja v a2s. c o m*/ return addedCommands.build(); }
From source file:org.chaston.oakfunds.security.SinglePermissionAssertionImpl.java
public SinglePermissionAssertionImpl(AbstractAuthenticationScope authenticationScope, Permission permission) { ImmutableList.Builder<AtomicInteger> actionTypeCounts = ImmutableList.builder(); for (Map.Entry<RecordType, ActionType> entry : permission.getRelatedActions().entries()) { Map<ActionType, AtomicInteger> actionCounters = authenticationScope.getAccessCounters(entry.getKey()); AtomicInteger actionTypeCount = actionCounters.get(entry.getValue()); if (actionTypeCount == null) { actionTypeCount = new AtomicInteger(); actionCounters.put(entry.getValue(), actionTypeCount); }/*from www .j av a 2 s . c o m*/ actionTypeCount.incrementAndGet(); actionTypeCounts.add(actionTypeCount); } this.actionTypeCounts = actionTypeCounts.build(); }