List of usage examples for com.google.common.collect ImmutableMultimap get
@Override public abstract ImmutableCollection<V> get(K key);
From source file:com.facebook.buck.features.project.intellij.lang.java.JavaLibraryModuleRule.java
@Override public void apply(TargetNode<JavaLibraryDescription.CoreArg> target, ModuleBuildContext context) { Optional<Path> presetResourcesRoot = target.getConstructorArg().getResourcesRoot(); ImmutableSortedSet<SourcePath> resources = target.getConstructorArg().getResources(); ImmutableSet<Path> resourcePaths; if (presetResourcesRoot.isPresent()) { resourcePaths = getResourcePaths(resources, presetResourcesRoot.get()); addResourceFolders(IjResourceFolderType.JAVA_RESOURCE, resourcePaths, presetResourcesRoot.get(), context);//from ww w.j a va 2s . co m } else { resourcePaths = getResourcePaths(resources); ImmutableMultimap<Path, Path> resourcesRootsToResources = getResourcesRootsToResources(packageFinder, resourcePaths); for (Path resourcesRoot : resourcesRootsToResources.keySet()) { addResourceFolders(IjResourceFolderType.JAVA_RESOURCE, resourcesRootsToResources.get(resourcesRoot), resourcesRoot, context); } } addDepsAndSources(target, true /* wantsPackagePrefix */, context, resourcePaths); JavaLibraryRuleHelper.addCompiledShadowIfNeeded(projectConfig, target, context); JavaLibraryRuleHelper.addNonSourceBuildTargets(target, context); context.setJavaLanguageLevel(JavaLibraryRuleHelper.getLanguageLevel(projectConfig, target)); context.setCompilerOutputPath(moduleFactoryResolver.getCompilerOutputPath(target)); }
From source file:com.facebook.buck.features.project.intellij.lang.java.JavaTestModuleRule.java
@Override public void apply(TargetNode<JavaTestDescription.CoreArg> target, ModuleBuildContext context) { Optional<Path> presetResourcesRoot = target.getConstructorArg().getResourcesRoot(); ImmutableSortedSet<SourcePath> resources = target.getConstructorArg().getResources(); ImmutableSet<Path> resourcePaths; if (presetResourcesRoot.isPresent()) { resourcePaths = getResourcePaths(target.getConstructorArg().getResources(), presetResourcesRoot.get()); addResourceFolders(IjResourceFolderType.JAVA_TEST_RESOURCE, resourcePaths, presetResourcesRoot.get(), context);//from w w w . ja va2s . co m } else { resourcePaths = getResourcePaths(resources); ImmutableMultimap<Path, Path> resourcesRootsToResources = getResourcesRootsToResources(packageFinder, resourcePaths); for (Path resourcesRoot : resourcesRootsToResources.keySet()) { addResourceFolders(IjResourceFolderType.JAVA_TEST_RESOURCE, resourcesRootsToResources.get(resourcesRoot), resourcesRoot, context); } } addDepsAndTestSources(target, true /* wantsPackagePrefix */, context, resourcePaths); JavaLibraryRuleHelper.addCompiledShadowIfNeeded(projectConfig, target, context); context.setJavaLanguageLevel(JavaLibraryRuleHelper.getLanguageLevel(projectConfig, target)); }
From source file:org.apache.beam.runners.flink.translation.functions.FlinkBatchSideInputHandlerFactory.java
private <T, W extends BoundedWindow> SideInputHandler<T, W> forIterableSideInput( List<WindowedValue<T>> broadcastVariable, Coder<T> elementCoder, Coder<W> windowCoder) { ImmutableMultimap.Builder<Object, T> windowToValuesBuilder = ImmutableMultimap.builder(); for (WindowedValue<T> windowedValue : broadcastVariable) { for (BoundedWindow boundedWindow : windowedValue.getWindows()) { @SuppressWarnings("unchecked") W window = (W) boundedWindow; windowToValuesBuilder.put(windowCoder.structuralValue(window), windowedValue.getValue()); }/*from w w w . j av a 2 s . c o m*/ } ImmutableMultimap<Object, T> windowToValues = windowToValuesBuilder.build(); return new SideInputHandler<T, W>() { @Override public Iterable<T> get(byte[] key, W window) { return windowToValues.get(windowCoder.structuralValue(window)); } @Override public Coder<T> resultCoder() { return elementCoder; } }; }
From source file:org.knowm.dropwizard.sundial.tasks.StartJobTask.java
@Override public void execute(ImmutableMultimap<String, String> parameters, PrintWriter output) throws Exception { logger.info(parameters.toString());//from w ww . j a v a 2s . c om Map<String, Object> params = new HashMap<String, Object>(); for (Entry<String, String> entry : parameters.entries()) { params.put(entry.getKey(), entry.getValue()); } String jobName = (String) parameters.get("JOB_NAME").toArray()[0]; SundialJobScheduler.startJob(jobName, params); }
From source file:org.knowm.dropwizard.sundial.tasks.AddJobTask.java
@Override public void execute(ImmutableMultimap<String, String> parameters, PrintWriter output) throws Exception { logger.info(parameters.toString());// w w w .ja v a 2s .c o m Map<String, Object> params = new HashMap<String, Object>(); for (Entry<String, String> entry : parameters.entries()) { params.put(entry.getKey(), entry.getValue()); } String jobName = (String) parameters.get("JOB_NAME").toArray()[0]; String jobClass = (String) parameters.get("JOB_CLASS").toArray()[0]; SundialJobScheduler.addJob(jobName, jobClass, params, false); }
From source file:me.taylorkelly.mywarp.bukkit.commands.printer.AssetsPrinter.java
/** * Prints the given Limit to the receiver. The given Warps will be matched to the individual Limit.Types and displayed * accordingly.//from w w w.j a v a 2 s . com * * @param receiver the Actor who is receiving this print * @param limit the limit * @param warps the Warps that are affected by the given Limit */ private void printLimit(Actor receiver, Limit limit, Collection<Warp> warps) { ImmutableMultimap.Builder<Limit.Type, Warp> builder = ImmutableMultimap.builder(); // sort warps to types for (Warp warp : warps) { for (Limit.Type type : Limit.Type.values()) { if (type.getCondition().apply(warp)) { builder.put(type, warp); } } } // display... ImmutableMultimap<Limit.Type, Warp> index = builder.build(); // ...the total limit receiver.sendMessage(ChatColor.GRAY + MESSAGES.getString("assets.total", CommandUtils.joinWorlds(limit.getAffectedWorlds()), warpLimitCount(index.get(Limit.Type.TOTAL).size(), limit.getLimit(Limit.Type.TOTAL)))); // ... all other limits List<String> limitStrings = new ArrayList<String>(); for (Limit.Type type : DISPLAYABLE_TYPES) { Collection<Warp> privateWarps = index.get(type); limitStrings.add(ChatColor.GOLD + MESSAGES.getString("assets." + type.lowerCaseName(), warpLimitCount(privateWarps.size(), limit.getLimit(type))) + " " + ChatColor.WHITE + ChatColor.ITALIC + CommandUtils.joinWarps(privateWarps)); } receiver.sendMessage(FormattingUtils.toList(limitStrings)); }
From source file:com.facebook.buck.core.cell.AbstractCellConfig.java
/** * Translates the 'cell name'->override map into a 'Path'->override map. * * @param pathMapping a map containing paths to all of the cells we want to query. * @return 'Path'->override map// w w w. jav a 2 s . com */ public ImmutableMap<Path, RawConfig> getOverridesByPath(ImmutableMap<CellName, Path> pathMapping) throws InvalidCellOverrideException { ImmutableSet<CellName> relativeNamesOfCellsWithOverrides = FluentIterable.from(getValues().keySet()) .filter(Predicates.not(CellName.ALL_CELLS_SPECIAL_NAME::equals)).toSet(); ImmutableSet.Builder<Path> pathsWithOverrides = ImmutableSet.builder(); for (CellName cellWithOverride : relativeNamesOfCellsWithOverrides) { if (!pathMapping.containsKey(cellWithOverride)) { throw new InvalidCellOverrideException( String.format("Trying to override settings for unknown cell %s", cellWithOverride)); } pathsWithOverrides.add(pathMapping.get(cellWithOverride)); } ImmutableMultimap<Path, CellName> pathToRelativeName = Multimaps.index(pathMapping.keySet(), Functions.forMap(pathMapping)); for (Path pathWithOverrides : pathsWithOverrides.build()) { ImmutableList<CellName> namesForPath = RichStream.from(pathToRelativeName.get(pathWithOverrides)) .filter(name -> name.getLegacyName().isPresent()).toImmutableList(); if (namesForPath.size() > 1) { throw new InvalidCellOverrideException( String.format("Configuration override is ambiguous: cell rooted at %s is reachable " + "as [%s]. Please override the config by placing a .buckconfig.local file in the " + "cell's root folder.", pathWithOverrides, Joiner.on(',').join(namesForPath))); } } Map<Path, RawConfig> overridesByPath = new HashMap<>(); for (Map.Entry<CellName, Path> entry : pathMapping.entrySet()) { CellName cellRelativeName = entry.getKey(); Path cellPath = entry.getValue(); RawConfig configFromOtherRelativeName = overridesByPath.get(cellPath); RawConfig config = getForCell(cellRelativeName); if (configFromOtherRelativeName != null) { // Merge configs RawConfig mergedConfig = RawConfig.builder().putAll(configFromOtherRelativeName).putAll(config) .build(); overridesByPath.put(cellPath, mergedConfig); } else { overridesByPath.put(cellPath, config); } } return ImmutableMap.copyOf(overridesByPath); }
From source file:org.prebake.service.tools.ext.JunitHtmlReportGenerator.java
private static Map<String, Integer> generateHtmlReportOnePackage(String packageName, Collection<Map<?, ?>> tests, Path reportDir, List<String> resultTypes) throws IOException { ImmutableMultimap<String, Map<?, ?>> byClass = groupBy(tests, new Function<Map<?, ?>, String>() { public String apply(Map<?, ?> test) { String className = getIfOfType(test, ReportKey.CLASS_NAME, String.class); int lastDot = className.lastIndexOf('.'); return lastDot >= 0 ? className.substring(lastDot + 1) : className; }//from ww w . j av a 2 s. c o m }); Map<String, Integer> summary = Maps.newHashMap(); ImmutableList.Builder<Html> table = ImmutableList.builder(); Path outFile = reportDir.resolve(packageName + PACKAGE_FILE_SUFFIX + ".html"); mkdirs(outFile.getParent()); String[] classNames = byClass.keySet().toArray(NO_STRINGS); Arrays.sort(classNames); for (String className : classNames) { Collection<Map<?, ?>> classTests = byClass.get(className); Map<String, Integer> itemSummary = generateHtmlReportOneClass(packageName, className, classTests, reportDir.resolve(packageName), resultTypes); bagPutAll(itemSummary, summary); table.add(htmlLink(packageName + "/" + className + ".html", className)) .add(htmlSpan("summary", summaryToHtml(itemSummary, resultTypes))); } writeReport(outFile, "package " + packageName, KEY_VAL, table.build(), summary, tests, resultTypes, "index", packageName + PACKAGE_FILE_SUFFIX); return summary; }
From source file:com.facebook.buck.config.AbstractCellConfig.java
/** * Translates the 'cell name'->override map into a 'Path'->override map. * @param pathMapping a map containing paths to all of the cells we want to query. * @return 'Path'->override map/* w w w . j av a2s . co m*/ */ public ImmutableMap<Path, RawConfig> getOverridesByPath(ImmutableMap<RelativeCellName, Path> pathMapping) throws MalformedOverridesException { ImmutableSet<RelativeCellName> relativeNamesOfCellsWithOverrides = FluentIterable.from(getValues().keySet()) .filter(Predicates.not(ALL_CELLS_OVERRIDE::equals)).toSet(); ImmutableSet.Builder<Path> pathsWithOverrides = ImmutableSet.builder(); for (RelativeCellName cellWithOverride : relativeNamesOfCellsWithOverrides) { if (!pathMapping.containsKey(cellWithOverride)) { throw new MalformedOverridesException( String.format("Trying to override settings for unknown cell %s", cellWithOverride)); } pathsWithOverrides.add(pathMapping.get(cellWithOverride)); } ImmutableMultimap<Path, RelativeCellName> pathToRelativeName = Multimaps.index(pathMapping.keySet(), Functions.forMap(pathMapping)); for (Path pathWithOverrides : pathsWithOverrides.build()) { ImmutableCollection<RelativeCellName> namesForPath = pathToRelativeName.get(pathWithOverrides); if (namesForPath.size() > 1) { throw new MalformedOverridesException( String.format("Configuration override is ambiguous: cell rooted at %s is reachable " + "as [%s]. Please override the config by placing a .buckconfig.local file in the " + "cell's root folder.", pathWithOverrides, Joiner.on(',').join(namesForPath))); } } Map<Path, RawConfig> overridesByPath = new HashMap<>(); for (Map.Entry<RelativeCellName, Path> entry : pathMapping.entrySet()) { RelativeCellName cellRelativeName = entry.getKey(); Path cellPath = entry.getValue(); RawConfig configFromOtherRelativeName = overridesByPath.get(cellPath); RawConfig config = getForCell(cellRelativeName); if (configFromOtherRelativeName != null) { Preconditions.checkState(configFromOtherRelativeName.equals(config), "Attempting to create cell %s at %s with conflicting overrides [%s] vs [%s].", cellRelativeName, cellPath, configFromOtherRelativeName, config); } else { overridesByPath.put(cellPath, config); } } return ImmutableMap.copyOf(overridesByPath); }
From source file:google.registry.tools.CreateAuctionCreditsCommand.java
/** * Stages the creation of RegistrarCredit and RegistrarCreditBalance instances for each * registrar in the provided multimap of credit amounts by registrar. The balance instance * created is the total of all the credit amounts for a given registrar. *//*w w w .ja v a2s .c o m*/ private void stageCreditCreations(ImmutableMultimap<Registrar, BigMoney> creditMap) { DateTime now = DateTime.now(UTC); CurrencyUnit currency = Registry.get(tld).getCurrency(); for (Registrar registrar : creditMap.keySet()) { // Use RoundingMode.UP to be nice and give registrars the extra fractional units. Money totalAmount = BigMoney.total(currency, creditMap.get(registrar)).toMoney(RoundingMode.UP); System.out.printf("Total auction credit balance for %s: %s\n", registrar.getClientId(), totalAmount); // Create the actual credit and initial credit balance. RegistrarCredit credit = new RegistrarCredit.Builder().setParent(registrar).setType(CreditType.AUCTION) .setCreationTime(now).setCurrency(currency).setTld(tld).build(); RegistrarCreditBalance creditBalance = new RegistrarCreditBalance.Builder().setParent(credit) .setEffectiveTime(effectiveTime).setWrittenTime(now).setAmount(totalAmount).build(); stageEntityChange(null, credit); stageEntityChange(null, creditBalance); } }