List of usage examples for com.google.common.collect ImmutableMap entrySet
public final ImmutableSet<Entry<K, V>> entrySet()
From source file:com.facebook.buck.parser.TargetSpecResolver.java
private <T extends HasBuildTarget> ImmutableSet<BuildTarget> applySpecFilter(TargetNodeSpec spec, ImmutableList<T> targetNodes, FlavorEnhancer<T> flavorEnhancer, TargetNodeFilterForSpecResolver<T> targetNodeFilter) { ImmutableSet.Builder<BuildTarget> targets = ImmutableSet.builder(); ImmutableMap<BuildTarget, T> partialTargets = targetNodeFilter.filter(spec, targetNodes); for (Map.Entry<BuildTarget, T> partialTarget : partialTargets.entrySet()) { BuildTarget target = flavorEnhancer.enhanceFlavors(partialTarget.getKey(), partialTarget.getValue(), spec.getTargetType());//w w w. j ava 2 s .com targets.add(target); } return targets.build(); }
From source file:com.stratio.ingestion.deserializer.xmlxpath.XmlXpathDeserializer.java
/** * From a properties, evaluate every xpath expression in value and put result in a map * maintaining given key.//from www.j av a 2s . c o m * * @param properties * @return */ private Map<String, String> evaluateStaticFields(ImmutableMap<String, String> properties) { Map<String, String> headers = new HashMap<String, String>(); for (Entry<String, String> entry : properties.entrySet()) { try { XPathExpression expression = xpath.compile(entry.getValue()); String value = (String) expression.evaluate(doc, XPathConstants.STRING); headers.put(entry.getKey(), value); } catch (XPathExpressionException e) { e.printStackTrace(); } } return headers; }
From source file:com.facebook.buck.haskell.HaskellGhciDescription.java
private boolean isPrebuiltSO(NativeLinkable nativeLinkable, CxxPlatform cxxPlatform) throws NoSuchBuildTargetException { if (nativeLinkable instanceof PrebuiltCxxLibraryGroupDescription.CustomPrebuiltCxxLibrary) { return true; }// ww w.ja v a2 s . co m if (!(nativeLinkable instanceof PrebuiltCxxLibrary)) { return false; } ImmutableMap<String, SourcePath> sharedLibraries = nativeLinkable.getSharedLibraries(cxxPlatform); for (Map.Entry<String, SourcePath> ent : sharedLibraries.entrySet()) { if (!(ent.getValue() instanceof PathSourcePath)) { return false; } } return true; }
From source file:com.facebook.buck.apple.xcode.ProjectGenerator.java
private static void setProjectLevelConfigs(PBXProject project, Path repoRootRelativeToOutputDirectory, ImmutableMap<String, ConfigInXcodeLayout> configs) { for (Map.Entry<String, ConfigInXcodeLayout> configEntry : configs.entrySet()) { XCBuildConfiguration outputConfig = project.getBuildConfigurationList().getBuildConfigurationsByName() .getUnchecked(configEntry.getKey()); ConfigInXcodeLayout config = configEntry.getValue(); PBXGroup configurationsGroup = project.getMainGroup().getOrCreateChildGroupByName("Configurations"); PBXFileReference fileReference = configurationsGroup.getOrCreateFileReferenceBySourceTreePath( new SourceTreePath(PBXReference.SourceTree.SOURCE_ROOT, repoRootRelativeToOutputDirectory .resolve(config.projectLevelConfigFile.get()).normalize())); outputConfig.setBaseConfigurationReference(fileReference); NSDictionary inlineSettings = new NSDictionary(); for (Map.Entry<String, String> entry : config.projectLevelInlineSettings.entrySet()) { inlineSettings.put(entry.getKey(), entry.getValue()); }//from ww w . ja va 2s. c o m outputConfig.setBuildSettings(inlineSettings); } }
From source file:com.facebook.buck.doctor.DefaultDefectReporter.java
private void addNamedFilesToArchive(CustomZipOutputStream out, ImmutableMap<String, VersionControlSupplier<InputStream>> fileStreams) throws IOException, VersionControlCommandFailedException, InterruptedException { for (Map.Entry<String, VersionControlSupplier<InputStream>> fs : fileStreams.entrySet()) { try (InputStream input = fs.getValue().get()) { out.writeEntry(fs.getKey(), input); }/*w w w .j a va 2 s. co m*/ out.closeEntry(); } }
From source file:com.google.devtools.build.docgen.SkylarkJavaInterfaceExplorer.java
/** * Collects and returns all the Java objects reachable in Skylark from (and including) * firstClassObject with the corresponding SkylarkSignature annotations. * * <p>Note that the {@link SkylarkSignature} annotation for firstClassObject - firstAnnotation - * is also an input parameter, because some top level Skylark built-in objects and methods * are not annotated on the class, but on a field referencing them. *//*from w w w. j a va 2 s . com*/ void collect(SkylarkModule firstModule, Class<?> firstClass, Map<String, SkylarkModuleDoc> modules) { Set<Class<?>> processedClasses = new HashSet<>(); LinkedList<Class<?>> classesToProcess = new LinkedList<>(); Map<Class<?>, SkylarkModule> annotations = new HashMap<>(); classesToProcess.addLast(firstClass); annotations.put(firstClass, firstModule); while (!classesToProcess.isEmpty()) { Class<?> classObject = classesToProcess.removeFirst(); SkylarkModule annotation = annotations.get(classObject); processedClasses.add(classObject); if (!modules.containsKey(annotation.name())) { modules.put(annotation.name(), new SkylarkModuleDoc(annotation, classObject)); } SkylarkModuleDoc module = modules.get(annotation.name()); if (module.javaMethodsNotCollected()) { ImmutableMap<Method, SkylarkCallable> methods = FuncallExpression .collectSkylarkMethodsWithAnnotation(classObject); ArrayList<SkylarkJavaMethod> methodList = new ArrayList<>(); for (Map.Entry<Method, SkylarkCallable> entry : methods.entrySet()) { methodList.add(new SkylarkJavaMethod(entry.getKey(), entry.getValue())); } module.setJavaMethods(methodList); for (Map.Entry<Method, SkylarkCallable> method : methods.entrySet()) { Class<?> returnClass = method.getKey().getReturnType(); if (returnClass.isAnnotationPresent(SkylarkModule.class) && !processedClasses.contains(returnClass)) { classesToProcess.addLast(returnClass); annotations.put(returnClass, returnClass.getAnnotation(SkylarkModule.class)); } } } } }
From source file:com.facebook.buck.android.exopackage.ExopackageInstaller.java
public void installMissingFiles(ImmutableSortedSet<Path> presentFiles, ImmutableMap<Path, Path> wantedFilesToInstall, String filesType) throws Exception { ImmutableSortedMap<Path, Path> filesToInstall = wantedFilesToInstall.entrySet().stream() .filter(entry -> !presentFiles.contains(entry.getKey())).collect(ImmutableSortedMap .toImmutableSortedMap(Ordering.natural(), Map.Entry::getKey, Map.Entry::getValue)); installFiles(filesType, filesToInstall); }
From source file:org.kiji.scoring.impl.InternalFreshKijiTableReader.java
/** * Fills a partial map of Fresheners by creating new Fresheners for each record not already * reflected by the fresheners map.//from w ww. java 2 s . c o m * * @param readerUID unique identifier for the reader which called this method. Used for logging. * @param records a map of records for which to create Fresheners. * @param oldFresheners a partially filled map of Fresheners to be completed with new Fresheners * built from the records map. * @return a map of Fresheners for each KijiFreshenerRecord in records. * @throws IOException in case of an error setting up a KijiFreshnessPolicy or ScoreFunction. */ private static ImmutableMap<KijiColumnName, Freshener> fillFresheners(final String readerUID, final ImmutableMap<KijiColumnName, KijiFreshenerRecord> records, final ImmutableMap<KijiColumnName, Freshener> oldFresheners) throws IOException { final Map<KijiColumnName, Freshener> fresheners = Maps.newHashMap(); for (Map.Entry<KijiColumnName, KijiFreshenerRecord> entry : records.entrySet()) { if (!oldFresheners.containsKey(entry.getKey())) { // If there is not already a Freshener for this record, make one. final KijiFreshenerRecord record = entry.getValue(); // Create the FreshenerSetupContext final InternalFreshenerContext context = InternalFreshenerContext.create(entry.getKey(), record.getParameters()); // Instantiate the policy and score function. final KijiFreshnessPolicy policy = ScoringUtils.policyForName(record.getFreshnessPolicyClass()); final ScoreFunction<?> scoreFunction = ScoringUtils .scoreFunctionForName(record.getScoreFunctionClass()); // Create the KVStoreReaderFactory from the required stores of the score function and // policy, and add the factory to the Freshener context. final KeyValueStoreReaderFactory factory = ScoringUtils.createKVStoreReaderFactory(context, scoreFunction, policy); context.setKeyValueStoreReaderFactory(factory); // Setup the policy and score function. policy.setup(context); scoreFunction.setup(context); // Build the Freshener from initialized components. final Freshener freshener = new Freshener(policy, scoreFunction, factory, entry.getKey(), entry.getValue().getParameters()); LOG.debug("{} loading new Freshener: {}", readerUID, freshener); fresheners.put(entry.getKey(), freshener); } else { // If there is already a Freshener for this key, save it. final Freshener oldFreshener = oldFresheners.get(entry.getKey()); LOG.debug("{} preserving old Freshener: {}", readerUID, oldFreshener); fresheners.put(entry.getKey(), oldFreshener); } } return ImmutableMap.copyOf(fresheners); }
From source file:com.arpnetworking.metrics.mad.performance.FilePerfTestBase.java
/** * Runs a filter.//w w w .j ava2 s.c o m * * @param pipelineConfigurationFile Pipeline configuration file. * @param duration Timeout period. * @param variables Substitution key-value pairs into pipeline configuration file. * @throws IOException if configuration cannot be loaded. */ protected void benchmark(final String pipelineConfigurationFile, final Duration duration, final ImmutableMap<String, String> variables) throws IOException { // Replace any variables in the configuration file String configuration = Resources.toString(Resources.getResource(pipelineConfigurationFile), Charsets.UTF_8); for (final Map.Entry<String, String> entry : variables.entrySet()) { configuration = configuration.replace(entry.getKey(), entry.getValue()); } // Load the specified stock configuration final PipelineConfiguration stockPipelineConfiguration = new StaticConfiguration.Builder() .addSource(new JsonNodeLiteralSource.Builder().setSource(configuration).build()) .setObjectMapper(PipelineConfiguration.createObjectMapper(_injector)).build() .getRequiredAs(PipelineConfiguration.class); // Canary tracking LOGGER.info(String.format("Expected canaries; periods=%s", stockPipelineConfiguration.getPeriods())); final CountDownLatch latch = new CountDownLatch(stockPipelineConfiguration.getPeriods().size()); final Set<Period> periods = Sets.newConcurrentHashSet(); // Create custom "canary" sink final ListeningSink sink = new ListeningSink((periodicData) -> { if (periodicData != null) { for (final String metricName : periodicData.getData().keys()) { if (TestFileGenerator.CANARY.equals(metricName)) { if (periods.add(periodicData.getPeriod())) { LOGGER.info(String.format("Canary flew; filter=%s, period=%s", this.getClass(), periodicData.getPeriod())); latch.countDown(); } } } } return null; }); // Add the custom "canary" sink final List<Sink> benchmarkSinks = Lists.newArrayList(stockPipelineConfiguration.getSinks()); benchmarkSinks.add(sink); // Create the custom configuration final PipelineConfiguration benchmarkPipelineConfiguration = OvalBuilder.<PipelineConfiguration, PipelineConfiguration.Builder>clone( stockPipelineConfiguration).setSinks(benchmarkSinks).build(); // Instantiate the pipeline final Pipeline pipeline = new Pipeline(benchmarkPipelineConfiguration); // Execute the pipeline until the canary flies the coop try { LOGGER.debug(String.format("Launching pipeline; configuration=%s", pipelineConfigurationFile)); final Stopwatch timer = Stopwatch.createUnstarted(); timer.start(); pipeline.launch(); if (!latch.await(duration.getMillis(), TimeUnit.MILLISECONDS)) { LOGGER.error("Test timed out"); throw new RuntimeException("Test timed out"); } timer.stop(); LOGGER.info(String.format("Performance filter result; filter=%s, seconds=%s", this.getClass(), timer.elapsed(TimeUnit.SECONDS))); } catch (final InterruptedException e) { Thread.interrupted(); throw new RuntimeException("Test interrupted"); } finally { pipeline.shutdown(); } }
From source file:se.sics.caracaldb.global.SchemaData.java
public String schemaInfo(String name) { ByteBuffer id = schemaIDs.get(name); if (id == null) { return "Not found!"; }/*from w w w . j a v a 2 s. c o m*/ ImmutableMap<String, String> meta = metaData.get(id); if (meta == null) { return "No info!"; } StringBuilder sb = new StringBuilder(); sb.append(name); sb.append(" ( \n"); for (Entry<String, String> e : meta.entrySet()) { sb.append(" "); sb.append(e.getKey()); sb.append(" -> "); sb.append(e.getValue()); sb.append("\n"); } sb.append(" )"); return sb.toString(); }