List of usage examples for com.google.common.collect ImmutableList.Builder add
boolean add(E e);
From source file:io.prestosql.plugin.raptor.legacy.storage.organization.ShardOrganizerUtil.java
public static Collection<ShardIndexInfo> getOrganizationEligibleShards(IDBI dbi, MetadataDao metadataDao, Table tableInfo, Collection<ShardMetadata> shards, boolean includeSortColumns) { Map<Long, ShardMetadata> shardsById = uniqueIndex(shards, ShardMetadata::getShardId); long tableId = tableInfo.getTableId(); ImmutableList.Builder<String> columnsBuilder = ImmutableList.builder(); columnsBuilder.add("shard_id"); // include temporal columns if present Optional<TableColumn> temporalColumn = Optional.empty(); if (tableInfo.getTemporalColumnId().isPresent()) { long temporalColumnId = tableInfo.getTemporalColumnId().getAsLong(); temporalColumn = Optional.of(metadataDao.getTableColumn(tableId, temporalColumnId)); columnsBuilder.add(minColumn(temporalColumnId), maxColumn(temporalColumnId)); }/*from w ww. jav a 2s . co m*/ // include sort columns if needed Optional<List<TableColumn>> sortColumns = Optional.empty(); if (includeSortColumns) { sortColumns = Optional.of(metadataDao.listSortColumns(tableId)); for (TableColumn column : sortColumns.get()) { columnsBuilder.add(minColumn(column.getColumnId()), maxColumn(column.getColumnId())); } } String columnToSelect = Joiner.on(",\n").join(columnsBuilder.build()); ImmutableList.Builder<ShardIndexInfo> indexInfoBuilder = ImmutableList.builder(); try (Connection connection = dbi.open().getConnection()) { for (List<ShardMetadata> partitionedShards : partition(shards, 1000)) { String shardIds = Joiner.on(",").join(nCopies(partitionedShards.size(), "?")); String sql = format("" + "SELECT %s\n" + "FROM %s\n" + "WHERE shard_id IN (%s)", columnToSelect, shardIndexTable(tableId), shardIds); try (PreparedStatement statement = connection.prepareStatement(sql)) { for (int i = 0; i < partitionedShards.size(); i++) { statement.setLong(i + 1, partitionedShards.get(i).getShardId()); } try (ResultSet resultSet = statement.executeQuery()) { while (resultSet.next()) { long shardId = resultSet.getLong("shard_id"); Optional<ShardRange> sortRange = Optional.empty(); if (includeSortColumns) { sortRange = getShardRange(sortColumns.get(), resultSet); if (!sortRange.isPresent()) { continue; } } Optional<ShardRange> temporalRange = Optional.empty(); if (temporalColumn.isPresent()) { temporalRange = getShardRange(ImmutableList.of(temporalColumn.get()), resultSet); if (!temporalRange.isPresent()) { continue; } } ShardMetadata shardMetadata = shardsById.get(shardId); indexInfoBuilder.add(toShardIndexInfo(shardMetadata, temporalRange, sortRange)); } } } } } catch (SQLException e) { throw new RuntimeException(e); } return indexInfoBuilder.build(); }
From source file:com.android.tools.idea.assistant.RecipeUtils.java
@NotNull public static List<RecipeMetadata> getRecipeMetadata(@NotNull Recipe recipe, @NotNull Project project) { Pair key = new Pair(recipe, project); if (!myRecipeMetadataCache.containsKey(key)) { ImmutableList.Builder<RecipeMetadata> cache = ImmutableList.builder(); for (Module module : GradleProjectInfo.getInstance(project).getAndroidModules()) { cache.add(getRecipeMetadata(recipe, module)); }// w w w . ja v a 2 s. c o m myRecipeMetadataCache.put(key, cache.build()); } return myRecipeMetadataCache.get(key); }
From source file:com.google.errorprone.bugpatterns.inject.dagger.Util.java
/** * Returns a fix that changes a concrete class to an abstract class. * * <ul>/*from www. j a va2 s . com*/ * <li>Removes {@code final} if it was there. * <li>Adds {@code abstract} if it wasn't there. * <li>Adds a private empty constructor if the class was {@code final} and had only a default * constructor. * </ul> */ static SuggestedFix.Builder makeConcreteClassAbstract(ClassTree classTree, VisitorState state) { Set<Modifier> flags = EnumSet.noneOf(Modifier.class); flags.addAll(classTree.getModifiers().getFlags()); boolean wasFinal = flags.remove(FINAL); boolean wasAbstract = !flags.add(ABSTRACT); if (classTree.getKind().equals(INTERFACE) || (!wasFinal && wasAbstract)) { return SuggestedFix.builder(); // no-op } ImmutableList.Builder<Object> modifiers = ImmutableList.builder(); for (AnnotationTree annotation : classTree.getModifiers().getAnnotations()) { modifiers.add(state.getSourceForNode(annotation)); } modifiers.addAll(flags); SuggestedFix.Builder makeAbstract = SuggestedFix.builder(); if (((JCModifiers) classTree.getModifiers()).pos == -1) { makeAbstract.prefixWith(classTree, Joiner.on(' ').join(modifiers.build())); } else { makeAbstract.replace(classTree.getModifiers(), Joiner.on(' ').join(modifiers.build())); } if (wasFinal && HAS_GENERATED_CONSTRUCTOR.matches(classTree, state)) { makeAbstract.merge(addPrivateConstructor(classTree)); } return makeAbstract; }
From source file:com.facebook.buck.skylark.io.impl.WatchmanGlobber.java
/** Returns an expression for matching types of files to return. */ private static ImmutableList<Object> toTypeExpression(boolean excludeDirectories) { ImmutableList.Builder<Object> typeExpressionBuilder = ImmutableList.builder().add("anyof") .add(ImmutableList.of("type", "f")).add(ImmutableList.of("type", "l")); if (!excludeDirectories) { typeExpressionBuilder.add(ImmutableList.of("type", "d")); }// ww w .ja v a 2 s. c om return typeExpressionBuilder.build(); }
From source file:com.noodlewiz.xjavab.ext.record.internal.Unpacker.java
public static ClientInfo unpackClientInfo(final ByteBuffer __xjb_buf) { final long clientResource = com.noodlewiz.xjavab.core.internal.Unpacker.unpackUInt(__xjb_buf); final long numRanges = com.noodlewiz.xjavab.core.internal.Unpacker.unpackUInt(__xjb_buf); final com.google.common.collect.ImmutableList.Builder<com.noodlewiz.xjavab.ext.record.Range> __xjb_rangesBuilder = new com.google.common.collect.ImmutableList.Builder<com.noodlewiz.xjavab.ext.record.Range>(); for (int __xjb_i = 0; (__xjb_i < numRanges); __xjb_i++) { __xjb_rangesBuilder.add(com.noodlewiz.xjavab.ext.record.internal.Unpacker.unpackRange(__xjb_buf)); }/*from ww w.jav a 2 s . c o m*/ final List<com.noodlewiz.xjavab.ext.record.Range> ranges = __xjb_rangesBuilder.build(); return new ClientInfo(clientResource, numRanges, ranges); }
From source file:org.ambraproject.wombat.freemarker.TemplateModelUtil.java
static ImmutableList<TemplateModel> getAsList(TemplateModel value) throws TemplateModelException { if (value == null) return ImmutableList.of(); if (value instanceof TemplateSequenceModel) { ImmutableList.Builder<TemplateModel> builder = ImmutableList.builder(); TemplateSequenceModel sequenceModel = (TemplateSequenceModel) value; int size = sequenceModel.size(); for (int i = 0; i < size; i++) { builder.add(sequenceModel.get(i)); }/*www . j av a 2s. co m*/ return builder.build(); } else { return ImmutableList.of(value); } }
From source file:org.mule.extension.validation.internal.ImmutableMultipleValidationResult.java
/** * A {@link Iterable} with all the {@link ValidationResult} that were generated * together, both failed and successful alike. * * @param results the obtained {@link ValidationResult} objects * @return a {@link MultipleValidationResult} *///from w w w .ja v a 2s . c o m public static MultipleValidationResult of(Iterable<ValidationResult> results) { ImmutableList.Builder<ValidationResult> failedResultsBuilder = ImmutableList.builder(); StringBuilder message = new StringBuilder(); boolean error = false; for (ValidationResult result : results) { if (result.isError()) { failedResultsBuilder.add(result); if (message.length() > 0) { message.append('\n'); } message.append(result.getMessage()); error = true; } } return new ImmutableMultipleValidationResult(failedResultsBuilder.build(), error, message.toString()); }
From source file:com.noodlewiz.xjavab.ext.xfixes.internal.ReplyUnpacker.java
public static GetCursorImageReply unpackGetCursorImage(final ByteBuffer __xjb_buf) { __xjb_buf.position(4);// w w w . j ava 2 s . c o m final long length = com.noodlewiz.xjavab.core.internal.Unpacker.unpackUInt(__xjb_buf); __xjb_buf.position(1); com.noodlewiz.xjavab.core.internal.Unpacker.unpackPad(__xjb_buf, 1); __xjb_buf.position(8); final short x = com.noodlewiz.xjavab.core.internal.Unpacker.unpackShort(__xjb_buf); final short y = com.noodlewiz.xjavab.core.internal.Unpacker.unpackShort(__xjb_buf); final int width = com.noodlewiz.xjavab.core.internal.Unpacker.unpackUShort(__xjb_buf); final int height = com.noodlewiz.xjavab.core.internal.Unpacker.unpackUShort(__xjb_buf); final int xhot = com.noodlewiz.xjavab.core.internal.Unpacker.unpackUShort(__xjb_buf); final int yhot = com.noodlewiz.xjavab.core.internal.Unpacker.unpackUShort(__xjb_buf); final long cursorSerial = com.noodlewiz.xjavab.core.internal.Unpacker.unpackUInt(__xjb_buf); com.noodlewiz.xjavab.core.internal.Unpacker.unpackPad(__xjb_buf, 8); final com.google.common.collect.ImmutableList.Builder<Long> __xjb_cursorImageBuilder = new com.google.common.collect.ImmutableList.Builder<Long>(); for (int __xjb_i = 0; (__xjb_i < (width * height)); __xjb_i++) { __xjb_cursorImageBuilder.add(com.noodlewiz.xjavab.core.internal.Unpacker.unpackUInt(__xjb_buf)); } final List<Long> cursorImage = __xjb_cursorImageBuilder.build(); return new GetCursorImageReply(x, y, width, height, xhot, yhot, cursorSerial, cursorImage); }
From source file:com.facebook.buck.apple.XcodeRuleConfiguration.java
/** * Convert from a raw json representation of the Configuration to an actual Configuration object. * * @param configurations/* ww w. j a v a 2 s.c om*/ * A map of configuration names to lists, where each each element is a layer of the * configuration. Each layer can be specified as a path to a .xcconfig file, or a dictionary of * xcode build settings. */ public static ImmutableSet<XcodeRuleConfiguration> fromRawJsonStructure( ImmutableMap<String, ImmutableList<Either<Path, ImmutableMap<String, String>>>> configurations) { ImmutableSet.Builder<XcodeRuleConfiguration> builder = ImmutableSet.builder(); for (ImmutableMap.Entry<String, ImmutableList<Either<Path, ImmutableMap<String, String>>>> entry : configurations .entrySet()) { ImmutableList.Builder<Layer> layers = ImmutableList.builder(); for (Either<Path, ImmutableMap<String, String>> value : entry.getValue()) { if (value.isLeft()) { layers.add(new Layer(value.getLeft())); } else if (value.isRight()) { layers.add(new Layer(value.getRight())); } } builder.add(new XcodeRuleConfiguration(entry.getKey(), layers.build())); } return builder.build(); }
From source file:com.android.build.gradle.ndk.internal.NativeCompilerArgsUtil.java
/** * Convert compile arguments to the form used in options.txt. *//*from w ww .ja v a 2 s . c o m*/ @NonNull public static List<String> transform(@NonNull Iterable<String> args) { ImmutableList.Builder<String> builder = ImmutableList.builder(); for (String arg : args) { String str = arg; str = str.replace("\\", "\\\\").replace("\"", "\\\""); if (WHITESPACE.matcher(str).find()) { str = '\"' + str + '\"'; } builder.add(str); } return builder.build(); }