List of usage examples for com.google.common.collect ImmutableMap builder
public static <K, V> Builder<K, V> builder()
From source file:ratpack.handlebars.Template.java
public static Template handlebarsTemplate(String name, Consumer<? super ImmutableMap.Builder<String, Object>> modelBuilder) { return handlebarsTemplate(name, null, modelBuilder); }
From source file:com.addthis.cronus.internal.TimePeriod.java
private static ImmutableMap<Pattern, String> buildReplacements(String description) { ImmutableMap.Builder<Pattern, String> builder = ImmutableMap.builder(); switch (description) { case "dayOfWeek": DayOfWeek[] days = DayOfWeek.values(); for (int i = 0; i < days.length; i++) { String needle = days[i].getDisplayName(TextStyle.SHORT, Locale.ENGLISH); builder.put(Pattern.compile(Pattern.quote(needle), Pattern.CASE_INSENSITIVE), Integer.toString(i + 1)); }/* www . j a va 2 s . c om*/ break; case "month": Month[] months = Month.values(); for (int i = 0; i < months.length; i++) { String needle = months[i].getDisplayName(TextStyle.SHORT, Locale.ENGLISH); builder.put(Pattern.compile(Pattern.quote(needle), Pattern.CASE_INSENSITIVE), Integer.toString(i + 1)); } break; } return builder.build(); }
From source file:com.facebook.buck.features.lua.LuaUtil.java
public static ImmutableMap<String, SourcePath> toModuleMap(BuildTarget target, SourcePathResolver resolver, String parameter, String baseModule, Iterable<SourceSortedSet> inputs) { ImmutableMap.Builder<String, SourcePath> moduleNamesAndSourcePaths = ImmutableMap.builder(); for (SourceSortedSet input : inputs) { ImmutableMap<String, SourcePath> namesAndSourcePaths; if (input.getUnnamedSources().isPresent()) { namesAndSourcePaths = resolver.getSourcePathNames(target, parameter, input.getUnnamedSources().get()); } else {/*w w w. ja v a 2s.c o m*/ 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.google.idea.blaze.base.lang.buildfile.language.semantics.BuildLanguageSpec.java
public static BuildLanguageSpec fromProto(Build.BuildLanguage proto) { ImmutableMap.Builder<String, RuleDefinition> builder = ImmutableMap.builder(); for (Build.RuleDefinition rule : proto.getRuleList()) { builder.put(rule.getName(), RuleDefinition.fromProto(rule)); }/*www .j a v a 2s . c o m*/ return new BuildLanguageSpec(builder.build()); }
From source file:org.trancecode.collection.TcMaps.java
public static <K, V> Map<K, V> merge(final Map<K, V> map1, final Map<? extends K, ? extends V> map2) { final Builder<K, V> builder = ImmutableMap.builder(); @SuppressWarnings("unchecked") final Set<K> map2keys = (Set<K>) map2.keySet(); final Predicate<K> keyFilter = Predicates.not(TcPredicates.isContainedBy(map2keys)); final Map<K, V> map1WithoutKeysFromMap2 = Maps.filterKeys(map1, keyFilter); return builder.putAll(map1WithoutKeysFromMap2).putAll(map2).build(); }
From source file:google.registry.tmch.ClaimsListParser.java
/** * Converts the lines from the DNL CSV file into a {@link ClaimsListShard} object. * * <p>Please note that this does <b>not</b> insert the object into the datastore. *//*from www .java 2 s .c o m*/ public static ClaimsListShard parse(List<String> lines) { ImmutableMap.Builder<String, String> builder = new ImmutableMap.Builder<>(); // First line: <version>,<DNL List creation datetime> List<String> firstLine = Splitter.on(',').splitToList(lines.get(0)); checkArgument(firstLine.size() == 2, String.format("Line 1: Expected 2 elements, found %d", firstLine.size())); Integer version = Integer.valueOf(firstLine.get(0)); DateTime creationTime = DateTime.parse(firstLine.get(1)); checkArgument(version == 1, String.format("Line 1: Expected version 1, found %d", version)); // Second line contains headers: DNL,lookup-key,insertion-datetime List<String> secondLine = Splitter.on(',').splitToList(lines.get(1)); checkArgument(secondLine.size() == 3, String.format("Line 2: Expected 3 elements, found %d", secondLine.size())); checkArgument("DNL".equals(secondLine.get(0)), String.format("Line 2: Expected header \"DNL\", found \"%s\"", secondLine.get(0))); checkArgument("lookup-key".equals(secondLine.get(1)), String.format("Line 2: Expected header \"lookup-key\", found \"%s\"", secondLine.get(1))); checkArgument("insertion-datetime".equals(secondLine.get(2)), String.format("Line 2: Expected header \"insertion-datetime\", found \"%s\"", secondLine.get(2))); // Subsequent lines: <DNL>,<lookup key>,<DNL insertion datetime> for (int i = 2; i < lines.size(); i++) { List<String> currentLine = Splitter.on(',').splitToList(lines.get(i)); checkArgument(currentLine.size() == 3, String.format("Line %d: Expected 3 elements, found %d", i + 1, currentLine.size())); String label = currentLine.get(0); String lookupKey = currentLine.get(1); DateTime.parse(currentLine.get(2)); // This is the insertion time, currently unused. builder.put(label, lookupKey); } return ClaimsListShard.create(creationTime, builder.build()); }
From source file:com.google.idea.blaze.base.model.primitives.LanguageClass.java
private static ImmutableMap<String, LanguageClass> extensionToClassMap() { ImmutableMap.Builder<String, LanguageClass> result = ImmutableMap.builder(); for (LanguageClass lang : LanguageClass.values()) { for (String ext : lang.recognizedFilenameExtensions) { result.put(ext, lang);// w ww .j av a2 s . c o m } } return result.build(); }
From source file:com.facebook.buck.apple.RuleUtils.java
/** * Extract the source and header paths and flags from the input list * and populate the output collections.//from w w w . ja va 2s .c om * * @param outputSources The ordered tree of sources, headers, and groups (as * they should appear in a generated Xcode project) will be added to * this builder. * @param outputPerFileFlags per file flags will be added to this builder * @param items input list of sources */ public static void extractSourcePaths(ImmutableList.Builder<GroupedSource> outputSources, ImmutableMap.Builder<SourcePath, String> outputPerFileFlags, ImmutableList<AppleSource> items) { for (AppleSource item : items) { switch (item.getType()) { case SOURCE_PATH: outputSources.add(GroupedSource.ofSourcePath(item.getSourcePath())); break; case SOURCE_PATH_WITH_FLAGS: Pair<SourcePath, String> pair = item.getSourcePathWithFlags(); outputSources.add(GroupedSource.ofSourcePath(pair.getFirst())); outputPerFileFlags.put(pair.getFirst(), pair.getSecond()); break; case SOURCE_GROUP: Pair<String, ImmutableList<AppleSource>> sourceGroup = item.getSourceGroup(); String sourceGroupName = sourceGroup.getFirst(); ImmutableList<AppleSource> sourceGroupItems = sourceGroup.getSecond(); ImmutableList.Builder<GroupedSource> nestedSourceGroups = ImmutableList.builder(); extractSourcePaths(nestedSourceGroups, outputPerFileFlags, sourceGroupItems); outputSources.add(GroupedSource.ofSourceGroup(sourceGroupName, nestedSourceGroups.build())); break; default: throw new RuntimeException("Unhandled AppleSource item type: " + item.getType()); } } }
From source file:org.sonar.server.computation.task.projectanalysis.api.posttask.ScannerContextImpl.java
static ScannerContextImpl from(CloseableIterator<ScannerReport.ContextProperty> it) { try {/*from w ww. ja va 2s . c o m*/ ImmutableMap.Builder<String, String> mapBuilder = ImmutableMap.builder(); while (it.hasNext()) { ScannerReport.ContextProperty prop = it.next(); mapBuilder.put(prop.getKey(), prop.getValue()); } return new ScannerContextImpl(mapBuilder.build()); } finally { it.close(); } }
From source file:com.google.idea.blaze.base.lang.projectview.language.ProjectViewKeywords.java
private static ImmutableMap<String, ListSectionParser> getListKeywordMap() { ImmutableMap.Builder<String, ListSectionParser> builder = ImmutableMap.builder(); for (SectionParser parser : Sections.getParsers()) { if (parser instanceof ListSectionParser) { builder.put(parser.getName(), (ListSectionParser) parser); }//w ww . j a va 2 s .c om } return builder.build(); }