List of usage examples for com.google.common.collect ImmutableMap containsKey
@Override public boolean containsKey(@Nullable Object key)
From source file:com.google.devtools.build.lib.rules.cpp.FeatureSelection.java
FeatureSelection(ImmutableSet<String> requestedFeatures, ImmutableMap<String, CrosstoolSelectable> selectablesByName, ImmutableList<CrosstoolSelectable> selectables, ImmutableMultimap<String, CrosstoolSelectable> provides, ImmutableMultimap<CrosstoolSelectable, CrosstoolSelectable> implies, ImmutableMultimap<CrosstoolSelectable, CrosstoolSelectable> impliedBy, ImmutableMultimap<CrosstoolSelectable, ImmutableSet<CrosstoolSelectable>> requires, ImmutableMultimap<CrosstoolSelectable, CrosstoolSelectable> requiredBy, ImmutableMap<String, ActionConfig> actionConfigsByActionName) { ImmutableSet.Builder<CrosstoolSelectable> builder = ImmutableSet.builder(); for (String name : requestedFeatures) { if (selectablesByName.containsKey(name)) { builder.add(selectablesByName.get(name)); }/*from ww w .ja v a 2 s .c o m*/ } this.requestedSelectables = builder.build(); this.selectables = selectables; this.provides = provides; this.implies = implies; this.impliedBy = impliedBy; this.requires = requires; this.requiredBy = requiredBy; this.actionConfigsByActionName = actionConfigsByActionName; }
From source file:org.sonar.java.it.ProfileGenerator.java
static void generate(Orchestrator orchestrator, String language, String repositoryKey, ImmutableMap<String, ImmutableMap<String, String>> rulesParameters, Set<String> excluded, Set<String> subsetOfEnabledRules, Set<String> activatedRuleKeys) { try {//from ww w . j av a 2 s .co m StringBuilder sb = new StringBuilder().append("<profile>").append("<name>rules</name>") .append("<language>").append(language).append("</language>").append("<alerts>") .append("<alert>").append("<metric>blocker_violations</metric>") .append("<operator>></operator>").append("<warning></warning>").append("<error>0</error>") .append("</alert>").append("<alert>").append("<metric>info_violations</metric>") .append("<operator>></operator>").append("<warning></warning>").append("<error>0</error>") .append("</alert>").append("</alerts>").append("<rules>"); List<String> ruleKeys = Lists.newArrayList(); String json = new HttpRequestFactory(orchestrator.getServer().getUrl()).get("/api/rules/search", ImmutableMap.<String, Object>of("languages", language, "repositories", repositoryKey, "ps", "1000")); @SuppressWarnings("unchecked") List<Map> jsonRules = (List<Map>) ((Map) JSONValue.parse(json)).get("rules"); for (Map jsonRule : jsonRules) { String key = (String) jsonRule.get("key"); ruleKeys.add(key.split(":")[1]); } for (String key : ruleKeys) { if (excluded.contains(key) || (!subsetOfEnabledRules.isEmpty() && !subsetOfEnabledRules.contains(key))) { continue; } activatedRuleKeys.add(key); sb.append("<rule>").append("<repositoryKey>").append(repositoryKey).append("</repositoryKey>") .append("<key>").append(key).append("</key>").append("<priority>INFO</priority>"); if (rulesParameters.containsKey(key)) { sb.append("<parameters>"); for (Map.Entry<String, String> parameter : rulesParameters.get(key).entrySet()) { sb.append("<parameter>").append("<key>").append(parameter.getKey()).append("</key>") .append("<value>").append(parameter.getValue()).append("</value>") .append("</parameter>"); } sb.append("</parameters>"); } sb.append("</rule>"); } sb.append("</rules>").append("</profile>"); File file = File.createTempFile("profile", ".xml"); Files.write(sb, file, StandardCharsets.UTF_8); orchestrator.getServer().restoreProfile(FileLocation.of(file)); file.delete(); } catch (IOException e) { throw Throwables.propagate(e); } }
From source file:com.aitorvs.autoparcel.internal.codegen.AutoParcelProcessor.java
private MethodSpec generateWriteToParcel(int version, ProcessingEnvironment env, ImmutableList<Property> properties, ImmutableMap<TypeMirror, FieldSpec> typeAdapters) { ParameterSpec dest = ParameterSpec.builder(ClassName.get("android.os", "Parcel"), "dest").build(); ParameterSpec flags = ParameterSpec.builder(int.class, "flags").build(); MethodSpec.Builder builder = MethodSpec.methodBuilder("writeToParcel").addAnnotation(Override.class) .addModifiers(PUBLIC).addParameter(dest).addParameter(flags); // write first the parcelable object version... builder.addCode(Parcelables.writeVersion(version, dest)); // ...then write all the properties for (Property p : properties) { if (p.typeAdapter != null && typeAdapters.containsKey(p.typeAdapter)) { FieldSpec typeAdapter = typeAdapters.get(p.typeAdapter); builder.addCode(Parcelables.writeValueWithTypeAdapter(typeAdapter, p, dest)); } else {//from w ww . j a v a 2 s . com builder.addCode(Parcelables.writeValue(p, dest, flags, env.getTypeUtils())); } } return builder.build(); }
From source file:org.elasticsearch.index.gateway.blobstore.BlobStoreIndexShardGateway.java
private boolean commitPointFileExistsInBlobs(CommitPoint.FileInfo fileInfo, ImmutableMap<String, BlobMetaData> blobs) { BlobMetaData blobMetaData = blobs.get(fileInfo.name()); if (blobMetaData != null) { if (blobMetaData.length() != fileInfo.length()) { return false; }/* w w w. jav a2 s . c om*/ } else if (blobs.containsKey(fileInfo.name() + ".part0")) { // multi part file sum up the size and check int part = 0; long totalSize = 0; while (true) { blobMetaData = blobs.get(fileInfo.name() + ".part" + part++); if (blobMetaData == null) { break; } totalSize += blobMetaData.length(); } if (totalSize != fileInfo.length()) { return false; } } else { // no file, not exact and not multipart return false; } return true; }
From source file:com.facebook.buck.android.AndroidBinaryBuildable.java
private void processModule(APKModule module, ImmutableSet.Builder<Path> nativeLibraryDirectoriesBuilder, ImmutableSet.Builder<Path> nativeLibraryAsAssetDirectories, ImmutableSet.Builder<Path> moduleResourcesDirectories, ImmutableList.Builder<Step> steps, SourcePathResolver pathResolver, BuildContext context, ImmutableMap<String, SourcePath> mapOfModuleToSecondaryDexSourcePaths, ModuleInfo.Builder baseModuleInfo, ImmutableSet.Builder<ModuleInfo> modulesInfo) { boolean addThisModule = false; ImmutableMap.Builder<Path, String> assetDirectoriesBuilderForThisModule = ImmutableMap.builder(); ImmutableSet.Builder<Path> nativeLibraryDirectoriesBuilderForThisModule = ImmutableSet.builder(); Path resourcesDirectoryForThisModule = null; ImmutableSet.Builder<Path> dexFileDirectoriesBuilderForThisModule = ImmutableSet.builder(); if (mapOfModuleToSecondaryDexSourcePaths.containsKey(module.getName())) { addDexFileDirectories(pathResolver, module, mapOfModuleToSecondaryDexSourcePaths, dexFileDirectoriesBuilderForThisModule, assetDirectoriesBuilderForThisModule); }//from w w w . j a v a 2 s. com boolean shouldPackageAssetLibraries = packageAssetLibraries || !module.isRootModule(); if (!ExopackageMode.enabledForNativeLibraries(exopackageModes) && nativeFilesInfo.nativeLibsDirs.isPresent() && nativeFilesInfo.nativeLibsDirs.get().containsKey(module)) { addThisModule = true; addNativeDirectory(shouldPackageAssetLibraries, module, pathResolver, nativeLibraryDirectoriesBuilder, nativeLibraryDirectoriesBuilderForThisModule); } if (shouldPackageAssetLibraries) { addThisModule = true; addNativeLibraryAsAssetDirectory(module, context, nativeLibraryAsAssetDirectories, assetDirectoriesBuilderForThisModule, steps); } if (moduleResourceApkPaths.get(module) != null) { addThisModule = true; resourcesDirectoryForThisModule = addModuleResourceDirectory(module, context, moduleResourcesDirectories, steps); } if (!addThisModule || isApk) { return; } if (module.isRootModule()) { baseModuleInfo.putAllAssetDirectories(assetDirectoriesBuilderForThisModule.build()) .addAllNativeLibraryDirectories(nativeLibraryDirectoriesBuilderForThisModule.build()) .addAllDexFile(dexFileDirectoriesBuilderForThisModule.build()); } else { String moduleName = module.getName(); modulesInfo.add(ModuleInfo.of(moduleName, resourcesDirectoryForThisModule, dexFileDirectoriesBuilderForThisModule.build(), assetDirectoriesBuilderForThisModule.build(), nativeLibraryDirectoriesBuilderForThisModule.build(), ImmutableSet.<Path>builder().build(), ImmutableSet.<Path>builder().build())); } }
From source file:com.facebook.buck.cli.BuckConfig.java
/** * A set of paths to subtrees that do not contain source files, build files or files that could * affect either (buck-out, .idea, .buckd, buck-cache, .git, etc.). May return absolute paths * as well as relative paths.// w w w . j a va 2 s.c o m */ public ImmutableSet<Path> getIgnorePaths() { final ImmutableMap<String, String> projectConfig = getEntriesForSection("project"); final String ignoreKey = "ignore"; ImmutableSet.Builder<Path> builder = ImmutableSet.builder(); builder.add(Paths.get(BuckConstant.BUCK_OUTPUT_DIRECTORY)); builder.add(Paths.get(".idea")); // Take care not to ignore absolute paths. Path buckdDir = Paths.get(System.getProperty(BUCK_BUCKD_DIR_KEY, ".buckd")); Path cacheDir = getCacheDir(); for (Path path : ImmutableList.of(buckdDir, cacheDir)) { if (!path.toString().isEmpty()) { builder.add(path); } } if (projectConfig.containsKey(ignoreKey)) { builder.addAll(MorePaths.asPaths( Splitter.on(',').omitEmptyStrings().trimResults().split(projectConfig.get(ignoreKey)))); } // Normalize paths in order to eliminate trailing '/' characters and whatnot. return builder.build(); }
From source file:org.zanata.client.commands.push.RawPushCommand.java
/** * Validate file extensions/*from w w w .j a v a 2 s . co m*/ * @param inputFileType * @param userExtensions * @param acceptedTypes */ private void validateFileExtensions(@Nullable FileTypeName inputFileType, ImmutableMap<String, String> userExtensions, List<FileTypeInfo> acceptedTypes) { if (inputFileType != null) { return; } // if file type is missing but extensions are present, try to provide // a helpful error message if (userExtensions.isEmpty()) { //throw error if inputFileType and inputExtensions is empty throw new InvalidUserInputException("Invalid expression for '--file-types' option"); } else { //suggest --file-types options for this extension for (FileTypeInfo docType : acceptedTypes) { for (String srcExt : docType.getSourceExtensions()) { if (userExtensions.containsKey(srcExt)) { String msg = Messages.format("file.type.suggestFromExtension", docType, srcExt, docType); throw new InvalidUserInputException(msg); } } } throw new InvalidUserInputException("Invalid expression for '--file-types' option"); } }
From source file:com.facebook.buck.shell.AbstractGenruleStep.java
@Override public ImmutableMap<String, String> getEnvironmentVariables(ExecutionContext context) { ImmutableMap.Builder<String, String> allEnvironmentVariablesBuilder = ImmutableMap.builder(); addEnvironmentVariables(context, allEnvironmentVariablesBuilder); ImmutableMap<String, String> allEnvironmentVariables = allEnvironmentVariablesBuilder.build(); // Long lists of environment variables can extend the length of the command such that it exceeds // exec()'s ARG_MAX limit. Defend against this by filtering out variables that do not appear in // the command string. String command = getCommandAndExecutionArgs(context).command; ImmutableMap.Builder<String, String> usedEnvironmentVariablesBuilder = ImmutableMap.builder(); for (Map.Entry<String, String> environmentVariable : allEnvironmentVariables.entrySet()) { // We check for the presence of the variable without adornment for $ or %% so it works on both // Windows and non-Windows environments. Eventually, we will require $ in the command string // and modify the command directly rather than using environment variables. String environmentVariableName = environmentVariable.getKey(); if (command.contains(environmentVariableName)) { // I hate this $DEPS variable so much... if ("DEPS".equals(environmentVariableName) && allEnvironmentVariables.containsKey("GEN_DIR")) { usedEnvironmentVariablesBuilder.put("GEN_DIR", allEnvironmentVariables.get("GEN_DIR")); }//from w w w .jav a 2 s .c o m usedEnvironmentVariablesBuilder.put(environmentVariable); } } return usedEnvironmentVariablesBuilder.build(); }
From source file:org.apache.hadoop.hive.metastore.PartitionProjectionEvaluator.java
public PartitionProjectionEvaluator(PersistenceManager pm, ImmutableMap<String, String> fieldNameToTableName, List<String> projectionFields, boolean convertMapNullsToEmptyStrings, boolean isView, String includeParamKeyPattern, String excludeParamKeyPattern) throws MetaException { this.pm = pm; this.fieldNameToTableName = fieldNameToTableName; this.convertMapNullsToEmptyStrings = convertMapNullsToEmptyStrings; this.isView = isView; this.includeParamKeyPattern = includeParamKeyPattern; this.excludeParamKeyPattern = excludeParamKeyPattern; this.PARTITIONS = fieldNameToTableName.containsKey("PARTITIONS_TABLE_NAME") ? fieldNameToTableName.get("PARTITIONS_TABLE_NAME") : "PARTITIONS"; this.SDS = fieldNameToTableName.containsKey("SDS_TABLE_NAME") ? fieldNameToTableName.get("SDS_TABLE_NAME") : "SDS"; this.SERDES = fieldNameToTableName.containsKey("SERDES_TABLE_NAME") ? fieldNameToTableName.get("SERDES_TABLE_NAME") : "SERDES"; this.PARTITION_PARAMS = fieldNameToTableName.containsKey("PARTITION_PARAMS") ? fieldNameToTableName.get("PARTITION_PARAMS") : "PARTITION_PARAMS"; roots = parse(projectionFields);/*from w ww . ja v a 2s. c o m*/ // we always query PART_ID roots.add(partIdNode); if (find(SD_PATTERN)) { roots.add(sdIdNode); } if (find(SERDE_PATTERN)) { roots.add(serdeIdNode); } if (find(CD_PATTERN)) { roots.add(cdIdNode); } }
From source file:com.aitorvs.autoparcel.internal.codegen.AutoParcelProcessor.java
private MethodSpec generateConstructorFromParcel(ProcessingEnvironment env, ImmutableList<Property> properties, ImmutableMap<TypeMirror, FieldSpec> typeAdapters) { // Create the PRIVATE constructor from Parcel MethodSpec.Builder builder = MethodSpec.constructorBuilder().addModifiers(PRIVATE) // private .addParameter(ClassName.bestGuess("android.os.Parcel"), "in"); // input param // get a code block builder CodeBlock.Builder block = CodeBlock.builder(); // First thing is reading the Parcelable object version block.add("this.version = in.readInt();\n"); // FIXME: 31/07/16 remove if not used boolean requiresSuppressWarnings = false; // Now, iterate all properties, check the version initialize them for (Property p : properties) { // get the property version int pVersion = p.version(); if (pVersion > 0) { block.beginControlFlow("if (this.version >= $L)", pVersion); }// w w w. j ava2 s .com block.add("this.$N = ", p.fieldName); if (p.typeAdapter != null && typeAdapters.containsKey(p.typeAdapter)) { Parcelables.readValueWithTypeAdapter(block, p, typeAdapters.get(p.typeAdapter)); } else { requiresSuppressWarnings |= Parcelables.isTypeRequiresSuppressWarnings(p.typeName); TypeName parcelableType = Parcelables.getTypeNameFromProperty(p, env.getTypeUtils()); Parcelables.readValue(block, p, parcelableType); } block.add(";\n"); if (pVersion > 0) { block.endControlFlow(); } } builder.addCode(block.build()); return builder.build(); }