List of usage examples for com.google.common.collect ImmutableMap get
V get(Object key);
From source file:mod.steamnsteel.structure.StructureDefinitionBuilder.java
private static void assignX(ImmutableMap<Character, ?> map, String[][] layers, TripleIterator itr, Object[][][] res) {//from w w w . j a va 2 s. c o m while (itr.hasNext()) { final TripleCoord local = itr.next(); final char c = layers[local.y][local.z].charAt(local.x); if (!map.containsKey(c) && c != ' ') { throw new StructureDefinitionError("assignX.Map missing '" + c + "' @" + local); } res[local.x][local.y][local.z] = map.get(c); } }
From source file:com.google.polymer.JsRenamer.java
/** * Renames a string node as if the entire string contained the symbol. * @param renameMap A mapping from symbol to renamed symbol. * @param node String node to rename in entirety. Can be null. Will not attempt a rename if the * node is not a string node.//from ww w .j a v a 2 s . co m */ private static void renameStringNode(ImmutableMap<String, String> renameMap, Node node) { if (node == null || !node.isString()) { return; } String symbolName = node.getString(); if (renameMap.containsKey(symbolName)) { node.setString(renameMap.get(symbolName)); } }
From source file:dagger.internal.codegen.FrameworkDependency.java
/** * Groups {@code binding}'s implicit dependencies by their binding key, using the dependency keys * from the {@link Binding#unresolved()} binding if it exists. *//*from w w w. j ava 2s. c o m*/ private static ImmutableList<Collection<DependencyRequest>> groupByUnresolvedKey(Binding binding) { // If the binding has no unresolved version, just group the dependencies by binding key. if (!binding.unresolved().isPresent()) { return groupByKey(binding, Functions.<DependencyRequest>identity()); } // Group the unresolved dependencies, replacing each one with its resolved version by looking it // up by request element. final ImmutableMap<Element, DependencyRequest> resolvedDependencies = Maps .uniqueIndex(binding.implicitDependencies(), new Function<DependencyRequest, Element>() { @Override public Element apply(DependencyRequest dependencyRequest) { return dependencyRequest.requestElement(); } }); return groupByKey(binding.unresolved().get(), new Function<DependencyRequest, DependencyRequest>() { @Override public DependencyRequest apply(DependencyRequest unresolvedRequest) { return resolvedDependencies.get(unresolvedRequest.requestElement()); } }); }
From source file:com.google.idea.blaze.base.sync.projectstructure.ContentEntryEditor.java
private static void walkFileSystem(WorkspaceRoot workspaceRoot, SourceTestConfig testConfig, Collection<WorkspacePath> excludedDirectories, ContentEntry contentEntry, SourceFolderProvider provider, ImmutableMap<VirtualFile, SourceFolder> sourceFolders, SourceFolder parent, VirtualFile file) { if (!file.isDirectory()) { return;//from w w w . j a va 2 s .c o m } WorkspacePath workspacePath; try { workspacePath = workspaceRoot.workspacePathFor(file); } catch (IllegalArgumentException e) { // stop at directories with unhandled characters. return; } if (excludedDirectories.contains(workspacePath)) { return; } boolean isTest = testConfig.isTestSource(workspacePath.relativePath()); SourceFolder current = sourceFolders.get(file); SourceFolder currentOrParent = current != null ? current : parent; if (isTest != currentOrParent.isTestSource()) { currentOrParent = provider.setSourceFolderForLocation(contentEntry, currentOrParent, file, isTest); if (current != null) { contentEntry.removeSourceFolder(current); } } for (VirtualFile child : file.getChildren()) { walkFileSystem(workspaceRoot, testConfig, excludedDirectories, contentEntry, provider, sourceFolders, currentOrParent, child); } }
From source file:com.google.devtools.build.lib.rules.genquery.GenQuery.java
/** * Precomputes the transitive closure of the scope. Returns two maps: one identifying the * successful packages, and the other identifying the valid targets. Breaks in the transitive * closure of the scope will cause the query to error out early. *///from w w w .ja va 2 s . c om @Nullable private static Pair<ImmutableMap<PackageIdentifier, Package>, ImmutableMap<Label, Target>> constructPackageMap( SkyFunction.Environment env, Collection<Target> scope) throws InterruptedException, BrokenQueryScopeException { // It is not necessary for correctness to construct intermediate NestedSets; we could iterate // over individual targets in scope immediately. However, creating a composite NestedSet first // saves us from iterating over the same sub-NestedSets multiple times. NestedSetBuilder<Label> validTargets = NestedSetBuilder.stableOrder(); NestedSetBuilder<PackageIdentifier> successfulPackageNames = NestedSetBuilder.stableOrder(); for (Target target : scope) { SkyKey key = TransitiveTargetValue.key(target.getLabel()); TransitiveTargetValue transNode = (TransitiveTargetValue) env.getValue(key); if (transNode == null) { return null; } if (!transNode.getTransitiveUnsuccessfulPackages().isEmpty()) { // This should only happen if the unsuccessful package was loaded in a non-selected // path, as otherwise this configured target would have failed earlier. See b/34132681. throw new BrokenQueryScopeException( "errors were encountered while computing transitive closure of the scope."); } validTargets.addTransitive(transNode.getTransitiveTargets()); successfulPackageNames.addTransitive(transNode.getTransitiveSuccessfulPackages()); } // Construct the package id to package map for all successful packages. ImmutableMap.Builder<PackageIdentifier, Package> packageMapBuilder = ImmutableMap.builder(); for (PackageIdentifier pkgId : successfulPackageNames.build()) { PackageValue pkg = (PackageValue) env.getValue(PackageValue.key(pkgId)); Preconditions.checkNotNull(pkg, "package %s not preloaded", pkgId); Preconditions.checkState(!pkg.getPackage().containsErrors(), "package %s was found to both have and not have errors.", pkgId); packageMapBuilder.put(pkg.getPackage().getPackageIdentifier(), pkg.getPackage()); } ImmutableMap<PackageIdentifier, Package> packageMap = packageMapBuilder.build(); ImmutableMap.Builder<Label, Target> validTargetsMapBuilder = ImmutableMap.builder(); for (Label label : validTargets.build()) { try { Target target = packageMap.get(label.getPackageIdentifier()).getTarget(label.getName()); validTargetsMapBuilder.put(label, target); } catch (NoSuchTargetException e) { throw new IllegalStateException(e); } } return Pair.of(packageMap, validTargetsMapBuilder.build()); }
From source file:google.registry.model.domain.DomainCommand.java
private static Set<DesignatedContact> linkContacts(Set<ForeignKeyedDesignatedContact> contacts, DateTime now) throws InvalidReferencesException { if (contacts == null) { return null; }//from w ww.j av a 2 s.c om ImmutableSet.Builder<String> foreignKeys = new ImmutableSet.Builder<>(); for (ForeignKeyedDesignatedContact contact : contacts) { foreignKeys.add(contact.contactId); } ImmutableMap<String, Key<ContactResource>> loadedContacts = loadByForeignKey(foreignKeys.build(), ContactResource.class, now); ImmutableSet.Builder<DesignatedContact> linkedContacts = new ImmutableSet.Builder<>(); for (ForeignKeyedDesignatedContact contact : contacts) { linkedContacts.add(DesignatedContact.create(contact.type, loadedContacts.get(contact.contactId))); } return linkedContacts.build(); }
From source file:org.apache.beam.sdk.util.AvroUtils.java
private static Object convertRequiredField(Type avroType, TableFieldSchema fieldSchema, Object v) { // REQUIRED fields are represented as the corresponding Avro types. For example, a BigQuery // INTEGER type maps to an Avro LONG type. checkNotNull(v, "REQUIRED field %s should not be null", fieldSchema.getName()); ImmutableMap<String, Type> fieldMap = ImmutableMap.<String, Type>builder().put("STRING", Type.STRING) .put("INTEGER", Type.LONG).put("FLOAT", Type.DOUBLE).put("BOOLEAN", Type.BOOLEAN) .put("TIMESTAMP", Type.LONG).put("RECORD", Type.RECORD).build(); // Per https://cloud.google.com/bigquery/docs/reference/v2/tables#schema, the type field // is required, so it may not be null. String bqType = fieldSchema.getType(); Type expectedAvroType = fieldMap.get(bqType); verify(avroType == expectedAvroType, "Expected Avro schema type %s, not %s, for BigQuery %s field %s", expectedAvroType, avroType, bqType, fieldSchema.getName()); switch (fieldSchema.getType()) { case "STRING": // Avro will use a CharSequence to represent String objects, but it may not always use // java.lang.String; for example, it may prefer org.apache.avro.util.Utf8. verify(v instanceof CharSequence, "Expected CharSequence (String), got %s", v.getClass()); return v.toString(); case "INTEGER": verify(v instanceof Long, "Expected Long, got %s", v.getClass()); return ((Long) v).toString(); case "FLOAT": verify(v instanceof Double, "Expected Double, got %s", v.getClass()); return v; case "BOOLEAN": verify(v instanceof Boolean, "Expected Boolean, got %s", v.getClass()); return v; case "TIMESTAMP": // TIMESTAMP data types are represented as Avro LONG types. They are converted back to // Strings with variable-precision (up to six digits) to match the JSON files export // by BigQuery. verify(v instanceof Long, "Expected Long, got %s", v.getClass()); Double doubleValue = ((Long) v) / 1000000.0; return formatTimestamp(doubleValue.toString()); case "RECORD": verify(v instanceof GenericRecord, "Expected GenericRecord, got %s", v.getClass()); return convertGenericRecordToTableRow((GenericRecord) v, fieldSchema.getFields()); default:/*from w ww. j a v a 2 s . c o m*/ throw new UnsupportedOperationException( String.format("Unexpected BigQuery field schema type %s for field named %s", fieldSchema.getType(), fieldSchema.getName())); } }
From source file:com.google.devtools.build.lib.standalone.StandaloneSpawnStrategy.java
/** * Adds to the given environment all variables that are dependent on system state of the host * machine.//from www .j a va 2 s. c o m * * <p>Admittedly, hermeticity is "best effort" in such cases; these environment values should be * as tied to configuration parameters as possible. * * <p>For example, underlying iOS toolchains require that SDKROOT resolve to an absolute system * path, but, when selecting which SDK to resolve, the version number comes from build * configuration. * * @return the new environment, comprised of the old environment plus any new variables * @throws UserExecException if any variables dependent on system state could not be resolved */ public static ImmutableMap<String, String> locallyDeterminedEnv(Path execRoot, String productName, ImmutableMap<String, String> env) throws UserExecException { // TODO(bazel-team): Remove apple-specific logic from this class. ImmutableMap.Builder<String, String> newEnvBuilder = ImmutableMap.builder(); newEnvBuilder.putAll(env); // Empty developer dir indicates to use the system default. // TODO(bazel-team): Bazel's view of the xcode version and developer dir // should be explicitly set for build hermiticity. String developerDir = ""; if (env.containsKey(AppleConfiguration.XCODE_VERSION_ENV_NAME)) { developerDir = getDeveloperDir(execRoot, productName, env.get(AppleConfiguration.XCODE_VERSION_ENV_NAME)); newEnvBuilder.put("DEVELOPER_DIR", developerDir); } if (env.containsKey(AppleConfiguration.APPLE_SDK_VERSION_ENV_NAME)) { // The Apple platform is needed to select the appropriate SDK. if (!env.containsKey(AppleConfiguration.APPLE_SDK_PLATFORM_ENV_NAME)) { throw new UserExecException("Could not resolve apple platform for determining SDK"); } String iosSdkVersion = env.get(AppleConfiguration.APPLE_SDK_VERSION_ENV_NAME); String appleSdkPlatform = env.get(AppleConfiguration.APPLE_SDK_PLATFORM_ENV_NAME); newEnvBuilder.put("SDKROOT", getSdkRootEnv(execRoot, productName, developerDir, iosSdkVersion, appleSdkPlatform)); } return newEnvBuilder.build(); }
From source file:com.google.api.codegen.config.ResourceNameOneofConfig.java
@Nullable public static ResourceNameOneofConfig createResourceNameOneof(DiagCollector diagCollector, CollectionOneofProto collectionOneofProto, ImmutableMap<String, SingleResourceNameConfig> singleResourceNameConfigs, ImmutableMap<String, FixedResourceNameConfig> fixedResourceNameConfigs, ProtoFile file) { String oneofName = collectionOneofProto.getOneofName(); if (singleResourceNameConfigs.containsKey(oneofName)) { diagCollector.addDiag(Diag.error(SimpleLocation.TOPLEVEL, "oneof_name \"" + oneofName + "\" already exists in collection configs")); return null; }/* w w w . ja va 2 s . c o m*/ List<ResourceNameConfig> configList = new ArrayList<>(); boolean gotSingleResourceName = false; for (String entityName : collectionOneofProto.getCollectionNamesList()) { ResourceNameConfig resourceNameConfig = singleResourceNameConfigs.get(entityName); if (resourceNameConfig == null) { resourceNameConfig = fixedResourceNameConfigs.get(entityName); } else { gotSingleResourceName = true; } if (resourceNameConfig == null) { diagCollector.addDiag(Diag.error(SimpleLocation.TOPLEVEL, "entity_name \"" + entityName + "\" in collection oneof \"" + oneofName + "\" not found in collection configs")); return null; } configList.add(resourceNameConfig); } if (!gotSingleResourceName) { diagCollector.addDiag(Diag.error(SimpleLocation.TOPLEVEL, "At least one ResourceNameConfig with type SINGLE is required in oneof " + oneofName)); return null; } return new AutoValue_ResourceNameOneofConfig(oneofName, oneofName, configList, file); }
From source file:com.google.auto.value.processor.AutoAnnotationProcessor.java
/** * Returns a map from the names of members with invariable hashCodes to the values of those * hashCodes./* ww w.j a va 2 s . c om*/ */ private static ImmutableMap<String, Integer> invariableHashes(ImmutableMap<String, Member> members, ImmutableSet<String> parameters) { ImmutableMap.Builder<String, Integer> builder = ImmutableMap.builder(); for (String element : members.keySet()) { if (!parameters.contains(element)) { Member member = members.get(element); AnnotationValue annotationValue = member.method.getDefaultValue(); Optional<Integer> invariableHash = invariableHash(annotationValue); if (invariableHash.isPresent()) { builder.put(element, (element.hashCode() * 127) ^ invariableHash.get()); } } } return builder.build(); }