List of usage examples for com.google.common.collect ImmutableMap builder
public static <K, V> Builder<K, V> builder()
From source file:org.quickgeo.generate.Generate.java
License:asdf
private static ImmutableMap<String, InputStream> convertToStreams(ImmutableMap<String, File> map) { ImmutableMap.Builder<String, InputStream> builder = new ImmutableMap.Builder<String, InputStream>(); for (Entry<String, File> entry : map.entrySet()) { String cc = entry.getKey(); File zipFile = entry.getValue(); try {/*from w w w .j a va 2 s.co m*/ ZipFile zf = new ZipFile(zipFile); ZipEntry ze = zf.getEntry(cc + ".txt"); if (ze != null) { builder.put(cc, zf.getInputStream(ze)); } } catch (Exception ex) { Settings.getSettings().getLogger().log(Level.WARNING, "Couldn't parse entry for " + cc, ex); } } return builder.build(); }
From source file:com.facebook.buck.cxx.CxxCompilableEnhancer.java
/** * Resolve the map of names to SourcePaths to a map of names to CxxSource objects. *///from w w w . j a v a2s . com public static ImmutableMap<String, CxxSource> resolveCxxSources(ImmutableMap<String, SourceWithFlags> sources) { ImmutableMap.Builder<String, CxxSource> cxxSources = ImmutableMap.builder(); // For each entry in the input C/C++ source, build a CxxSource object to wrap // it's name, input path, and output object file path. for (ImmutableMap.Entry<String, SourceWithFlags> ent : sources.entrySet()) { String extension = Files.getFileExtension(ent.getKey()); Optional<CxxSource.Type> type = CxxSource.Type.fromExtension(extension); if (!type.isPresent()) { throw new HumanReadableException("invalid extension \"%s\": %s", extension, ent.getKey()); } cxxSources.put(ent.getKey(), CxxSource.of(type.get(), ent.getValue().getSourcePath(), ent.getValue().getFlags())); } return cxxSources.build(); }
From source file:com.spotify.metrics.remote.SemanticAggregator.java
public static Map<String, String> buildAttributes(MetricId id, String type) { ImmutableMap.Builder<String, String> builder = ImmutableMap.builder(); builder.putAll(id.getTags());/*from w ww.j a va2 s . c o m*/ builder.put("metric_type", type); return builder.build(); }
From source file:com.facebook.buck.android.ProguardMapping.java
public static Map<String, String> readClassMapping(Iterable<String> lines) { ImmutableMap.Builder<String, String> classMappingBuilder = ImmutableMap.builder(); for (String line : lines) { if (line.charAt(0) == ' ') { // This is a member mapping, which we don't handle yet. continue; }/*from ww w .ja va2 s. c o m*/ Matcher matcher = CLASS_LINE_PATTERN.matcher(line); if (!matcher.matches()) { throw new IllegalArgumentException("Invalid line in proguard mapping: " + line); } classMappingBuilder.put(matcher.group(1), matcher.group(2)); } return classMappingBuilder.build(); }
From source file:com.facebook.buck.core.build.engine.manifest.ManifestUtil.java
public static ImmutableMap<RuleKey, ImmutableMap<String, HashCode>> toMap(Manifest manifest) { Builder<RuleKey, ImmutableMap<String, HashCode>> builder = ImmutableMap.builder(); for (Pair<RuleKey, int[]> entry : manifest.entries) { Builder<String, HashCode> entryBuilder = ImmutableMap.builder(); for (int hashIndex : entry.getSecond()) { Pair<Integer, HashCode> hashEntry = manifest.hashes.get(hashIndex); String input = manifest.inputs.get(hashEntry.getFirst()); HashCode inputHash = hashEntry.getSecond(); entryBuilder.put(input, inputHash); }//w w w . j a v a2 s .c o m builder.put(entry.getFirst(), entryBuilder.build()); } return builder.build(); }
From source file:com.facebook.buck.lua.LuaUtil.java
public static ImmutableMap<String, SourcePath> toModuleMap(BuildTarget target, SourcePathResolver resolver, String parameter, String baseModule, Iterable<SourceList> inputs) { ImmutableMap.Builder<String, SourcePath> moduleNamesAndSourcePaths = ImmutableMap.builder(); for (SourceList input : inputs) { ImmutableMap<String, SourcePath> namesAndSourcePaths; if (input.getUnnamedSources().isPresent()) { namesAndSourcePaths = resolver.getSourcePathNames(target, parameter, input.getUnnamedSources().get()); } else {// w w w . j ava 2 s. com namesAndSourcePaths = input.getNamedSources().get(); } for (ImmutableMap.Entry<String, SourcePath> entry : namesAndSourcePaths.entrySet()) { String name = entry.getKey(); if (!baseModule.isEmpty()) { name = baseModule + '/' + name; } moduleNamesAndSourcePaths.put(name, entry.getValue()); } } return moduleNamesAndSourcePaths.build(); }
From source file:com.facebook.buck.util.ProcessExecutorSerializer.java
public static ImmutableMap<String, Object> serialize(ProcessExecutor executor) { ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder(); if (executor instanceof DefaultProcessExecutor) { builder.put(TYPE, TYPE_DEFAULT); } else if (executor instanceof ContextualProcessExecutor) { builder.put(TYPE, TYPE_CONTEXTUAL); ContextualProcessExecutor contextualProcessExecutor = (ContextualProcessExecutor) executor; builder.put(CONTEXT, contextualProcessExecutor.getContext()); builder.put(DELEGATE, serialize(contextualProcessExecutor.getDelegate())); } else {// w ww. j av a 2 s . c o m throw new RuntimeException( String.format("Cannot serialize ProcessExecutor with class %s", executor.getClass())); } return builder.build(); }
From source file:com.facebook.buck.jvm.java.ClassUsageFileWriterSerializer.java
public static ImmutableMap<String, Object> serialize(ClassUsageFileWriter writer) { ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder(); if (writer instanceof DefaultClassUsageFileWriter) { builder.put(TYPE, TYPE_DEFAULT); builder.put(RELATIVE_PATH, ((DefaultClassUsageFileWriter) writer).getRelativePath().toString()); } else if (writer instanceof NoOpClassUsageFileWriter) { builder.put(TYPE, TYPE_NOOP);//from w w w.j a v a2 s . co m } else { throw new UnsupportedOperationException( String.format("Cannot serialize ClassUsageFileWriter with class: %s", writer.getClass())); } return builder.build(); }
From source file:com.facebook.buck.core.graph.transformation.TransformationStageMap.java
static TransformationStageMap from(ImmutableList<GraphTransformationStage<?, ?>> stages) { ImmutableMap.Builder<Class<? extends ComputeKey<?>>, GraphTransformationStage<?, ?>> mapBuilder = ImmutableMap .builderWithExpectedSize(stages.size()); for (GraphTransformationStage<?, ?> stage : stages) { mapBuilder.put(stage.getKeyClass(), stage); }// w w w. ja v a 2 s . com return new TransformationStageMap(mapBuilder.build()); }
From source file:com.google.polymer.PolymerRenamer.java
private static ImmutableMap<String, String> getRenameMap(String inputFilename) throws FileNotFoundException { try (Scanner s = new Scanner(new File(inputFilename))) { ImmutableMap.Builder<String, String> renameMapBuilder = ImmutableMap.builder(); while (s.hasNextLine()) { String line = s.nextLine(); String[] components = line.split(":"); if (components.length == 2) { renameMapBuilder.put(components[0], components[1]); }//from w w w . j av a 2 s . c o m } return renameMapBuilder.build(); } }