List of usage examples for com.google.common.collect ImmutableMap.Builder putAll
public final void putAll(Map<? extends K, ? extends V> map)
From source file:org.openqa.selenium.remote.server.NewSessionPayload.java
/** * If the local end sent a request with a JSON Wire Protocol payload that does not have a matching * W3C payload, then we need to synthesize one that matches. *///from w w w.j ava2s. com private Sources rewrite(Sources sources) { if (!sources.getDialects().contains(Dialect.OSS)) { // Yay! Nothing to do! return sources; } if (!sources.getDialects().contains(Dialect.W3C)) { // Yay! Also nothing to do. I mean, we have an empty payload, but that's cool. return sources; } Map<String, Object> ossPayload = sources.getOss().get().entrySet().stream() .filter(e -> !("platform".equals(e.getKey()) && "ANY".equals(e.getValue()))) .filter(e -> !("version".equals(e.getKey()) && "".equals(e.getValue()))) .collect(ImmutableMap.toImmutableMap(Map.Entry::getKey, Map.Entry::getValue)); Map<String, Object> always = sources.getAlwaysMatch().get(); Optional<ImmutableMap<String, Object>> w3cMatch = sources.getFirstMatch().stream().map(Supplier::get) .map(m -> ImmutableMap.<String, Object>builder().putAll(always).putAll(m).build()) .filter(m -> m.equals(ossPayload)).findAny(); if (w3cMatch.isPresent()) { // There's a w3c capability that matches the oss one. Nothing to do. LOG.fine("Found a w3c capability that matches the oss one."); return sources; } LOG.info("Mismatched capabilities. Creating a synthetic w3c capability."); ImmutableList.Builder<Supplier<Map<String, Object>>> newFirstMatches = ImmutableList.builder(); newFirstMatches.add(sources.getOss()); sources.getFirstMatch().forEach(m -> newFirstMatches.add(() -> { ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder(); builder.putAll(sources.getAlwaysMatch().get()); builder.putAll(m.get()); return builder.build(); })); return new Sources(sources.getOriginalPayload(), sources.getPayloadSize(), sources.getOss(), ImmutableMap::of, newFirstMatches.build(), sources.getDialects()); }
From source file:com.facebook.buck.android.AndroidTransitiveDependencyGraph.java
/** * @param uberRDotJava that may have produced {@code R.class} files that need to be dexed. *///from ww w. j ava2 s . com public AndroidDexTransitiveDependencies findDexDependencies( ImmutableList<HasAndroidResourceDeps> androidResourceDeps, final ImmutableSet<JavaLibrary> buildRulesToExcludeFromDex, final UberRDotJava uberRDotJava) { // These are paths that will be dex'ed. They may be either directories of compiled .class files, // or paths to compiled JAR files. final ImmutableSet.Builder<Path> pathsToDexBuilder = ImmutableSet.builder(); // Paths to the classfiles to not dex. final ImmutableSet.Builder<Path> noDxPathsBuilder = ImmutableSet.builder(); // These are paths to third-party jars that may contain resources that must be included in the // final APK. final ImmutableSet.Builder<Path> pathsToThirdPartyJarsBuilder = ImmutableSet.builder(); AndroidResourceDetails details = findAndroidResourceDetails(androidResourceDeps); // Update pathsToDex. final ImmutableSetMultimap<JavaLibrary, Path> classpath = Classpaths .getClasspathEntries(rulesToTraverseForTransitiveDeps); for (Map.Entry<JavaLibrary, Path> entry : classpath.entries()) { if (!buildRulesToExcludeFromDex.contains(entry.getKey())) { pathsToDexBuilder.add(entry.getValue()); } else { noDxPathsBuilder.add(entry.getValue()); } } // Include the directory of compiled R.java files on the classpath. final ImmutableSet<String> rDotJavaPackages = details.rDotJavaPackages; if (!rDotJavaPackages.isEmpty()) { Path pathToCompiledRDotJavaFiles = uberRDotJava.getPathToCompiledRDotJavaFiles(); pathsToDexBuilder.add(pathToCompiledRDotJavaFiles); } ImmutableSet<Path> noDxPaths = noDxPathsBuilder.build(); // Filter out the classpath entries to exclude from dex'ing, if appropriate Set<Path> classpathEntries = Sets.difference(pathsToDexBuilder.build(), noDxPaths); Supplier<Map<String, HashCode>> classNamesToHashesSupplier = Suppliers .memoize(new Supplier<Map<String, HashCode>>() { @Override public Map<String, HashCode> get() { ImmutableMap.Builder<String, HashCode> builder = ImmutableMap.builder(); for (JavaLibrary javaLibrary : classpath.keySet()) { if (!buildRulesToExcludeFromDex.contains(javaLibrary)) { builder.putAll(javaLibrary.getClassNamesToHashes()); } } if (!rDotJavaPackages.isEmpty()) { builder.putAll(uberRDotJava.getClassNamesToHashes()); } return builder.build(); } }); // Visit all of the transitive dependencies to populate the above collections. new AbstractDependencyVisitor(rulesToTraverseForTransitiveDeps) { @Override public ImmutableSet<BuildRule> visit(BuildRule rule) { // We need to include the transitive closure of the compiled .class files when dex'ing, as // well as the third-party jars that they depend on. // Update pathsToThirdPartyJars. if (rule.getBuildable() instanceof PrebuiltJar) { PrebuiltJar prebuiltJar = (PrebuiltJar) rule.getBuildable(); pathsToThirdPartyJarsBuilder.add(prebuiltJar.getBinaryJar()); } return maybeVisitAllDeps(rule, rule.getProperties().is(LIBRARY)); } }.start(); // Classpath entries that should be excluded from dexing should also be excluded from // pathsToThirdPartyJars because their resources should not end up in main APK. If they do, // the pre-dexed library may try to load a resource from the main APK rather than from within // the pre-dexed library (even though the resource is available in both locations). This // causes a significant performance regression, as the resource may take more than one second // longer to load. Set<Path> pathsToThirdPartyJars = Sets.difference(pathsToThirdPartyJarsBuilder.build(), noDxPaths); return new AndroidDexTransitiveDependencies(classpathEntries, pathsToThirdPartyJars, noDxPaths, classNamesToHashesSupplier); }
From source file:com.opengamma.strata.pricer.curve.CurveCalibrator.java
private ImmutableMap<CurveName, JacobianCalibrationMatrix> updateJacobiansForGroup( ImmutableRatesProvider provider, ImmutableList<ResolvedTrade> trades, ImmutableList<CurveParameterSize> orderGroup, ImmutableList<CurveParameterSize> orderPrev, ImmutableList<CurveParameterSize> orderAll, ImmutableMap<CurveName, JacobianCalibrationMatrix> jacobians) { // sensitivity to all parameters in the stated order int totalParamsAll = orderAll.stream().mapToInt(e -> e.getParameterCount()).sum(); DoubleMatrix res = derivatives(trades, provider, orderAll, totalParamsAll); // jacobian direct int nbTrades = trades.size(); int totalParamsGroup = orderGroup.stream().mapToInt(e -> e.getParameterCount()).sum(); int totalParamsPrevious = totalParamsAll - totalParamsGroup; DoubleMatrix pDmCurrentMatrix = jacobianDirect(res, nbTrades, totalParamsGroup, totalParamsPrevious); // jacobian indirect: when totalParamsPrevious > 0 DoubleMatrix pDmPrevious = jacobianIndirect(res, pDmCurrentMatrix, nbTrades, totalParamsGroup, totalParamsPrevious, orderPrev, jacobians); // add to the map of jacobians, one entry for each curve in this group ImmutableMap.Builder<CurveName, JacobianCalibrationMatrix> jacobianBuilder = ImmutableMap.builder(); jacobianBuilder.putAll(jacobians); int startIndex = 0; for (CurveParameterSize order : orderGroup) { int paramCount = order.getParameterCount(); double[][] pDmCurveArray = new double[paramCount][totalParamsAll]; // copy data for previous groups if (totalParamsPrevious > 0) { for (int p = 0; p < paramCount; p++) { System.arraycopy(pDmPrevious.rowArray(startIndex + p), 0, pDmCurveArray[p], 0, totalParamsPrevious); }/*w w w. jav a2s . c om*/ } // copy data for this group for (int p = 0; p < paramCount; p++) { System.arraycopy(pDmCurrentMatrix.rowArray(startIndex + p), 0, pDmCurveArray[p], totalParamsPrevious, totalParamsGroup); } // build final Jacobian matrix DoubleMatrix pDmCurveMatrix = DoubleMatrix.ofUnsafe(pDmCurveArray); jacobianBuilder.put(order.getName(), JacobianCalibrationMatrix.of(orderAll, pDmCurveMatrix)); startIndex += paramCount; } return jacobianBuilder.build(); }
From source file:com.opengamma.engine.view.client.PortfolioPermissionChecker.java
/** * Recursively check each node in the portfolio. * * @param node the node to check// w w w . ja va2 s . co m * @param nodeChecker the checker for the node * @return map of nodes with permissions */ private Map<PortfolioNode, PortfolioPermission> checkNodes(PortfolioNode node, NodeChecker nodeChecker) { // TODO This should probably use PortfolioNodeTraverser for doing the depth-first traversal of the portfolio if (nodeChecker.check(node) == DENY) { return ImmutableMap.of(node, DENY); } else { List<PortfolioNode> children = node.getChildNodes(); ImmutableMap.Builder<PortfolioNode, PortfolioPermission> builder = ImmutableMap.builder(); // Result for node of interest is dependent on whether the children are accessible // so keep track of whether we are denied access to any boolean allAllowed = true; for (PortfolioNode child : children) { Map<PortfolioNode, PortfolioPermission> result = checkNodes(child, nodeChecker); builder.putAll(result); allAllowed = allAllowed && result.get(child) == ALLOW; } builder.put(node, allAllowed ? ALLOW : PARTIAL); return builder.build(); } }
From source file:org.level28.android.moca.sync.SessionHelper.java
/** * Fetch current list of sessions off the network. *//*www . j a v a 2s . co m*/ private ImmutableMap<String, Session> getRemoteSessions() throws IOException, JsonDeserializerException { final ImmutableMap.Builder<String, Session> mapBuilder = ImmutableMap.builder(); ScheduleDeserializer jsonDeserializer = new ScheduleDeserializer(); HttpRequest request = HttpRequest.get(mUrl).userAgent(mUserAgent).acceptJson().acceptGzipEncoding() .uncompress(true); if (request.ok()) { mapBuilder.putAll(jsonDeserializer.fromInputStream(request.stream())); } else if (!request.notModified()) { // Anything that's not a 200 or a 304 should cause the // synchronization code to fail fast throw new IOException("Request failed: " + request.code() + " - " + request.message()); } return mapBuilder.build(); }
From source file:com.facebook.buck.cxx.toolchain.CxxPlatformsProviderFactory.java
@Override public Optional<CxxPlatformsProvider> createToolchain(ToolchainProvider toolchainProvider, ToolchainCreationContext context) { Iterable<String> toolchainNames = toolchainProvider.getToolchainsWithCapability(CxxPlatformsSupplier.class); ImmutableMap.Builder<Flavor, UnresolvedCxxPlatform> cxxSystemPlatforms = ImmutableMap.builder(); for (String toolchainName : toolchainNames) { if (toolchainProvider.isToolchainPresent(toolchainName)) { CxxPlatformsSupplier cxxPlatformsSupplier = toolchainProvider.getByName(toolchainName, CxxPlatformsSupplier.class); cxxSystemPlatforms.putAll(cxxPlatformsSupplier.getCxxPlatforms()); }/* w w w . jav a2 s. c o m*/ } try { return Optional.of(createProvider(context.getBuckConfig(), cxxSystemPlatforms.build())); } catch (HumanReadableException e) { throw ToolchainInstantiationException.wrap(e); } }
From source file:org.openqa.selenium.firefox.FirefoxOptions.java
@Override public Map<String, ?> asMap() { TreeMap<String, Object> toReturn = new TreeMap<>(); toReturn.putAll(super.asMap()); ImmutableSortedMap.Builder<String, Object> w3cOptions = ImmutableSortedMap.naturalOrder(); w3cOptions.put("args", args); if (binary != null) { w3cOptions.put("binary", binary.asPath()); }/*w w w . ja v a2 s .c o m*/ if (logLevel != null) { w3cOptions.put("log", ImmutableMap.of("level", logLevel)); } if (profile != null) { for (Map.Entry<String, Boolean> pref : booleanPrefs.entrySet()) { profile.setPreference(pref.getKey(), pref.getValue()); } for (Map.Entry<String, Integer> pref : intPrefs.entrySet()) { profile.setPreference(pref.getKey(), pref.getValue()); } for (Map.Entry<String, String> pref : stringPrefs.entrySet()) { profile.setPreference(pref.getKey(), pref.getValue()); } try { w3cOptions.put("profile", profile.toJson()); } catch (IOException e) { throw new WebDriverException(e); } } else { ImmutableMap.Builder<String, Object> allPrefs = ImmutableMap.builder(); allPrefs.putAll(booleanPrefs); allPrefs.putAll(intPrefs); allPrefs.putAll(stringPrefs); w3cOptions.put("prefs", allPrefs.build()); } toReturn.put(FIREFOX_OPTIONS, w3cOptions.build()); return toReturn; }
From source file:de.xaniox.heavyspleef.core.flag.FlagManager.java
public Map<String, AbstractFlag<?>> getPresentFlags() { Map<String, AbstractFlag<?>> unloadedFlags = Maps.newHashMap(); for (UnloadedFlag unloaded : this.unloadedFlags) { unloadedFlags.put(unloaded.getFlagName(), unloaded); }// ww w .ja va2 s.c om ImmutableMap.Builder<String, AbstractFlag<?>> builder = ImmutableMap.builder(); return builder.putAll(flags).putAll(unloadedFlags).build(); }
From source file:org.apache.hive.druid.MiniDruidCluster.java
public MiniDruidCluster(String name, String logDir, String tmpDir, Integer zookeeperPort, String classpath) { super(name);//from w ww . ja va 2 s. c o m this.dataDirectory = new File(tmpDir, "druid-data"); this.logDirectory = new File(logDir); boolean isKafka = name.contains("kafka"); coordinatorPort = isKafka ? 8081 : 9081; brokerPort = coordinatorPort + 1; historicalPort = brokerPort + 1; int derbyPort = historicalPort + 1; ensureCleanDirectory(dataDirectory); derbyURI = String.format("jdbc:derby://localhost:%s/%s/druid_derby/metadata.db;create=true", derbyPort, dataDirectory.getAbsolutePath()); String segmentsCache = String.format("[{\"path\":\"%s/druid/segment-cache\",\"maxSize\":130000000000}]", dataDirectory.getAbsolutePath()); String indexingLogDir = new File(logDirectory, "indexer-log").getAbsolutePath(); ImmutableMap.Builder<String, String> coordinatorMapBuilder = new ImmutableMap.Builder(); ImmutableMap.Builder<String, String> historicalMapBuilder = new ImmutableMap.Builder(); ImmutableMap.Builder<String, String> brokerMapBuilder = new ImmutableMap.Builder(); Map<String, String> coordinatorProperties = coordinatorMapBuilder.putAll(COMMON_DRUID_CONF) .putAll(COMMON_COORDINATOR_INDEXER).put("druid.metadata.storage.connector.connectURI", derbyURI) .put("druid.metadata.storage.connector.port", String.valueOf(derbyPort)) .put("druid.indexer.logs.directory", indexingLogDir) .put("druid.zk.service.host", "localhost:" + zookeeperPort) .put("druid.coordinator.startDelay", "PT1S").put("druid.indexer.runner", "local") .put("druid.storage.storageDirectory", getDeepStorageDir()) .put("druid.port", String.valueOf(coordinatorPort)).build(); Map<String, String> historicalProperties = historicalMapBuilder.putAll(COMMON_DRUID_CONF) .putAll(COMMON_DRUID_HISTORICAL).put("druid.zk.service.host", "localhost:" + zookeeperPort) .put("druid.segmentCache.locations", segmentsCache) .put("druid.storage.storageDirectory", getDeepStorageDir()) .put("druid.port", String.valueOf(historicalPort)).build(); Map<String, String> brokerProperties = brokerMapBuilder.putAll(COMMON_DRUID_CONF) .put("druid.zk.service.host", "localhost:" + zookeeperPort) .put("druid.port", String.valueOf(brokerPort)).build(); coordinator = new ForkingDruidNode("coordinator", classpath, coordinatorProperties, COORDINATOR_JVM_CONF, logDirectory, null); historical = new ForkingDruidNode("historical", classpath, historicalProperties, HISTORICAL_JVM_CONF, logDirectory, null); broker = new ForkingDruidNode("broker", classpath, brokerProperties, HISTORICAL_JVM_CONF, logDirectory, null); druidNodes = Arrays.asList(coordinator, historical, broker); }
From source file:org.trancecode.xproc.step.XQueryStepProcessor.java
private Map<QName, String> getParameters(final StepInput input) { final ImmutableMap.Builder<QName, String> builder = new ImmutableMap.Builder<>(); final Map<QName, Variable> stepParams = Environment.getCurrentEnvironment().getPipeline().getParameters(); for (final Map.Entry<QName, Variable> entry : stepParams.entrySet()) { builder.put(entry.getKey(), entry.getValue().getValue()); }// ww w . j av a 2 s . c om final Map<QName, String> inputParams = input.getParameters(XProcSteps.PARAMETERS.getLocalName()); builder.putAll(inputParams); return builder.build(); }