List of usage examples for com.google.common.collect Multimap get
Collection<V> get(@Nullable K key);
From source file:org.terasology.documentation.BindingScraper.java
/** * @param args (ignored)/*w w w .j a v a 2 s . c om*/ * @throws Exception if the module environment cannot be loaded */ public static void main(String[] args) throws Exception { ModuleManager moduleManager = ModuleManagerFactory.create(); // Holds normal input mappings where there is only one key Multimap<InputCategory, String> categories = ArrayListMultimap.create(); Multimap<String, Input> keys = ArrayListMultimap.create(); Map<String, String> desc = new HashMap<>(); for (Class<?> holdingType : moduleManager.getEnvironment().getTypesAnnotatedWith(InputCategory.class)) { InputCategory inputCategory = holdingType.getAnnotation(InputCategory.class); categories.put(inputCategory, null); for (String button : inputCategory.ordering()) { categories.put(inputCategory, button); } } for (Class<?> buttonEvent : moduleManager.getEnvironment() .getTypesAnnotatedWith(RegisterBindButton.class)) { DefaultBinding defBinding = buttonEvent.getAnnotation(DefaultBinding.class); RegisterBindButton info = buttonEvent.getAnnotation(RegisterBindButton.class); String cat = info.category(); String id = "engine:" + info.id(); desc.put(id, info.description()); if (cat.isEmpty()) { InputCategory inputCategory = findEntry(categories, id); if (inputCategory == null) { System.out.println("Invalid category for: " + info.id()); } } else { InputCategory inputCategory = findCategory(categories, cat); if (inputCategory != null) { categories.put(inputCategory, id); } else { System.out.println("Invalid category for: " + info.id()); } } if (defBinding != null) { // This handles bindings with just one key Input input = defBinding.type().getInput(defBinding.id()); keys.put(id, input); } else { // See if there is a multi-mapping for this button DefaultBindings multiBinding = buttonEvent.getAnnotation(DefaultBindings.class); // Annotation math magic. We're expecting a DefaultBindings containing one DefaultBinding pair if (multiBinding != null && multiBinding.value().length == 2) { DefaultBinding[] bindings = multiBinding.value(); Input primary = bindings[0].type().getInput(bindings[0].id()); Input secondary = bindings[1].type().getInput(bindings[1].id()); keys.put(id, primary); keys.put(id, secondary); } } } for (InputCategory row : categories.keySet()) { System.out.println("# " + row.displayName()); categories.get(row).stream().filter(entry -> entry != null) .forEach(entry -> System.out.println(desc.get(entry) + ": " + keys.get(entry))); } }
From source file:org.jclouds.digitalocean2.functions.LinkToListOptions.java
public static String getFirstOrNull(String key, Multimap<String, String> params) { return params.containsKey(key) ? emptyToNull(getFirst(params.get(key), null)) : null; }
From source file:se.curity.examples.oauth.FilterHelper.java
private static Optional<String> getSingleValue(String name, Multimap<String, String> initParams) { Collection<String> values = initParams.get(name); if (values.size() > 1) { throw new IllegalStateException(String.format("More than one value for parameter [%s]", name)); }//from w w w .ja v a 2 s . co m return Optional.ofNullable(Iterables.getFirst(values, null)); }
From source file:com.zimbra.cs.index.query.LuceneQuery.java
public static Collection<String> lookup(Multimap<String, String> multimap, String what) { Collection<String> types = multimap.get(what); if (types.isEmpty()) { types = ImmutableList.of(what); // Need new collection as original types is probably immutable }/*from w w w. jav a 2 s . co m*/ return types; }
From source file:org.icgc.dcc.portal.task.InstallTask.java
private static String value(Multimap<String, String> parameters, String name) { val values = parameters.get(name); return values.isEmpty() ? null : values.iterator().next(); }
From source file:com.google.caliper.runner.EnvironmentGetter.java
private static String describe(Multimap<String, String> cpuInfo, String s) { Collection<String> strings = cpuInfo.get(s); // TODO redo the ImmutableMultiset.toString() call so we don't get square brackets return (strings.size() == 1) ? strings.iterator().next() : ImmutableMultiset.copyOf(strings).toString(); }
From source file:org.terasology.documentation.BindingScraper.java
private static InputCategory findEntry(Multimap<InputCategory, String> categories, String id) { for (InputCategory x : categories.keySet()) { if (categories.get(x).contains(id)) { return x; }//w w w . j a v a 2 s .c o m } return null; }
From source file:org.jclouds.occi.util.HeaderConverter.java
@IgnoreJRERequirement public static Headers convertHeaders(Multimap<String, String> googleHeaders) { Headers javaHeaders = new Headers(); for (String key : googleHeaders.keySet()) { for (String value : googleHeaders.get(key)) { javaHeaders.add(key, value); }// w w w . ja v a 2 s.co m } return javaHeaders; }
From source file:com.eucalyptus.simpleworkflow.common.client.WorkflowRegistry.java
private static Iterable<Class<?>> lookup(final Multimap<Class<? extends ComponentId>, Class<?>> registry, final Class<? extends ComponentId> componentIdClass) { return registry.get(componentIdClass); }
From source file:org.killbill.billing.plugin.simpletax.util.InvoiceHelpers.java
/** * Utility method that computes the amount of a given * {@linkplain InvoiceItem invoice item}, taking any adjustments into * consideration./*from w w w . j a va 2 s .c om*/ * * @param item * An invoice item. Must not be {@code null}. * @param allAdjustments * All the adjustments items of all invoices (for the same * account as the invoice item above). Must not be {@code null}. * @return the adjusted amount, never {@code null}. * @throws NullPointerException * when {@code item} or {@code allAdjustments} are {@code null}. */ @Nonnull public static BigDecimal amountWithAdjustments(@Nonnull InvoiceItem item, @Nonnull Multimap<UUID, InvoiceItem> allAdjustments) { Iterable<InvoiceItem> adjustments = allAdjustments.get(item.getId()); BigDecimal amount = sumItems(adjustments); if (item.getAmount() != null) { amount = amount.add(item.getAmount()); } return amount; }