List of usage examples for com.google.common.collect ImmutableMap.Builder putAll
public final void putAll(Map<? extends K, ? extends V> map)
From source file:com.ardor3d.input.MouseState.java
/** * Constructs a new MouseState instance. * // w w w . j a va 2 s. c o m * @param x * the mouse's x position * @param y * the mouse's y position * @param dx * the delta in the mouse's x position since the last update * @param dy * the delta in the mouse's y position since the last update * @param dwheel * the delta in the mouse's wheel movement since the last update * @param buttonStates * the states of the various given buttons. * @param clicks * the number of times each button has been clicked */ public MouseState(final int x, final int y, final int dx, final int dy, final int dwheel, final EnumMap<MouseButton, ButtonState> buttonStates, final Multiset<MouseButton> clicks) { _x = x; _y = y; _dx = dx; _dy = dy; _dwheel = dwheel; if (buttonStates != null) { final com.google.common.collect.ImmutableMap.Builder<MouseButton, ButtonState> builder = ImmutableMap .builder(); _buttonStates = builder.putAll(buttonStates).build(); } else { _buttonStates = ImmutableMap.of(); } if (clicks != null) { final Builder<MouseButton> builder = ImmutableMultiset.builder(); _clickCounts = builder.addAll(clicks).build(); } else { _clickCounts = ImmutableMultiset.of(); } }
From source file:com.facebook.buck.features.rust.RustCompileRule.java
@Override public ImmutableList<Step> getBuildSteps(BuildContext buildContext, BuildableContext buildableContext) { Path outputdir = getOutputDir(getBuildTarget(), getProjectFilesystem()); Path output = getOutput();//from www . j a va 2s.c o m if (filename.isPresent()) { buildableContext.recordArtifact(output); } SourcePathResolver resolver = buildContext.getSourcePathResolver(); Path argFilePath = getProjectFilesystem().getRootPath() .resolve(BuildTargetPaths.getScratchPath(getProjectFilesystem(), getBuildTarget(), "%s.argsfile")); Path fileListPath = getProjectFilesystem().getRootPath().resolve( BuildTargetPaths.getScratchPath(getProjectFilesystem(), getBuildTarget(), "%s__filelist.txt")); return new ImmutableList.Builder<Step>() .addAll(MakeCleanDirectoryStep.of(BuildCellRelativePath.fromCellRelativePath( buildContext.getBuildCellRootPath(), getProjectFilesystem(), scratchDir))) .add(new SymlinkFilesIntoDirectoryStep(getProjectFilesystem(), getProjectFilesystem().getRootPath(), srcs.stream().map(resolver::getRelativePath).collect(ImmutableList.toImmutableList()), scratchDir)) .addAll(MakeCleanDirectoryStep .of(BuildCellRelativePath.fromCellRelativePath(buildContext.getBuildCellRootPath(), getProjectFilesystem(), getOutputDir(getBuildTarget(), getProjectFilesystem())))) .addAll(CxxPrepareForLinkStep.create(argFilePath, fileListPath, linker.fileList(fileListPath), output, linkerArgs, linker, getBuildTarget().getCellPath(), resolver)) .add(new ShellStep(getProjectFilesystem().getRootPath()) { @Override protected ImmutableList<String> getShellCommandInternal(ExecutionContext executionContext) { ImmutableList<String> linkerCmd = linker.getCommandPrefix(resolver); ImmutableList.Builder<String> cmd = ImmutableList.builder(); // Accumulate Args into set to dedup them while retaining their order, // since there are often many duplicates for things like library paths. // // NOTE: this means that all logical args should be a single string on the command // line (ie "-Lfoo", not ["-L", "foo"]) ImmutableSet.Builder<String> dedupArgs = ImmutableSet.builder(); dedupArgs.addAll(Arg.stringify(depArgs, buildContext.getSourcePathResolver())); Path src = scratchDir.resolve(resolver.getRelativePath(rootModule)); cmd.addAll(compiler.getCommandPrefix(resolver)); if (executionContext.getAnsi().isAnsiTerminal()) { cmd.add("--color=always"); } remapSrcPaths.addRemapOption(cmd, workingDirectory.toString(), scratchDir + "/"); // Generate a target-unique string to distinguish distinct crates with the same // name. String metadata = RustCompileUtils.hashForTarget(RustCompileRule.this.getBuildTarget()); cmd.add(String.format("-Clinker=%s", linkerCmd.get(0))) .add(String.format("-Clink-arg=@%s", argFilePath)) .add(String.format("-Cmetadata=%s", metadata)) .add(String.format("-Cextra-filename=-%s", metadata)) .addAll(Arg.stringify(args, buildContext.getSourcePathResolver())) .addAll(dedupArgs.build()).add("--out-dir", outputdir.toString()) .add(src.toString()); return cmd.build(); } /* * Make sure all stderr output from rustc is emitted, since its either a warning or an * error. In general Rust code should have zero warnings, or all warnings as errors. * Regardless, respect requests for silence. */ @Override protected boolean shouldPrintStderr(Verbosity verbosity) { return !verbosity.isSilent(); } @Override public ImmutableMap<String, String> getEnvironmentVariables(ExecutionContext context) { ImmutableMap.Builder<String, String> env = ImmutableMap.builder(); env.putAll(compiler.getEnvironment(buildContext.getSourcePathResolver())); Path root = getProjectFilesystem().getRootPath(); Path basePath = getBuildTarget().getBasePath(); // These need to be set as absolute paths - the intended use // is within an `include!(concat!(env!("..."), "...")` // invocation in Rust source, and if the path isn't absolute // it will be treated as relative to the current file including // it. The trailing '/' is also to assist this use-case. env.put("RUSTC_BUILD_CONTAINER", root.resolve(scratchDir) + "/"); env.put("RUSTC_BUILD_CONTAINER_BASE_PATH", root.resolve(scratchDir.resolve(basePath)) + "/"); return env.build(); } @Override public String getShortName() { return "rust-build"; } }).build(); }
From source file:com.facebook.presto.orc.writer.MapColumnWriter.java
@Override public Map<Integer, ColumnStatistics> getColumnStripeStatistics() { checkState(closed);/*from www . ja v a2 s . c om*/ ImmutableMap.Builder<Integer, ColumnStatistics> columnStatistics = ImmutableMap.builder(); columnStatistics.put(column, ColumnStatistics.mergeColumnStatistics(rowGroupColumnStatistics)); columnStatistics.putAll(keyWriter.getColumnStripeStatistics()); columnStatistics.putAll(valueWriter.getColumnStripeStatistics()); return columnStatistics.build(); }
From source file:com.facebook.buck.android.AndroidPackageableCollector.java
public AndroidPackageableCollection build() { collectionBuilder.setBuildConfigs(ImmutableMap.copyOf(buildConfigs)); final ImmutableSet<HasJavaClassHashes> javaClassProviders = javaClassHashesProviders.build(); collectionBuilder.addAllJavaLibrariesToDex(javaClassProviders.stream().map(HasBuildTarget::getBuildTarget) .collect(MoreCollectors.toImmutableSet())); collectionBuilder.setClassNamesToHashesSupplier(Suppliers.memoize(() -> { ImmutableMap.Builder<String, HashCode> builder = ImmutableMap.builder(); for (HasJavaClassHashes hasJavaClassHashes : javaClassProviders) { builder.putAll(hasJavaClassHashes.getClassNamesToHashes()); }/*from w ww . j a va 2 s . c om*/ return builder.build(); })); ImmutableSet<BuildTarget> resources = ImmutableSet.copyOf(resourcesWithNonEmptyResDir.build()); for (BuildTarget buildTarget : resourcesWithAssets.build()) { if (!resources.contains(buildTarget)) { resourceDetailsBuilder.addResourcesWithEmptyResButNonEmptyAssetsDir(buildTarget); } } // Reverse the resource directories/targets collections because we perform a post-order // traversal of the action graph, and we need to return these collections topologically // sorted. resourceDetailsBuilder.setResourceDirectories( resourceDirectories.build().reverse().stream().distinct().collect(Collectors.toList())); resourceDetailsBuilder.setResourcesWithNonEmptyResDir(resourcesWithNonEmptyResDir.build().reverse()); collectionBuilder.setResourceDetails(resourceDetailsBuilder.build()); return collectionBuilder.build(); }
From source file:brooklyn.location.jclouds.JcloudsSshMachineLocation.java
@Override public Map<String, String> toMetadataRecord() { Hardware hardware = node.getHardware(); List<? extends Processor> processors = (hardware != null) ? hardware.getProcessors() : null; ImmutableMap.Builder<String, String> builder = ImmutableMap.builder(); builder.putAll(super.toMetadataRecord()); putIfNotNull(builder, "provider", getParent().getProvider()); putIfNotNull(builder, "account", getParent().getIdentity()); putIfNotNull(builder, "serverId", node.getProviderId()); putIfNotNull(builder, "imageId", node.getImageId()); putIfNotNull(builder, "instanceTypeName", (hardware != null ? hardware.getName() : null)); putIfNotNull(builder, "instanceTypeId", (hardware != null ? hardware.getProviderId() : null)); putIfNotNull(builder, "ram", "" + (hardware != null ? hardware.getRam() : null)); putIfNotNull(builder, "cpus", "" + (processors != null ? processors.size() : null)); try {//from w w w.j a v a 2 s . c o m OsDetails osDetails = getOsDetails(); putIfNotNull(builder, "osName", osDetails.getName()); putIfNotNull(builder, "osArch", osDetails.getArch()); putIfNotNull(builder, "is64bit", osDetails.is64bit() ? "true" : "false"); } catch (Exception e) { Exceptions.propagateIfFatal(e); LOG.warn("Unable to get OS Details for " + node + "; continuing", e); } return builder.build(); }
From source file:org.elasticsearch.search.fetch.FetchPhase.java
@Override public Map<String, ? extends SearchParseElement> parseElements() { ImmutableMap.Builder<String, SearchParseElement> parseElements = ImmutableMap.builder(); parseElements.put("fields", new FieldsParseElement()); for (FetchSubPhase fetchSubPhase : fetchSubPhases) { parseElements.putAll(fetchSubPhase.parseElements()); }/* w ww . j a v a 2 s. c o m*/ return parseElements.build(); }
From source file:org.prebake.service.plan.Product.java
/** * Returns a concrete product by binding inputs and outputs with the given * bindings./* www . jav a 2 s.com*/ */ public Product withParameterValues(Map<String, String> parameterValues) { if (parameterValues.isEmpty()) { return this; } ImmutableMap<String, String> bindings; { ImmutableMap.Builder<String, String> b = ImmutableMap.builder(); b.putAll(this.name.bindings); // Will fail if this.bindings and parameterValues have overlapping keys. b.putAll(parameterValues); bindings = b.build(); } GlobRelation.Solution s = filesAndParams.withParameterValues(bindings); GlobRelation newFilesAndParams = new GlobRelation(s.inputs, s.outputs); ImmutableList.Builder<Action> newActions = ImmutableList.builder(); for (Action a : actions) { newActions.add(a.withParameterValues(bindings)); } return new Product(name.withBindings(bindings), help, newFilesAndParams, newActions.build(), isIntermediate, bake, source, this.template == null ? this : this.template); }
From source file:co.cask.cdap.template.etl.common.guice.TypeResolver.java
/** Returns a new {@code TypeResolver} with {@code variable} mapping to {@code type}. */ final TypeResolver where(Map<? extends TypeVariable<?>, ? extends Type> mappings) { ImmutableMap.Builder<TypeVariable<?>, Type> builder = ImmutableMap.builder(); builder.putAll(typeTable); for (Map.Entry<? extends TypeVariable<?>, ? extends Type> mapping : mappings.entrySet()) { TypeVariable<?> variable = mapping.getKey(); Type type = mapping.getValue(); checkArgument(!variable.equals(type), "Type variable %s bound to itself", variable); builder.put(variable, type);//from w w w . ja va2s . c o m } return new TypeResolver(builder.build()); }
From source file:org.lanternpowered.server.game.registry.type.effect.ParticleTypeRegistryModule.java
private void registerParticle(int internalType, String id, boolean velocity, Map<ParticleOption<?>, Object> extraOptions) { final ImmutableMap.Builder<ParticleOption<?>, Object> options = ImmutableMap.builder(); options.put(ParticleOptions.OFFSET, Vector3d.ZERO); options.put(ParticleOptions.QUANTITY, 1); if (velocity) { options.put(ParticleOptions.VELOCITY, Vector3d.ZERO); }//from w w w. j a v a2 s . com options.putAll(extraOptions); registerEffect(id, OptionalInt.of(internalType), options.build()); }
From source file:com.b2international.snowowl.snomed.datastore.id.memory.DefaultSnomedIdentifierService.java
@Override public Map<String, SctId> getSctIds(final Set<String> componentIds) { final Query<SctId> getSctIdsQuery = Query.select(SctId.class) .where(Expressions.matchAny(DocumentMapping._ID, componentIds)).limit(componentIds.size()).build(); final Hits<SctId> existingIds = store.read(index -> index.search(getSctIdsQuery)); final Map<String, SctId> existingIdsMap = Maps.uniqueIndex(existingIds, SctId::getSctid); if (existingIdsMap.size() == componentIds.size()) { return existingIdsMap; } else {/*from w w w . ja v a2 s . c o m*/ final Set<String> knownComponentIds = existingIdsMap.keySet(); final Set<String> difference = ImmutableSet.copyOf(Sets.difference(componentIds, knownComponentIds)); final ImmutableMap.Builder<String, SctId> resultBuilder = ImmutableMap.builder(); resultBuilder.putAll(existingIdsMap); for (final String componentId : difference) { resultBuilder.put(componentId, buildSctId(componentId, IdentifierStatus.AVAILABLE)); } return resultBuilder.build(); } }