List of usage examples for com.google.common.collect ImmutableMap entrySet
public final ImmutableSet<Entry<K, V>> entrySet()
From source file:com.facebook.buck.cli.ServerStatusCommand.java
@Override public int runWithoutHelp(CommandRunnerParams params) throws IOException, InterruptedException { ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder(); if (isShowHttpserverPort()) { int port = -1; Optional<WebServer> webServer = params.getWebServer(); if (webServer.isPresent()) { port = webServer.get().getPort().orElse(port); }/* w ww . java2 s . c om*/ builder.put("http.port", port); } ImmutableMap<String, Object> values = builder.build(); Console console = params.getConsole(); if (isPrintJson()) { console.getStdOut().println(params.getObjectMapper().writeValueAsString(values)); } else { for (Map.Entry<String, Object> entry : values.entrySet()) { console.getStdOut().printf("%s=%s%n", entry.getKey(), entry.getValue()); } } return 0; }
From source file:org.apache.lens.cube.metadata.FactPartition.java
public double getAllTableWeights(ImmutableMap<String, Double> tableWeights) { double weight = 0; Map<String, Double> tblWithoutDBWeghts = new HashMap<>(); for (Map.Entry<String, Double> entry : tableWeights.entrySet()) { tblWithoutDBWeghts.put(entry.getKey().substring(entry.getKey().indexOf('.') + 1), entry.getValue()); }/*from www . ja v a2 s. c o m*/ for (String tblName : getStorageTables()) { Double tblWeight = tblWithoutDBWeghts.get(tblName); if (tblWeight != null) { weight += tblWeight; } } return weight; }
From source file:com.opengamma.collect.named.ExtendedEnum.java
/** * Returns the map of known instances by name. * <p>/*from ww w .j a va 2 s.c om*/ * This method returns all known instances. * It is permitted for an enum provider implementation to return an empty map, * thus the map may not be complete. * The map may include instances keyed under an alternate name, however it * will not include the base set of {@linkplain #alternateNames() alternate names}. * * @return the map of enum instance by name */ public ImmutableMap<String, T> lookupAll() { Map<String, T> map = new HashMap<>(); for (NamedLookup<T> lookup : lookups) { ImmutableMap<String, T> lookupMap = lookup.lookupAll(); for (Entry<String, T> entry : lookupMap.entrySet()) { map.putIfAbsent(entry.getKey(), entry.getValue()); } } return ImmutableMap.copyOf(map); }
From source file:com.facebook.buck.remoteexecution.util.MultiThreadedBlobUploader.java
private ListenableFuture<Void> enqueue(ImmutableMap<Digest, UploadDataSupplier> data) { ImmutableList.Builder<ListenableFuture<Void>> futures = ImmutableList.builder(); for (Entry<Digest, UploadDataSupplier> entry : data.entrySet()) { Digest digest = entry.getKey();//from w ww. j av a 2 s .co m ListenableFuture<Void> resultFuture = pendingUploads.computeIfAbsent(digest.getHash(), hash -> { if (containedHashes.contains(hash)) { return Futures.immediateFuture(null); } SettableFuture<Void> future = SettableFuture.create(); waitingMissingCheck.add(new PendingUpload(new UploadData(digest, entry.getValue()), future)); return Futures.transform(future, ignore -> { // If the upload was successful short circuit for future requests. containedHashes.add(digest.getHash()); return null; }, directExecutor()); }); Futures.addCallback(resultFuture, MoreFutures.finallyCallback(() -> { pendingUploads.remove(digest.getHash()); }), directExecutor()); futures.add(resultFuture); uploadService.submit(this::processUploads); } return Futures.whenAllSucceed(futures.build()).call(() -> null, directExecutor()); }
From source file:edu.mit.streamjit.impl.blob.DrainData.java
private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException { ois.defaultReadObject();//from w w w. j a va 2 s. c o m ImmutableMap<Integer, Map<String, Object>> map = (ImmutableMap<Integer, Map<String, Object>>) ois .readObject(); ImmutableTable.Builder<Integer, String, Object> builder = ImmutableTable.builder(); for (Map.Entry<Integer, Map<String, Object>> e1 : map.entrySet()) for (Map.Entry<String, Object> e2 : e1.getValue().entrySet()) builder.put(e1.getKey(), e2.getKey(), e2.getValue()); state = builder.build(); }
From source file:queries.PrimingMapsForQuery.java
@Test public void primingTextMaps() throws Exception { String query = "select * from something"; ImmutableMap<String, ColumnTypes> columnTypes = of("varchar_map", ColumnTypes.VarcharVarcharMap, "text_map", ColumnTypes.TextTextMap, "ascii_map", ColumnTypes.AsciiAsciiMap); Map<String, CqlType> newTypes = columnTypes.entrySet().stream() .collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().getType())); ImmutableMap<String, Map<String, String>> rows = ImmutableMap.<String, Map<String, String>>of("varchar_map", of("one", "two"), "text_map", of("three", "four"), "ascii_map", of()); PrimingRequest prime = PrimingRequest.queryBuilder().withQuery(query).withColumnTypes(columnTypes) .withRows(rows).build();/*from w ww. j a v a 2 s .com*/ AbstractScassandraTest.primingClient.prime(prime); List<CassandraRow> result = cassandra().executeQuery(query).rows(); assertEquals(result.size(), 1); CassandraRow rowOne = result.get(0); assertEquals(of("one", "two"), rowOne.getMap("varchar_map", String.class, String.class)); assertEquals(of("three", "four"), rowOne.getMap("text_map", String.class, String.class)); assertEquals(of(), rowOne.getMap("ascii_map", String.class, String.class)); // Retrieve primes check List<PrimingRequest> primingRequests = AbstractScassandraTest.primingClient.retrieveQueryPrimes(); assertEquals(newTypes, primingRequests.get(0).getThen().getColumnTypes()); assertEquals(Arrays.asList(rows), primingRequests.get(0).getThen().getRows()); }
From source file:com.facebook.buck.jvm.java.JavaBuckConfig.java
public JavacOptions getDefaultJavacOptions() { JavacOptions.Builder builder = JavacOptions.builderForUseInJavaBuckConfig(); Optional<String> sourceLevel = delegate.getValue(SECTION, "source_level"); if (sourceLevel.isPresent()) { builder.setSourceLevel(sourceLevel.get()); }/*from w ww . j a v a 2 s.c o m*/ Optional<String> targetLevel = delegate.getValue(SECTION, "target_level"); if (targetLevel.isPresent()) { builder.setTargetLevel(targetLevel.get()); } Optional<JavacOptions.JavacLocation> location = delegate.getEnum(SECTION, "location", JavacOptions.JavacLocation.class); if (location.isPresent()) { builder.setJavacLocation(location.get()); } ImmutableList<String> extraArguments = delegate.getListWithoutComments(SECTION, "extra_arguments"); ImmutableList<String> safeAnnotationProcessors = delegate.getListWithoutComments(SECTION, "safe_annotation_processors"); Optional<AbstractJavacOptions.SpoolMode> spoolMode = delegate.getEnum(SECTION, "jar_spool_mode", AbstractJavacOptions.SpoolMode.class); if (spoolMode.isPresent()) { builder.setSpoolMode(spoolMode.get()); } // This is just to make it possible to turn off dep-based rulekeys in case anything goes wrong // and can be removed when we're sure class usage tracking and dep-based keys for Java // work fine. Optional<Boolean> trackClassUsage = delegate.getBoolean(SECTION, "track_class_usage"); if (trackClassUsage.isPresent()) { builder.setTrackClassUsageNotDisabled(trackClassUsage.get()); } Optional<JavacOptions.AbiGenerationMode> abiGenerationMode = delegate.getEnum(SECTION, "abi_generation_mode", JavacOptions.AbiGenerationMode.class); if (abiGenerationMode.isPresent()) { builder.setAbiGenerationMode(abiGenerationMode.get()); } ImmutableMap<String, String> allEntries = delegate.getEntriesForSection(SECTION); ImmutableMap.Builder<String, String> bootclasspaths = ImmutableMap.builder(); for (Map.Entry<String, String> entry : allEntries.entrySet()) { if (entry.getKey().startsWith("bootclasspath-")) { bootclasspaths.put(entry.getKey().substring("bootclasspath-".length()), entry.getValue()); } } return builder.setJavacPath(getJavacPath().map(Either::ofLeft)).setJavacJarPath(getJavacJarPath()) .setCompilerClassName(getCompilerClassName()).putAllSourceToBootclasspath(bootclasspaths.build()) .addAllExtraArguments(extraArguments).setSafeAnnotationProcessors(safeAnnotationProcessors).build(); }
From source file:com.facebook.buck.features.python.PexStep.java
private ImmutableMap<Path, Path> getExpandedSourcePaths(ProjectFilesystemFactory projectFilesystemFactory, ImmutableMap<Path, Path> paths) throws InterruptedException, IOException { ImmutableMap.Builder<Path, Path> sources = ImmutableMap.builder(); for (ImmutableMap.Entry<Path, Path> ent : paths.entrySet()) { if (ent.getValue().toString().endsWith(SRC_ZIP)) { Path destinationDirectory = filesystem.resolve(tempDir.resolve(ent.getKey())); Files.createDirectories(destinationDirectory); ImmutableList<Path> zipPaths = ArchiveFormat.ZIP.getUnarchiver().extractArchive( projectFilesystemFactory, filesystem.resolve(ent.getValue()), destinationDirectory, ExistingFileMode.OVERWRITE); for (Path path : zipPaths) { Path modulePath = destinationDirectory.relativize(path); sources.put(modulePath, path); }//from www . j ava2 s .c om } else { sources.put(ent.getKey(), ent.getValue()); } } return sources.build(); }
From source file:com.facebook.buck.rules.modern.builders.RemoteExecution.java
private ImmutableList<Path> processClasspath(FileTreeBuilder inputsBuilder, Path cellPrefix, ImmutableMap<Path, Supplier<InputFile>> classPath) throws IOException { ImmutableList.Builder<Path> resolvedBuilder = ImmutableList.builder(); for (Map.Entry<Path, Supplier<InputFile>> entry : classPath.entrySet()) { Path path = entry.getKey(); Preconditions.checkState(path.isAbsolute()); if (!path.startsWith(cellPrefix)) { resolvedBuilder.add(path);//from w w w. j ava 2s .c o m } else { Path relative = cellPrefix.relativize(path); inputsBuilder.addFile(relative, () -> entry.getValue().get()); resolvedBuilder.add(relative); } } return resolvedBuilder.build(); }
From source file:com.facebook.buck.android.AndroidModuleConsistencyStep.java
@Override public StepExecutionResult execute(ExecutionContext context) { try {/*w w w . ja va 2 s .c o m*/ ProguardTranslatorFactory translatorFactory = ProguardTranslatorFactory.create(filesystem, proguardFullConfigFile, proguardMappingFile, skipProguard); ImmutableMultimap<String, APKModule> classToModuleMap = APKModuleGraph.getAPKModuleToClassesMap( apkModuleToJarPathMap, translatorFactory.createObfuscationFunction(), filesystem).inverse(); ImmutableMap<String, String> classToModuleResult = AppModularityMetadataUtil .getClassToModuleMap(filesystem, metadataInput); boolean hasError = false; StringBuilder errorMessage = new StringBuilder(); for (Map.Entry<String, String> entry : classToModuleResult.entrySet()) { String className = entry.getKey(); String resultName = entry.getValue(); if (classToModuleMap.containsKey(className)) { // if the new classMap does not contain the old class, that's fine, // consistency is only broken when a class changes to a different module. APKModule module = classToModuleMap.get(className).iterator().next(); if (!module.getName().equals(resultName)) { hasError = true; errorMessage.append(className).append(" moved from App Module: ").append(resultName) .append(" to App Module: ").append(module.getName()).append("\n"); } } } if (hasError) { throw new IllegalStateException(errorMessage.toString()); } return StepExecutionResults.SUCCESS; } catch (IOException e) { context.logError(e, "There was an error running AndroidModuleConsistencyStep."); return StepExecutionResults.ERROR; } catch (IllegalStateException e) { context.logError(e, "There was an error running AndroidModuleConsistencyStep."); return StepExecutionResults.ERROR; } }