/** * 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()); }
/** * 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()); }
/** * 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()); }
public void testMultimapCollectorGenerics() { ListMultimap<Integer, String> unused = Stream.of("foo", "bar", "quux") .collect( Multimaps.toMultimap( String::length, s -> s, MultimapBuilder.treeKeys().arrayListValues()::build)); }
ListMultimap<Long, AccumuloColumnConstraint> cardinalityToConstraints = MultimapBuilder.treeKeys().arrayListValues().build(); try { boolean earlyReturn = false;
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); }
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 // 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(); }
@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()); } } }
/** * 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); }
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 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()); }
/** * 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()); }
public void testMultimapCollectorGenerics() { ListMultimap<Integer, String> unused = Stream.of("foo", "bar", "quux") .collect( Multimaps.toMultimap( String::length, s -> s, MultimapBuilder.treeKeys().arrayListValues()::build)); }
static Multimap<String, String> multimapBuilder(final boolean caseSensitive) { return caseSensitive ? MultimapBuilder.hashKeys().arrayListValues().build() : MultimapBuilder.treeKeys(String.CASE_INSENSITIVE_ORDER).arrayListValues().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); }
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 // 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(); }