List of usage examples for com.google.common.collect ImmutableBiMap.Builder put
@Override @Nullable V put(@Nullable K key, @Nullable V value);
From source file:com.facebook.buck.cxx.PrefixMapDebugPathSanitizer.java
public PrefixMapDebugPathSanitizer(int pathSize, char separator, Path fakeCompilationDirectory, ImmutableBiMap<Path, Path> other, Path realCompilationDirectory, CxxToolProvider.Type cxxType) { super(separator, pathSize, fakeCompilationDirectory); this.isGcc = cxxType == CxxToolProvider.Type.GCC; this.compilationDir = realCompilationDirectory; ImmutableBiMap.Builder<Path, Path> pathsBuilder = ImmutableBiMap.builder(); // As these replacements are processed one at a time, if one is a prefix (or actually is just // contained in) another, it must be processed after that other one. To ensure that we can // process them in the correct order, they are inserted into allPaths in order of length // (longest first). Then, if they are processed in the order in allPaths, prefixes will be // handled correctly. pathsBuilder.putAll(FluentIterable.from(other.entrySet()).toSortedList( (left, right) -> right.getKey().toString().length() - left.getKey().toString().length())); // We assume that nothing in other is a prefix of realCompilationDirectory (though the reverse // is fine).//from w w w .java 2 s . com pathsBuilder.put(realCompilationDirectory, fakeCompilationDirectory); for (Path p : other.keySet()) { Assertions.assertCondition(!realCompilationDirectory.toString().contains(p.toString())); } this.allPaths = pathsBuilder.build(); }
From source file:dagger.internal.codegen.ComponentDescriptor.java
@Memoized ImmutableBiMap<TypeElement, ComponentDescriptor> subcomponentsByBuilderType() { ImmutableBiMap.Builder<TypeElement, ComponentDescriptor> subcomponentsByBuilderType = ImmutableBiMap .builder();//from www . j ava 2 s . com for (ComponentDescriptor subcomponent : subcomponents()) { if (subcomponent.builderSpec().isPresent()) { subcomponentsByBuilderType.put(subcomponent.builderSpec().get().builderDefinitionType(), subcomponent); } } return subcomponentsByBuilderType.build(); }
From source file:cz.cuni.mff.ms.brodecva.botnicek.ide.design.networks.views.NetworkInternalWindow.java
private BiMap<String, ImageIcon> loadIcons() { final ImmutableBiMap.Builder<String, ImageIcon> iconsBuilder = ImmutableBiMap.builder(); for (final Entry<String, String> iconEntry : iconNamesToPaths.entrySet()) { final String name = iconEntry.getKey(); final String path = iconEntry.getValue(); final URL iconUrl = getClass().getResource(path); if (Presence.isPresent(iconUrl)) { iconsBuilder.put(name, new ImageIcon(iconUrl)); } else {/*w w w. java 2s . c o m*/ LOGGER.log(Level.WARNING, "MissingIcon", path); } } return iconsBuilder.build(); }
From source file:com.android.tools.idea.structure.KeyValuePane.java
public KeyValuePane(@NotNull Project project, @NotNull ModificationListener listener) { myProject = project;/* w w w .jav a2s .co m*/ myListener = listener; LocalSdk sdk = null; AndroidSdkData androidSdkData = AndroidSdkUtils.tryToChooseAndroidSdk(); if (androidSdkData != null) { sdk = androidSdkData.getLocalSdk(); } // Use immutable maps with builders for our built-in value maps because ImmutableBiMap ensures that iteration order is the same as // insertion order. ImmutableBiMap.Builder<String, String> buildToolsMapBuilder = ImmutableBiMap.builder(); ImmutableBiMap.Builder<String, String> apisMapBuilder = ImmutableBiMap.builder(); ImmutableBiMap.Builder<String, String> compiledApisMapBuilder = ImmutableBiMap.builder(); if (sdk != null) { LocalPkgInfo[] buildToolsPackages = sdk.getPkgsInfos(PkgType.PKG_BUILD_TOOLS); for (LocalPkgInfo buildToolsPackage : buildToolsPackages) { if (!(buildToolsPackage instanceof LocalBuildToolPkgInfo)) { continue; } BuildToolInfo buildToolInfo = ((LocalBuildToolPkgInfo) buildToolsPackage).getBuildToolInfo(); if (buildToolInfo == null) { continue; } String buildToolVersion = buildToolInfo.getRevision().toString(); buildToolsMapBuilder.put(buildToolVersion, buildToolVersion); } for (IAndroidTarget target : sdk.getTargets()) { if (target.isPlatform()) { AndroidVersion version = target.getVersion(); String codename = version.getCodename(); String apiString, platformString; if (codename != null) { apiString = codename; platformString = AndroidTargetHash.getPlatformHashString(version); } else { platformString = apiString = Integer.toString(version.getApiLevel()); } String label = AndroidSdkUtils.getTargetLabel(target); apisMapBuilder.put(apiString, label); compiledApisMapBuilder.put(platformString, label); } } } BiMap<String, String> installedBuildTools = buildToolsMapBuilder.build(); BiMap<String, String> installedApis = apisMapBuilder.build(); BiMap<String, String> installedCompileApis = compiledApisMapBuilder.build(); BiMap<String, String> javaCompatibility = ImmutableBiMap.of("JavaVersion.VERSION_1_6", "1.6", "JavaVersion.VERSION_1_7", "1.7"); myKeysWithKnownValues = ImmutableMap.<BuildFileKey, BiMap<String, String>>builder() .put(BuildFileKey.MIN_SDK_VERSION, installedApis) .put(BuildFileKey.TARGET_SDK_VERSION, installedApis) .put(BuildFileKey.COMPILE_SDK_VERSION, installedCompileApis) .put(BuildFileKey.BUILD_TOOLS_VERSION, installedBuildTools) .put(BuildFileKey.SOURCE_COMPATIBILITY, javaCompatibility) .put(BuildFileKey.TARGET_COMPATIBILITY, javaCompatibility).build(); }
From source file:org.eclipse.xtext.xtext.RuleNames.java
public RuleNames(Grammar grammar, boolean installAdapter) { this.contextGrammar = grammar; Adapter adapter = new Adapter(this); if (installAdapter) { installAdapterIfMissing(adapter, grammar); }//from w w w . jav a2 s .c o m List<AbstractRule> allRules = GrammarUtil.allRules(grammar); ImmutableListMultimap.Builder<String, AbstractRule> simpleNameToRulesBuilder = ImmutableListMultimap .builder(); ImmutableMap.Builder<String, AbstractRule> qualifiedNameToRuleBuilder = ImmutableMap.builder(); ImmutableBiMap.Builder<String, AbstractRule> uniqueNameToRuleBuilder = ImmutableBiMap.builder(); ImmutableBiMap.Builder<String, AbstractRule> antlrNameToRuleBuilder = ImmutableBiMap.builder(); Map<String, AbstractRule> names = Maps.newHashMap(); Set<String> usedAntlrNames = Sets.newHashSet(); Set<String> usedUniqueNames = Sets.newHashSet(); for (AbstractRule rule : allRules) { String name = rule.getName(); simpleNameToRulesBuilder.put(name, rule); String qualifiedName = getQualifiedName(rule); qualifiedNameToRuleBuilder.put(qualifiedName, rule); String uniqueName = name; String antlrRuleName; if (names.containsKey(name)) { name = qualifiedName; uniqueName = getInheritedUniqueName(rule, usedUniqueNames); antlrRuleName = getInheritedAntlrRuleName(rule, usedAntlrNames); } else { antlrRuleName = getDefaultAntlrRuleName(rule); } names.put(name, rule); if (!usedUniqueNames.add(uniqueName)) { throw new IllegalStateException(uniqueName); } uniqueNameToRuleBuilder.put(uniqueName, rule); if (!usedAntlrNames.add(antlrRuleName)) { throw new IllegalStateException(antlrRuleName); } antlrNameToRuleBuilder.put(antlrRuleName, rule); if (installAdapter) { installAdapterIfMissing(adapter, rule); } } simpleNameToRules = simpleNameToRulesBuilder.build(); qualifiedNameToRule = qualifiedNameToRuleBuilder.build(); nameToRule = ImmutableBiMap.copyOf(names); uniqueNameToRule = uniqueNameToRuleBuilder.build(); antlrNameToRule = antlrNameToRuleBuilder.build(); this.allRules = ImmutableList.copyOf(allRules); }
From source file:com.facebook.buck.android.AndroidBinaryRule.java
/** * Sets up filtering of resources, images/drawables and strings in particular, based on build * rule parameters {@link #resourceFilter} and {@link #isStoreStringsAsAssets}. * * {@link com.facebook.buck.android.FilterResourcesStep.ResourceFilter} {@code resourceFilter} * determines which drawables end up in the APK (based on density - mdpi, hdpi etc), and also * whether higher density drawables get scaled down to the specified density (if not present). * * {@code isStoreStringsAsAssets} determines whether non-english string resources are packaged * separately as assets (and not bundled together into the {@code resources.arsc} file). *///from ww w . ja v a 2 s . c o m @VisibleForTesting FilterResourcesStep createFilterResourcesStep(Set<String> resourceDirectories) { ImmutableBiMap.Builder<String, String> filteredResourcesDirMapBuilder = ImmutableBiMap.builder(); String resDestinationBasePath = getBinPath("__filtered__%s__"); int count = 0; for (String resDir : resourceDirectories) { filteredResourcesDirMapBuilder.put(resDir, Paths.get(resDestinationBasePath, String.valueOf(count++)).toString()); } ImmutableBiMap<String, String> resSourceToDestDirMap = filteredResourcesDirMapBuilder.build(); FilterResourcesStep.Builder filterResourcesStepBuilder = FilterResourcesStep.builder() .setInResToOutResDirMap(resSourceToDestDirMap).setResourceFilter(resourceFilter); if (isStoreStringsAsAssets()) { filterResourcesStepBuilder.enableStringsFilter(); } return filterResourcesStepBuilder.build(); }
From source file:net.minecrell.ice.launch.transformers.DeobfuscationTransformer.java
public DeobfuscationTransformer() throws Exception { Path path = (Path) Launch.blackboard.get("ice.deobf-srg"); String name = path.getFileName().toString(); boolean gzip = name.endsWith(".gz"); ImmutableBiMap.Builder<String, String> classes = ImmutableBiMap.builder(); ImmutableTable.Builder<String, String, String> fields = ImmutableTable.builder(); ImmutableTable.Builder<String, String, String> methods = ImmutableTable.builder(); try (BufferedReader reader = new BufferedReader(new InputStreamReader( gzip ? new GZIPInputStream(Files.newInputStream(path)) : Files.newInputStream(path), StandardCharsets.UTF_8))) { String line;//w w w . j av a2 s . c o m while ((line = reader.readLine()) != null) { if ((line = line.trim()).isEmpty()) continue; String[] parts = StringUtils.split(line, ' '); if (parts.length < 3) { System.out.println("Invalid line: " + line); continue; } MappingType type = MappingType.of(parts[0]); if (type == null) { System.out.println("Invalid mapping: " + line); continue; } String[] source, dest; switch (type) { case CLASS: classes.put(parts[1], parts[2]); break; case FIELD: source = getSignature(parts[1]); dest = getSignature(parts[2]); String fieldType = getFieldType(source[0], source[1]); fields.put(source[0], source[1] + ':' + fieldType, dest[1]); if (fieldType != null) fields.put(source[0], source[1] + ":null", dest[1]); break; case METHOD: source = getSignature(parts[1]); dest = getSignature(parts[3]); methods.put(source[0], source[1] + parts[2], dest[1]); break; } } } this.classes = classes.build(); this.rawFields = fields.build(); this.rawMethods = methods.build(); this.fields = Maps.newHashMapWithExpectedSize(rawFields.size()); this.methods = Maps.newHashMapWithExpectedSize(rawMethods.size()); }
From source file:org.neptunepowered.vanilla.launch.transformers.DeobfuscationTransformer.java
public DeobfuscationTransformer() throws Exception { URL mappings = (URL) Launch.blackboard.get("vanilla.mappings"); final ImmutableBiMap.Builder<String, String> classes = ImmutableBiMap.builder(); final ImmutableTable.Builder<String, String, String> fields = ImmutableTable.builder(); final ImmutableTable.Builder<String, String, String> methods = ImmutableTable.builder(); readLines(mappings, Charsets.UTF_8, new LineProcessor<Void>() { @Override// w ww .j a v a 2 s.c o m public boolean processLine(String line) throws IOException { if ((line = line.trim()).isEmpty()) { return true; } String[] parts = StringUtils.split(line, ' '); if (parts.length < 3) { NeptuneServerTweaker.getLogger().warn("Invalid deobfuscation mapping line: {}", line); return true; } MappingType type = MappingType.of(parts[0]); if (type == null) { NeptuneServerTweaker.getLogger().warn("Invalid deobfuscation mapping type: {}", line); return true; } String[] source; String[] dest; switch (type) { case CLASS: classes.put(parts[1], parts[2]); break; case FIELD: source = getSignature(parts[1]); dest = getSignature(parts[2]); String fieldType = getFieldType(source[0], source[1]); fields.put(source[0], source[1] + ':' + fieldType, dest[1]); if (fieldType != null) { fields.put(source[0], source[1] + ":null", dest[1]); } break; case METHOD: source = getSignature(parts[1]); dest = getSignature(parts[3]); methods.put(source[0], source[1] + parts[2], dest[1]); break; default: } return true; } @Override public Void getResult() { return null; } }); this.classes = classes.build(); this.rawFields = fields.build(); this.rawMethods = methods.build(); this.fields = Maps.newHashMapWithExpectedSize(this.rawFields.size()); this.methods = Maps.newHashMapWithExpectedSize(this.rawMethods.size()); }
From source file:org.spongepowered.server.launch.transformer.DeobfuscationTransformer.java
public DeobfuscationTransformer() throws Exception { URL mappings = (URL) Launch.blackboard.get("vanilla.mappings"); final ImmutableBiMap.Builder<String, String> classes = ImmutableBiMap.builder(); final ImmutableTable.Builder<String, String, String> fields = ImmutableTable.builder(); final ImmutableTable.Builder<String, String, String> methods = ImmutableTable.builder(); readLines(mappings, Charsets.UTF_8, new LineProcessor<Void>() { @Override/* w w w .ja v a2s . c o m*/ public boolean processLine(String line) throws IOException { if ((line = line.trim()).isEmpty()) { return true; } String[] parts = StringUtils.split(line, ' '); if (parts.length < 3) { VanillaServerTweaker.getLogger().warn("Invalid deobfuscation mapping line: {}", line); return true; } MappingType type = MappingType.of(parts[0]); if (type == null) { VanillaServerTweaker.getLogger().warn("Invalid deobfuscation mapping type: {}", line); return true; } String[] source; String[] dest; switch (type) { case CLASS: classes.put(parts[1], parts[2]); break; case FIELD: source = getSignature(parts[1]); dest = getSignature(parts[2]); String fieldType = getFieldType(source[0], source[1]); fields.put(source[0], source[1] + ':' + fieldType, dest[1]); if (fieldType != null) { fields.put(source[0], source[1] + ":null", dest[1]); } break; case METHOD: source = getSignature(parts[1]); dest = getSignature(parts[3]); methods.put(source[0], source[1] + parts[2], dest[1]); break; default: } return true; } @Override public Void getResult() { return null; } }); this.classes = classes.build(); this.rawFields = fields.build(); this.rawMethods = methods.build(); this.fields = Maps.newHashMapWithExpectedSize(this.rawFields.size()); this.methods = Maps.newHashMapWithExpectedSize(this.rawMethods.size()); }
From source file:org.neptunepowered.vanilla.launch.transformer.DeobfuscationTransformer.java
public DeobfuscationTransformer() throws Exception { URL mappings = (URL) Launch.blackboard.get("vanilla.mappings"); final ImmutableBiMap.Builder<String, String> classes = ImmutableBiMap.builder(); final ImmutableTable.Builder<String, String, String> fields = ImmutableTable.builder(); final ImmutableTable.Builder<String, String, String> methods = ImmutableTable.builder(); readLines(mappings, Charsets.UTF_8, new LineProcessor<Void>() { @Override/*from ww w. jav a2 s . c om*/ public boolean processLine(String line) throws IOException { if ((line = line.trim()).isEmpty()) { return true; } String[] parts = StringUtils.split(line, ' '); if (parts.length < 3) { NeptuneServerTweaker.log.warn("Invalid deobfuscation mapping line: {}", line); return true; } MappingType type = MappingType.of(parts[0]); if (type == null) { NeptuneServerTweaker.log.warn("Invalid deobfuscation mapping type: {}", line); return true; } String[] source; String[] dest; switch (type) { case CLASS: classes.put(parts[1], parts[2]); break; case FIELD: source = getSignature(parts[1]); dest = getSignature(parts[2]); String fieldType = getFieldType(source[0], source[1]); fields.put(source[0], source[1] + ':' + fieldType, dest[1]); if (fieldType != null) { fields.put(source[0], source[1] + ":null", dest[1]); } break; case METHOD: source = getSignature(parts[1]); dest = getSignature(parts[3]); methods.put(source[0], source[1] + parts[2], dest[1]); break; default: } return true; } @Override public Void getResult() { return null; } }); this.classes = classes.build(); this.rawFields = fields.build(); this.rawMethods = methods.build(); this.fields = Maps.newHashMapWithExpectedSize(this.rawFields.size()); this.methods = Maps.newHashMapWithExpectedSize(this.rawMethods.size()); }