List of usage examples for com.google.common.collect ImmutableMap builder
public static <K, V> Builder<K, V> builder()
From source file:org.onos.yangtools.yang.binding.util.AbstractMappedRpcInvoker.java
protected AbstractMappedRpcInvoker(final Map<T, Method> map) { final Builder<T, RpcMethodInvoker> b = ImmutableMap.builder(); for (Entry<T, Method> e : map.entrySet()) { if (BindingReflections.isRpcMethod(e.getValue())) { b.put(e.getKey(), RpcMethodInvoker.from(e.getValue())); } else {//from ww w . j a v a 2 s . c o m LOG.debug("Method {} is not an RPC method, ignoring it", e.getValue()); } } this.map = b.build(); }
From source file:com.facebook.buck.apple.AppleToolchainDiscovery.java
/** * Given a path to an Xcode developer directory, walks through the * toolchains and builds a map of (identifier: path) pairs of the * toolchains inside./* w ww .j a v a 2 s . c o m*/ */ public static ImmutableMap<String, AppleToolchain> discoverAppleToolchains(Optional<Path> developerDir, ImmutableList<Path> extraDirs) throws IOException { ImmutableMap.Builder<String, AppleToolchain> toolchainIdentifiersToToolchainsBuilder = ImmutableMap .builder(); HashSet<Path> toolchainPaths = new HashSet<Path>(extraDirs); if (developerDir.isPresent()) { Path toolchainsDir = developerDir.get().resolve("Toolchains"); LOG.debug("Searching for Xcode toolchains under %s", toolchainsDir); toolchainPaths.add(toolchainsDir); } for (Path toolchains : toolchainPaths) { if (!Files.exists(toolchains)) { LOG.debug("Skipping toolchain search path %s that does not exist", toolchains); continue; } LOG.debug("Searching for Xcode toolchains in %s", toolchains); try (DirectoryStream<Path> toolchainStream = Files.newDirectoryStream(toolchains, "*.xctoolchain")) { for (Path toolchainPath : toolchainStream) { LOG.debug("Getting identifier for for Xcode toolchain under %s", toolchainPath); addIdentifierForToolchain(toolchainPath, toolchainIdentifiersToToolchainsBuilder); } } } return toolchainIdentifiersToToolchainsBuilder.build(); }
From source file:io.datty.unit.UnitRecord.java
public UnitRecord(String minorKey, UnitValue value) { ImmutableMap.Builder<String, UnitValue> builder = ImmutableMap.builder(); if (value != null) { builder.put(minorKey, value);/*from w w w. j a va 2s. c o m*/ } this.columnMap = builder.build(); this.version = 1L; }
From source file:org.opendaylight.yangtools.yang.data.util.ChoiceNodeContextNode.java
protected ChoiceNodeContextNode(final ChoiceSchemaNode schema) { super(NodeIdentifier.create(schema.getQName()), schema); ImmutableMap.Builder<QName, DataSchemaContextNode<?>> byQNameBuilder = ImmutableMap.builder(); ImmutableMap.Builder<PathArgument, DataSchemaContextNode<?>> byArgBuilder = ImmutableMap.builder(); for (ChoiceCaseNode caze : schema.getCases()) { for (DataSchemaNode cazeChild : caze.getChildNodes()) { DataSchemaContextNode<?> childOp = fromDataSchemaNode(cazeChild); byArgBuilder.put(childOp.getIdentifier(), childOp); for (QName qname : childOp.getQNameIdentifiers()) { byQNameBuilder.put(qname, childOp); }/*from w ww. j a va2s .c om*/ } } byQName = byQNameBuilder.build(); byArg = byArgBuilder.build(); }
From source file:org.terasology.web.servlet.LogServlet.java
@GET @Path("log") @Produces(MediaType.TEXT_HTML)/* ww w . j a v a2s . com*/ public Viewable log() { logger.info("Requested logs as HTML"); ImmutableMap<Object, Object> dataModel = ImmutableMap.builder().put("version", VersionInfo.getVersion()) .build(); return new Viewable("/log.ftl", dataModel); }
From source file:com.googlesource.gerrit.plugins.lfs.LfsGlobalConfig.java
public Map<String, LfsBackend> getBackends() { ImmutableMap.Builder<String, LfsBackend> builder = ImmutableMap.builder(); for (LfsBackendType type : LfsBackendType.values()) { Map<String, LfsBackend> backendsOfType = cfg.getSubsections(type.name()).stream() .collect(toMap(name -> name, name -> LfsBackend.create(name, type))); builder.putAll(backendsOfType);// w w w .j ava 2 s . c o m } return builder.build(); }
From source file:com.google.template.soy.shared.internal.InternalPlugins.java
public static ImmutableMap<String, SoyFunction> fromLegacyFunctions(Iterable<? extends SoyFunction> functions) { ImmutableMap.Builder<String, SoyFunction> builder = ImmutableMap.builder(); for (SoyFunction function : functions) { builder.put(function.getName(), function); }//from ww w .j av a 2 s .c o m return builder.build(); }
From source file:shaded.org.openqa.selenium.remote.server.handler.GetSessionLogsHandler.java
@Override public Map<String, SessionLogs> handle() throws Exception { ImmutableMap.Builder<String, SessionLogs> builder = ImmutableMap.<String, SessionLogs>builder(); for (SessionId sessionId : LoggingManager.perSessionLogHandler().getLoggedSessions()) { builder.put(sessionId.toString(), LoggingManager.perSessionLogHandler().getAllLogsForSession(sessionId)); }/*w w w . j av a 2s . c om*/ return builder.build(); }
From source file:com.facebook.buck.versions.NaiveVersionSelector.java
@Override public ImmutableMap<BuildTarget, Version> resolve(BuildTarget root, ImmutableMap<BuildTarget, ImmutableSet<Version>> domain) throws VersionException { ImmutableMap.Builder<BuildTarget, Version> selectedVersions = ImmutableMap.builder(); for (Map.Entry<BuildTarget, ImmutableSet<Version>> ent : domain.entrySet()) { selectedVersions.put(ent.getKey(), Iterables.get(ent.getValue(), 0)); }//from ww w. j a v a 2 s . com return selectedVersions.build(); }
From source file:com.google.thirdparty.publicsuffix.TrieParser.java
/** * Parses a trie node and returns the number of characters consumed. * * @param stack The prefixes that preceed the characters represented by this * node. Each entry of the stack is in reverse order. * @param encoded The serialized trie./*from w w w .j a v a 2 s . c o m*/ * @param builder A map builder to which all entries will be added. * @return The number of characters consumed from {@code encoded}. */ private static int doParseTrieToBuilder(List<CharSequence> stack, CharSequence encoded, ImmutableMap.Builder<String, PublicSuffixType> builder) { int encodedLen = encoded.length(); int idx = 0; char c = '\0'; // Read all of the characters for this node. for (; idx < encodedLen; idx++) { c = encoded.charAt(idx); if (c == '&' || c == '?' || c == '!' || c == ':' || c == ',') { break; } } stack.add(0, reverse(encoded.subSequence(0, idx))); if (c == '!' || c == '?' || c == ':' || c == ',') { // '!' represents an interior node that represents an ICANN entry in the map. // '?' represents a leaf node, which represents an ICANN entry in map. // ':' represents an interior node that represents a private entry in the map // ',' represents a leaf node, which represents a private entry in the map. String domain = PREFIX_JOINER.join(stack); if (domain.length() > 0) { builder.put(domain, PublicSuffixType.fromCode(c)); } } idx++; if (c != '?' && c != ',') { while (idx < encodedLen) { // Read all the children idx += doParseTrieToBuilder(stack, encoded.subSequence(idx, encodedLen), builder); if (encoded.charAt(idx) == '?' || encoded.charAt(idx) == ',') { // An extra '?' or ',' after a child node indicates the end of all children of this node. idx++; break; } } } stack.remove(0); return idx; }