/** * 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 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 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); }
input -> checkNotNull(keyFunction.apply(input)), input -> valuesFunction.apply(input).peek(Preconditions::checkNotNull), MultimapBuilder.linkedHashKeys().arrayListValues()::<K, V>build), ImmutableListMultimap::copyOf);
input -> checkNotNull(keyFunction.apply(input)), input -> valuesFunction.apply(input).peek(Preconditions::checkNotNull), MultimapBuilder.linkedHashKeys().linkedHashSetValues()::<K, V>build), ImmutableSetMultimap::copyOf);
input -> checkNotNull(keyFunction.apply(input)), input -> valuesFunction.apply(input).peek(Preconditions::checkNotNull), MultimapBuilder.linkedHashKeys().arrayListValues()::<K, V>build), ImmutableListMultimap::copyOf);
input -> checkNotNull(keyFunction.apply(input)), input -> valuesFunction.apply(input).peek(Preconditions::checkNotNull), MultimapBuilder.linkedHashKeys().linkedHashSetValues()::<K, V>build), ImmutableSetMultimap::copyOf);
/** * Returns a multimap whose keys are base directories and whose values are potential locations of * wire profile files. */ Multimap<Path, String> pathsToAttempt(Set<Location> protoLocations) { Multimap<Path, String> result = MultimapBuilder.linkedHashKeys().linkedHashSetValues().build(); for (Location location : protoLocations) { pathsToAttempt(result, location); } return result; }
private static Multimap<TypeVariableSymbol, TypeInfo> getResolvedGenerics( MethodInvocationTree tree) { Type type = ASTHelpers.getType(tree.getMethodSelect()); List<Type> from = new ArrayList<>(); List<Type> to = new ArrayList<>(); getSubst(type, from, to); Multimap<TypeVariableSymbol, TypeInfo> result = Streams.zip( from.stream(), to.stream(), (f, t) -> new TypeInfo((TypeVariableSymbol) f.asElement(), t, tree)) .collect( toMultimap( k -> k.sym, k -> k, MultimapBuilder.linkedHashKeys().arrayListValues()::build)); return result; }
operationsGroupedByTag = LinkedHashMultimap.create(); } else { operationsGroupedByTag = MultimapBuilder.linkedHashKeys().treeSetValues(operationOrdering).build();
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"); }
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(); }
@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()); } } }
@GwtIncompatible // doesn't build without explicit type parameters on build() methods public void testGenerics() { ListMultimap<String, Integer> a = MultimapBuilder.hashKeys().arrayListValues().build(); SortedSetMultimap<String, Integer> b = MultimapBuilder.linkedHashKeys().treeSetValues().build(); SetMultimap<String, Integer> c = MultimapBuilder.treeKeys(String.CASE_INSENSITIVE_ORDER).hashSetValues().build(); }
/** * Uses a {@link LinkedHashMap} 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 {@link LinkedHashMap} 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 {@link LinkedHashMap} 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); }
/** * Creates a new builder. The returned builder is equivalent to the builder * generated by {@link ImmutableSetMultimap#builder}. */ public Builder() { super(MultimapBuilder.linkedHashKeys().linkedHashSetValues().<K, V> build()); }
/** * Creates a new builder. The returned builder is equivalent to the builder * generated by {@link ImmutableMultimap#builder}. */ public Builder() { this(MultimapBuilder.linkedHashKeys().arrayListValues().<K, V> build()); }
/** * Returns a multimap whose keys are base directories and whose values are potential locations of * wire profile files. */ Multimap<Path, String> pathsToAttempt(Set<Location> protoLocations) { Multimap<Path, String> result = MultimapBuilder.linkedHashKeys().linkedHashSetValues().build(); for (Location location : protoLocations) { pathsToAttempt(result, location); } return result; }