public void testGenerics_gwtCompatible() { ListMultimap<String, Integer> a = MultimapBuilder.hashKeys().arrayListValues().<String, Integer>build(); SortedSetMultimap<String, Integer> b = MultimapBuilder.linkedHashKeys().treeSetValues().<String, Integer>build(); SetMultimap<String, Integer> c = MultimapBuilder.treeKeys(String.CASE_INSENSITIVE_ORDER) .hashSetValues() .<String, Integer>build(); }
/** * Returns a {@code Multimap} with the specified implementation, initialized with the entries of * {@code multimap}. */ public <K extends K0, V extends V0> Multimap<K, V> build( Multimap<? extends K, ? extends V> multimap) { Multimap<K, V> result = build(); result.putAll(multimap); return result; }
@Override protected Multimap<State, State> getStateTransitions() { Multimap<State, State> result = MultimapBuilder.enumKeys(State.class).arrayListValues().build(); result.put(State.UNINITIALISED, State.NEW); result.put(State.UNINITIALISED, State.READY); result.put(State.NEW, State.SAVE_STATE_IN_WALLET); result.put(State.SAVE_STATE_IN_WALLET, State.PROVIDE_MULTISIG_CONTRACT_TO_SERVER); result.put(State.PROVIDE_MULTISIG_CONTRACT_TO_SERVER, State.READY); result.put(State.READY, State.EXPIRED); result.put(State.READY, State.CLOSED); return result; }
private Multimap<String, BaleenMention> collateMentionsIntoEntities( final Map<String, BaleenMention> mentions) { final Multimap<String, BaleenMention> map = MultimapBuilder.hashKeys().arrayListValues().build(); mentions.values().forEach(m -> map.put(m.getEntityId(), m)); return map; }
operationsGroupedByTag = LinkedHashMultimap.create(); } else { operationsGroupedByTag = MultimapBuilder.linkedHashKeys().treeSetValues(operationOrdering).build(); logger.debug("Added path operation '{}' to tag '{}'", operation, tag); operationsGroupedByTag.put(tag, operation);
private void addMetadata(JCas jCas, Document doc) { Multimap<String, Object> meta = MultimapBuilder.linkedHashKeys().linkedListValues().build(); for (Metadata metadata : JCasUtil.select(jCas, Metadata.class)) { String key = metadata.getKey(); if (key.contains(".")) { // Field names can't contain a "." in Mongo, so replace with a _ key = key.replaceAll("\\.", "_"); } meta.put(key, metadata.getValue()); } doc.append(FIELD_METADATA, meta.asMap()); }
.enumKeys(ScalarType.class) .hashSetValues() .build(); byTypeValues.put(value.getType(), value); if (byTypeValues.isEmpty()) { result = Collections.emptyList(); } else {
private void generateViewTests(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { Multimap<String, ViewTestData> viewTestMap = MultimapBuilder.linkedHashKeys().arrayListValues().build(); getTextTests(roundEnv, viewTestMap); getResTests(roundEnv, viewTestMap); Set<String> strings = viewTestMap.keys().elementSet(); String[] keys = strings.toArray(new String[strings.size()]); for (String key : keys) { processingEnv.getMessager().printMessage(Diagnostic.Kind.WARNING, key); createTest(key, viewTestMap.get(key)); } }
idxConstraintRangePairs.asMap().forEach((key, value) -> executor.submit(() -> { long cardinality = getColumnCardinality(schema, table, auths, key.getFamily(), key.getQualifier(), value); LOG.debug("Cardinality for column %s is %s", key.getName(), cardinality); ListMultimap<Long, AccumuloColumnConstraint> cardinalityToConstraints = MultimapBuilder.treeKeys().arrayListValues().build(); try { boolean earlyReturn = false; int numTasks = idxConstraintRangePairs.asMap().entrySet().size(); do {
public void testFlatteningToMultimap() { Collector<String, ?, ListMultimap<Character, Character>> collector = Multimaps.flatteningToMultimap( str -> str.charAt(0), str -> str.substring(1).chars().mapToObj(c -> (char) c), MultimapBuilder.linkedHashKeys().arrayListValues()::build); BiPredicate<Multimap<?, ?>, Multimap<?, ?>> equivalence = Equivalence.equals() .onResultOf((Multimap<?, ?> mm) -> ImmutableList.copyOf(mm.asMap().entrySet())) .and(Equivalence.equals()); ListMultimap<Character, Character> empty = MultimapBuilder.linkedHashKeys().arrayListValues().build(); ListMultimap<Character, Character> filled = MultimapBuilder.linkedHashKeys().arrayListValues().build(); filled.putAll('b', Arrays.asList('a', 'n', 'a', 'n', 'a')); filled.putAll('a', Arrays.asList('p', 'p', 'l', 'e')); filled.putAll('c', Arrays.asList('a', 'r', 'r', 'o', 't')); filled.putAll('a', Arrays.asList('s', 'p', 'a', 'r', 'a', 'g', 'u', 's')); filled.putAll('c', Arrays.asList('h', 'e', 'r', 'r', 'y')); CollectorTester.of(collector, equivalence) .expectCollects(empty) .expectCollects(filled, "banana", "apple", "carrot", "asparagus", "cherry"); }
synchronized void updateCache() { Multimap<String, Location> newClassNameLocations = HashMultimap.create(); for (ClassLoader loader : getKnownClassLoaders()) { updateCache(loader, newClassNameLocations); } updateCacheWithClasspathClasses(newClassNameLocations); updateCacheWithBootstrapClasses(newClassNameLocations); if (!newClassNameLocations.isEmpty()) { // multimap that sorts keys and de-dups values while maintains value ordering SetMultimap<String, Location> newMap = MultimapBuilder.treeKeys().linkedHashSetValues().build(); newMap.putAll(classNameLocations); newMap.putAll(newClassNameLocations); classNameLocations = ImmutableMultimap.copyOf(newMap); } }
/** Uses a hash table to map keys to value collections. */ public static MultimapBuilderWithKeys<Object> hashKeys() { return hashKeys(DEFAULT_EXPECTED_KEYS); }
@GwtIncompatible // serialization public void testSerialization() throws Exception { for (MultimapBuilderWithKeys<?> builderWithKeys : ImmutableList.of( MultimapBuilder.hashKeys(), MultimapBuilder.linkedHashKeys(), MultimapBuilder.treeKeys(), MultimapBuilder.enumKeys(RoundingMode.class))) { for (MultimapBuilder<?, ?> builder : ImmutableList.of( builderWithKeys.arrayListValues(), builderWithKeys.linkedListValues(), builderWithKeys.hashSetValues(), builderWithKeys.linkedHashSetValues(), builderWithKeys.treeSetValues(), builderWithKeys.enumSetValues(RoundingMode.class))) { /* * Temporarily inlining SerializableTester here for obscure internal reasons. */ reserializeAndAssert(builder.build()); } } }
/** * Uses a hash table to map keys to value collections. * * <p>The collections returned by {@link Multimap#keySet()}, {@link Multimap#keys()}, and {@link * Multimap#asMap()} will iterate through the keys in the order that they were first added to the * multimap, save that if all values associated with a key are removed and then the key is added * back into the multimap, that key will come last in the key iteration order. */ public static MultimapBuilderWithKeys<Object> linkedHashKeys() { return linkedHashKeys(DEFAULT_EXPECTED_KEYS); }
/** * Uses a naturally-ordered {@link TreeMap} to map keys to value collections. * * <p>The collections returned by {@link Multimap#keySet()}, {@link Multimap#keys()}, and {@link * Multimap#asMap()} will iterate through the keys in sorted order. * * <p>For all multimaps generated by the resulting builder, the {@link Multimap#keySet()} can be * safely cast to a {@link java.util.SortedSet}, and the {@link Multimap#asMap()} can safely be * cast to a {@link java.util.SortedMap}. */ @SuppressWarnings("rawtypes") public static MultimapBuilderWithKeys<Comparable> treeKeys() { return treeKeys(Ordering.natural()); }
static Multimap<String, String> multimapBuilder(final boolean caseSensitive) { return caseSensitive ? MultimapBuilder.hashKeys().arrayListValues().build() : MultimapBuilder.treeKeys(String.CASE_INSENSITIVE_ORDER).arrayListValues().build(); }
@Override public <K extends K0, V extends V0> ListMultimap<K, V> build( Multimap<? extends K, ? extends V> multimap) { return (ListMultimap<K, V>) super.build(multimap); } }
@Override protected Multimap<State, State> getStateTransitions() { Multimap<State, State> result = MultimapBuilder.enumKeys(State.class).arrayListValues().build(); result.put(State.UNINITIALISED, State.NEW); result.put(State.UNINITIALISED, State.READY); result.put(State.NEW, State.SAVE_STATE_IN_WALLET); result.put(State.SAVE_STATE_IN_WALLET, State.PROVIDE_MULTISIG_CONTRACT_TO_SERVER); result.put(State.PROVIDE_MULTISIG_CONTRACT_TO_SERVER, State.READY); result.put(State.READY, State.EXPIRED); result.put(State.READY, State.CLOSED); return result; }
/** Uses a hash table to map keys to value collections. */ public static MultimapBuilderWithKeys<Object> hashKeys() { return hashKeys(DEFAULT_EXPECTED_KEYS); }