input -> checkNotNull(keyFunction.apply(input)), input -> valuesFunction.apply(input).peek(Preconditions::checkNotNull), MultimapBuilder.linkedHashKeys().arrayListValues()::<K, V>build), ImmutableListMultimap::copyOf);
ListMultimap<Long, AccumuloColumnConstraint> cardinalityToConstraints = MultimapBuilder.treeKeys().arrayListValues().build(); try { boolean earlyReturn = false;
input -> checkNotNull(keyFunction.apply(input)), input -> valuesFunction.apply(input).peek(Preconditions::checkNotNull), MultimapBuilder.linkedHashKeys().arrayListValues()::<K, V>build), ImmutableListMultimap::copyOf);
@Test public void testSerializeStringKey() throws Exception { Multimap<String, Integer> map = MultimapBuilder.hashKeys().arrayListValues().build(); map.put("a", 1); map.put("a", 2); map.put("a", 3); String json = mapper.writer().writeValueAsString(map); assertEquals(json, "{\"a\":[1,2,3]}"); }
public ClasspathEntrySnapshotBuilder(ResourceHasher classpathResourceHasher, StringInterner stringInterner) { this.classpathResourceHasher = classpathResourceHasher; this.stringInterner = stringInterner; this.normalizedSnapshots = MultimapBuilder.hashKeys().arrayListValues().build(); }
/** * Returns a {@code Collector} accumulating entries into an {@code ImmutableListMultimap}. * * <p>The keys of the entries are the result of applying the provided key mapping function while * the values are generated by applying the value mapping function and accumulated in the * encounter order of the stream. */ public static <T, K extends Comparable<K>, V> Collector<T, ?, ImmutableListMultimap<K, V>> groupingBySortedKeys( Function<? super T, ? extends K> keyFunction, Function<? super T, ? extends V> valueFunction) { return Collectors.collectingAndThen( Multimaps.toMultimap( keyFunction, valueFunction, MultimapBuilder.treeKeys().arrayListValues()::<K, V>build), ImmutableListMultimap::copyOf); }
}) .collect(Multimaps.toMultimap(Library::getLibraryKey, Function.identity(), MultimapBuilder.hashKeys().arrayListValues()::build));
}) .sorted(comparing(Pair::b)) .collect(() -> hashKeys().arrayListValues().build(), (map, pair) -> map.put(pair.a(), pair.b()), Multimap::putAll);
final ListMultimap<IndexSet, String> indexSets = MultimapBuilder.hashKeys().arrayListValues().build(); for (IndexSet indexSet : this.indexSets) { final String[] managedIndicesNames = indexSet.getManagedIndices();
/** Uses an {@link ArrayList} to store value collections. */ public ListMultimapBuilder<K0, Object> arrayListValues() { return arrayListValues(DEFAULT_EXPECTED_VALUES_PER_KEY); }
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; }
/** Uses an {@link ArrayList} to store value collections. */ public ListMultimapBuilder<K0, Object> arrayListValues() { return arrayListValues(DEFAULT_EXPECTED_VALUES_PER_KEY); }
@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()); } } }
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"); }
/** Uses an {@link ArrayList} to store value collections. */ public ListMultimapBuilder<K0, Object> arrayListValues() { return arrayListValues(DEFAULT_EXPECTED_VALUES_PER_KEY); }
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(); }
public void testTreeKeys_gwtCompatible() { ListMultimap<String, Integer> multimap = MultimapBuilder.treeKeys().arrayListValues().<String, Integer>build(); assertTrue(multimap.keySet() instanceof SortedSet); assertTrue(multimap.asMap() instanceof SortedMap); }
@GwtIncompatible // doesn't build without explicit type parameters on build() methods public void testTreeKeys() { ListMultimap<String, Integer> multimap = MultimapBuilder.treeKeys().arrayListValues().build(); assertTrue(multimap.keySet() instanceof SortedSet); assertTrue(multimap.asMap() instanceof SortedMap); }
@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(); }
public void testMultimapCollectorGenerics() { ListMultimap<Integer, String> unused = Stream.of("foo", "bar", "quux") .collect( Multimaps.toMultimap( String::length, s -> s, MultimapBuilder.treeKeys().arrayListValues()::build)); }