List of usage examples for com.google.common.collect ImmutableList.Builder add
boolean add(E e);
From source file:eu.eidas.auth.commons.attribute.FileAttributeDefinitionDao.java
private static ImmutableList<SingletonAccessor<ImmutableSortedSet<AttributeDefinition<?>>>> newSingletonAccessors( @Nonnull String fileName, @Nonnull String[] fileNames) { ImmutableList.Builder<SingletonAccessor<ImmutableSortedSet<AttributeDefinition<?>>>> builder = new ImmutableList.Builder<>(); Set<String> duplicates = new HashSet<>(); duplicates.add(fileName);/*from w ww. j ava 2s . c o m*/ builder.add(newSingletonAccessor(fileName)); for (final String name : fileNames) { if (duplicates.add(name)) { builder.add(newSingletonAccessor(name)); } } return builder.build(); }
From source file:com.google.debugging.sourcemap.SourceMapObjectParserJs.java
public static SourceMapObject parse(String contents) throws SourceMapParseException { SourceMapObject.Builder builder = SourceMapObject.builder(); Object jsonInstance = null;/*from w w w. j a v a 2 s. co m*/ try { jsonInstance = parseJson(contents); } catch (Exception ex) { throw new SourceMapParseException("JSON parse exception: " + ex); } JsonMap sourceMap = (JsonMap) jsonInstance; builder.setVersion(sourceMap.version); builder.setFile(sourceMap.file); // Line count is no longer part of the source map spec. -1 is the magic "not provided" value builder.setLineCount(-1); builder.setMappings(sourceMap.mappings); builder.setSourceRoot(sourceMap.sourceRoot); if (sourceMap.sections != null) { ImmutableList.Builder<SourceMapSection> listBuilder = ImmutableList.builder(); for (Section section : sourceMap.sections) { listBuilder.add(buildSection(section)); } builder.setSections(listBuilder.build()); } else { builder.setSections(null); } builder.setSources(sourceMap.sources); builder.setNames(sourceMap.names); Map<String, Object> extensions = new LinkedHashMap<>(); String[] keys = keys(sourceMap); for (String key : keys) { if (key.startsWith("x_")) { extensions.put(key, get(sourceMap, key)); } } builder.setExtensions(Collections.unmodifiableMap(extensions)); return builder.build(); }
From source file:com.facebook.presto.execution.ExecutionFailureInfo.java
private static Failure toException(ExecutionFailureInfo executionFailureInfo) { if (executionFailureInfo == null) { return null; }/* w w w .ja v a2 s.c om*/ Failure failure = new Failure(executionFailureInfo.getType(), executionFailureInfo.getMessage(), executionFailureInfo.getErrorCode(), toException(executionFailureInfo.getCause())); for (ExecutionFailureInfo suppressed : executionFailureInfo.getSuppressed()) { failure.addSuppressed(toException(suppressed)); } ImmutableList.Builder<StackTraceElement> stackTraceBuilder = ImmutableList.builder(); for (String stack : executionFailureInfo.getStack()) { stackTraceBuilder.add(toStackTraceElement(stack)); } ImmutableList<StackTraceElement> stackTrace = stackTraceBuilder.build(); failure.setStackTrace(stackTrace.toArray(new StackTraceElement[stackTrace.size()])); return failure; }
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./*from w w w .j av a 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:io.prestosql.execution.MemoryRevokingScheduler.java
private static List<MemoryPool> getMemoryPools(LocalMemoryManager localMemoryManager) { requireNonNull(localMemoryManager, "localMemoryManager can not be null"); ImmutableList.Builder<MemoryPool> builder = new ImmutableList.Builder<>(); builder.add(localMemoryManager.getGeneralPool()); localMemoryManager.getReservedPool().ifPresent(builder::add); return builder.build(); }
From source file:nz.co.fortytwo.signalk.util.TrackSimplifier.java
static List<Position> vertexReduction(List<Position> track, double tolerance) { // degenerate case if (track.size() < 2) { return track; }// w ww . j av a 2s . c om ImmutableList.Builder<Position> result = ImmutableList.builder(); double tol2 = tolerance * tolerance; Position last = track.get(0); result.add(last); for (int i = 1; i < track.size(); i++) { Position current = track.get(i); if (distanceSquared(last, current) > tol2) { result.add(current); last = current; } } return result.build(); }
From source file:nz.co.fortytwo.signalk.util.TrackSimplifier.java
static List<Position> dpReduction(List<Position> track, double tolerance) { // degenerate case if (track.size() < 3) { return track; }//w w w . j ava 2 s .c o m double tol2 = tolerance * tolerance; boolean[] marks = new boolean[track.size()]; marks[0] = true; marks[marks.length - 1] = true; mark(track, tol2, 0, track.size() - 1, marks); ImmutableList.Builder<Position> result = ImmutableList.builder(); for (int i = 0; i < marks.length; i++) { if (marks[i]) { result.add(track.get(i)); } } return result.build(); }
From source file:eu.eubrazilcc.lvl.core.util.LocaleUtils.java
/** * Obtains an unmodifiable list of installed locales. This method is a wrapper around * {@link Locale#getAvailableLocales()}, which caches the locales and uses generics. * @return country names./*w w w.j a v a2s .c om*/ */ public static ImmutableList<Locale> availableLocaleList() { if (availableLocaleList == null) { synchronized (LocaleUtils.class) { if (availableLocaleList == null) { final ImmutableList.Builder<Locale> builder = new ImmutableList.Builder<Locale>(); final String[] locales = getISOCountries(); for (final String countryCode : locales) { builder.add(new Locale("", countryCode)); } availableLocaleList = builder.build(); } } } return availableLocaleList; }
From source file:com.google.debugging.sourcemap.SourceMapObjectParser.java
public static SourceMapObject parse(String contents) throws SourceMapParseException { SourceMapObject.Builder builder = SourceMapObject.builder(); try {// w ww .ja v a2 s .c o m JsonObject sourceMapRoot = new Gson().fromJson(contents, JsonObject.class); builder.setVersion(sourceMapRoot.get("version").getAsInt()); builder.setFile(getStringOrNull(sourceMapRoot, "file")); builder.setLineCount(sourceMapRoot.has("lineCount") ? sourceMapRoot.get("lineCount").getAsInt() : -1); builder.setMappings(getStringOrNull(sourceMapRoot, "mappings")); builder.setSourceRoot(getStringOrNull(sourceMapRoot, "sourceRoot")); if (sourceMapRoot.has("sections")) { ImmutableList.Builder<SourceMapSection> listBuilder = ImmutableList.builder(); for (JsonElement each : sourceMapRoot.get("sections").getAsJsonArray()) { listBuilder.add(buildSection(each.getAsJsonObject())); } builder.setSections(listBuilder.build()); } builder.setSources(getJavaStringArray(sourceMapRoot.get("sources"))); builder.setSourcesContent(getJavaStringArray(sourceMapRoot.get("sourcesContent"))); builder.setNames(getJavaStringArray(sourceMapRoot.get("names"))); Map<String, Object> extensions = new LinkedHashMap<>(); for (Map.Entry<String, JsonElement> entry : sourceMapRoot.entrySet()) { if (entry.getKey().startsWith("x_")) { extensions.put(entry.getKey(), entry.getValue()); } } builder.setExtensions(Collections.unmodifiableMap(extensions)); } catch (JsonParseException ex) { throw new SourceMapParseException("JSON parse exception: " + ex); } return builder.build(); }
From source file:dagger.internal.codegen.MethodSignature.java
static MethodSignature fromExecutableType(String methodName, ExecutableType methodType) { checkNotNull(methodType);/*w w w .j a va 2 s. c o m*/ ImmutableList.Builder<Equivalence.Wrapper<TypeMirror>> parameters = ImmutableList.builder(); ImmutableList.Builder<Equivalence.Wrapper<TypeMirror>> thrownTypes = ImmutableList.builder(); for (TypeMirror parameter : methodType.getParameterTypes()) { parameters.add(MoreTypes.equivalence().wrap(parameter)); } for (TypeMirror thrownType : methodType.getThrownTypes()) { thrownTypes.add(MoreTypes.equivalence().wrap(thrownType)); } return new AutoValue_MethodSignature(methodName, parameters.build(), thrownTypes.build()); }