private static ImmutableList<Type> expandVarargsToArity(List<VarSymbol> formalArgs, int arity) { ImmutableList.Builder<Type> result = ImmutableList.builderWithExpectedSize(arity); int numberOfVarArgs = arity - formalArgs.size() + 1; for (Iterator<VarSymbol> argsIterator = formalArgs.iterator(); argsIterator.hasNext(); ) { VarSymbol arg = argsIterator.next(); if (argsIterator.hasNext()) { // Not the variadic argument: just add to result result.add(arg.type); } else { // Variadic argument: extract the type and add it to result the proper number of times Type varArgType = ((ArrayType) arg.type).elemtype; for (int idx = 0; idx < numberOfVarArgs; idx++) { result.add(varArgType); } } } return result.build(); }
/** * Gets a list of the unfinished {@link Allocation}s in the order in which those {@link * Allocation}s were encountered. This can be used to display, for example, currently executing * tasks. The order helps to keep the displayed tasks in a deterministic order (new subtasks * appear below older ones) and not jumbled together in some random order. * * @return a list of unfinished {@link Allocation}s */ ImmutableList<Allocation> getUnfinishedAllocations() { Queue<InsertionOrderUnits> unfinishedInsertionOrderUnits = new PriorityQueue<>(); for (InsertionOrderUnits insertionOrderUnits : completionMap.values()) { if (insertionOrderUnits.units.get() < insertionOrderUnits.allocation.getAllocationUnits()) { unfinishedInsertionOrderUnits.add(insertionOrderUnits); } } ImmutableList.Builder<Allocation> unfinishedAllocations = ImmutableList.builderWithExpectedSize(unfinishedInsertionOrderUnits.size()); while (!unfinishedInsertionOrderUnits.isEmpty()) { unfinishedAllocations.add(unfinishedInsertionOrderUnits.remove().allocation); } return unfinishedAllocations.build(); }
/** * Gets a new {@link AbsoluteUnixPath} from a {@link Path}. The {@code path} must be absolute * (indicated by a non-null {@link Path#getRoot}). * * @param path the absolute {@link Path} to convert to an {@link AbsoluteUnixPath}. * @return a new {@link AbsoluteUnixPath} */ public static AbsoluteUnixPath fromPath(Path path) { Preconditions.checkArgument( path.getRoot() != null, "Cannot create AbsoluteUnixPath from non-absolute Path: " + path); ImmutableList.Builder<String> pathComponents = ImmutableList.builderWithExpectedSize(path.getNameCount()); for (Path pathComponent : path) { pathComponents.add(pathComponent.toString()); } return new AbsoluteUnixPath(pathComponents.build()); }
/** * Resolves this path against another relative path. * * @param relativeUnixPath the relative path to resolve against * @return a new {@link AbsoluteUnixPath} representing the resolved path */ public AbsoluteUnixPath resolve(RelativeUnixPath relativeUnixPath) { ImmutableList.Builder<String> newPathComponents = ImmutableList.builderWithExpectedSize( pathComponents.size() + relativeUnixPath.getRelativePathComponents().size()); newPathComponents.addAll(pathComponents); newPathComponents.addAll(relativeUnixPath.getRelativePathComponents()); return new AbsoluteUnixPath(newPathComponents.build()); }
@Override final FieldScopeLogic subScopeImpl( Descriptor rootDescriptor, FieldDescriptorOrUnknown fieldDescriptorOrUnknown) { ImmutableList.Builder<FieldScopeLogic> builder = ImmutableList.builderWithExpectedSize(elements.size()); for (FieldScopeLogic elem : elements) { builder.add(elem.subScope(rootDescriptor, fieldDescriptorOrUnknown)); } return newLogicOfSameType(builder.build()); } }
private List<SingularField> compareUnknownFieldList( List<?> actualValues, List<?> expectedValues, boolean excludeNonRecursive, UnknownFieldDescriptor unknownFieldDescriptor, FluentEqualityConfig config) { int maxSize = Math.max(actualValues.size(), expectedValues.size()); ImmutableList.Builder<SingularField> builder = ImmutableList.builderWithExpectedSize(maxSize); for (int i = 0; i < maxSize; i++) { @NullableDecl Object actual = actualValues.size() > i ? actualValues.get(i) : null; @NullableDecl Object expected = expectedValues.size() > i ? expectedValues.get(i) : null; builder.add( compareUnknownFieldValue( actual, expected, excludeNonRecursive, unknownFieldDescriptor, indexedName(unknownFieldDescriptor, i), config)); } return builder.build(); }
/** * Compares {@code actualList} and {@code expectedList}, two submessages corresponding to {@code * fieldDescriptor}. Uses {@code excludeNonRecursive}, {@code parentFieldPath}, and {@code * fieldScopeLogic} to compare the messages. * * @return A list in index order, containing the diff results for each message. */ private List<SingularField> compareRepeatedFieldByIndices( List<?> actualList, List<?> expectedList, boolean excludeNonRecursive, FieldDescriptor fieldDescriptor, FluentEqualityConfig config) { int maxSize = Math.max(actualList.size(), expectedList.size()); ImmutableList.Builder<SingularField> builder = ImmutableList.builderWithExpectedSize(maxSize); for (int i = 0; i < maxSize; i++) { @NullableDecl Object actual = actualList.size() > i ? actualList.get(i) : null; @NullableDecl Object expected = expectedList.size() > i ? expectedList.get(i) : null; builder.add( compareSingularValue( actual, expected, /*defaultValue=*/ null, excludeNonRecursive, fieldDescriptor, indexedName(fieldDescriptor, i), config)); } return builder.build(); }
@GwtIncompatible public void testBuilderExactlySizedReusesArray() { ImmutableList.Builder<Integer> builder = ImmutableList.builderWithExpectedSize(10); Object[] builderArray = builder.contents; for (int i = 0; i < 10; i++) { builder.add(i); } Object[] builderArrayAfterAdds = builder.contents; RegularImmutableList<Integer> list = (RegularImmutableList<Integer>) builder.build(); Object[] listInternalArray = list.array; assertSame(builderArray, builderArrayAfterAdds); assertSame(builderArray, listInternalArray); }
@Override public FieldScopeLogicMap<V> subScope( Descriptor rootDescriptor, FieldDescriptorOrUnknown fieldDescriptorOrUnknown) { ImmutableList.Builder<Entry<V>> newEntries = ImmutableList.builderWithExpectedSize(entries.size()); for (Entry<V> entry : entries) { newEntries.add( Entry.of( entry.fieldScopeLogic().subScope(rootDescriptor, fieldDescriptorOrUnknown), entry.value())); } return new FieldScopeLogicMap<>(newEntries.build()); }
new TimerEventDispatcher(buildConfiguration.getEventDispatcher(), DESCRIPTION)) { ImmutableList.Builder<BuildAndCacheApplicationLayerStep> buildAndCacheApplicationLayerSteps = ImmutableList.builderWithExpectedSize(layerCount); for (LayerConfiguration layerConfiguration : buildConfiguration.getLayerConfigurations()) {
@Memoized @Override Iterable<? extends RecursableDiffEntity> childEntities() { // Assemble the diffs in field number order so it most closely matches the schema. ImmutableList.Builder<RecursableDiffEntity> builder = ImmutableList.builderWithExpectedSize( singularFields().size() + repeatedFields().size() + unknownFields().asSet().size()); Set<Integer> fieldNumbers = Sets.union(singularFields().keySet(), repeatedFields().keySet()); for (int fieldNumber : Ordering.natural().sortedCopy(fieldNumbers)) { builder.addAll(singularFields().get(fieldNumber)); builder.addAll(repeatedFields().get(fieldNumber)); } builder.addAll(unknownFields().asSet()); return builder.build(); }
= ImmutableList.builderWithExpectedSize(numberDistinctWeight); EndpointsGroupByWeight currentGroup = null;
@Override public ImmutableList<PullAndCacheBaseImageLayerStep> call() throws ExecutionException, LayerPropertyNotFoundException { BaseImageWithAuthorization pullBaseImageStepResult = NonBlockingSteps.get(pullBaseImageStep); ImmutableList<Layer> baseImageLayers = pullBaseImageStepResult.getBaseImage().getLayers(); try (ProgressEventDispatcher progressEventDispatcher = progressEventDispatcherFactory.create( BuildStepType.PULL_AND_CACHE_BASE_IMAGE_LAYER, "checking base image layers", baseImageLayers.size()); TimerEventDispatcher ignored = new TimerEventDispatcher(buildConfiguration.getEventDispatcher(), DESCRIPTION)) { ImmutableList.Builder<PullAndCacheBaseImageLayerStep> pullAndCacheBaseImageLayerStepsBuilder = ImmutableList.builderWithExpectedSize(baseImageLayers.size()); for (Layer layer : baseImageLayers) { pullAndCacheBaseImageLayerStepsBuilder.add( new PullAndCacheBaseImageLayerStep( listeningExecutorService, buildConfiguration, progressEventDispatcher.newChildProducer(), layer.getBlobDescriptor().getDigest(), pullBaseImageStepResult.getBaseImageAuthorization())); } return pullAndCacheBaseImageLayerStepsBuilder.build(); } } }
ImmutableList.builderWithExpectedSize(keyOrder.size()); for (Object key : keyOrder) { @NullableDecl Object actualValue = actualMap.get(key);
@Override public List<Row> apply(List<FlatRow> flatRowList) { ImmutableList.Builder<Row> rowBuilder = ImmutableList.builderWithExpectedSize(flatRowList.size()); for(FlatRow flatRow : flatRowList){ rowBuilder.add(FlatRowConverter.convertToModelRow(flatRow)); } return rowBuilder.build(); } }, MoreExecutors.directExecutor());
private YangInstanceIdentifier readYangInstanceIdentifierInternal() throws IOException { int size = input.readInt(); final Builder<PathArgument> pathArguments = ImmutableList.builderWithExpectedSize(size); for (int i = 0; i < size; i++) { pathArguments.add(readPathArgument()); } return YangInstanceIdentifier.create(pathArguments.build()); }
@Override final FieldScopeLogic subLogicImpl( Descriptor rootDescriptor, FieldDescriptorOrUnknown fieldDescriptorOrUnknown) { ImmutableList.Builder<FieldScopeLogic> builder = ImmutableList.builderWithExpectedSize(elements.size()); for (FieldScopeLogic elem : elements) { builder.add(elem.subLogic(rootDescriptor, fieldDescriptorOrUnknown)); } return newLogicOfSameType(builder.build()); } }
@Override public SchemaPath readSchemaPath() throws IOException { readSignatureMarkerAndVersionIfNeeded(); final boolean absolute = input.readBoolean(); final int size = input.readInt(); final Builder<QName> qnames = ImmutableList.builderWithExpectedSize(size); for (int i = 0; i < size; ++i) { qnames.add(readQName()); } return SchemaPath.create(qnames.build(), absolute); }
public static com.google.cloud.bigtable.data.v2.models.Row convertToModelRow(FlatRow row) { if (row == null || row.getCells() == null) { return null; } ImmutableList.Builder<RowCell> rowCellList = ImmutableList.builderWithExpectedSize(row.getCells().size()); for (FlatRow.Cell cell : row.getCells()) { rowCellList.add(toRowCell(cell)); } return com.google.cloud.bigtable.data.v2.models.Row.create(row.getRowKey(), rowCellList.build()); }
@GwtIncompatible public void testBuilderExactlySizedReusesArray() { ImmutableList.Builder<Integer> builder = ImmutableList.builderWithExpectedSize(10); Object[] builderArray = builder.contents; for (int i = 0; i < 10; i++) { builder.add(i); } Object[] builderArrayAfterAdds = builder.contents; RegularImmutableList<Integer> list = (RegularImmutableList<Integer>) builder.build(); Object[] listInternalArray = list.array; assertSame(builderArray, builderArrayAfterAdds); assertSame(builderArray, listInternalArray); }