/** * Returns an immutable multimap containing the given entries, in the "key-grouped" insertion * order described in the <a href="#iteration">class documentation</a>. */ public static <K, V> ImmutableMultimap<K, V> of( K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5) { return ImmutableListMultimap.of(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5); }
/** * Returns an immutable multimap containing the given entries, in the "key-grouped" insertion * order described in the <a href="#iteration">class documentation</a>. */ public static <K, V> ImmutableMultimap<K, V> of(K k1, V v1, K k2, V v2, K k3, V v3) { return ImmutableListMultimap.of(k1, v1, k2, v2, k3, v3); }
/** * Returns an immutable multimap containing the given entries, in the "key-grouped" insertion * order described in the <a href="#iteration">class documentation</a>. */ public static <K, V> ImmutableMultimap<K, V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4) { return ImmutableListMultimap.of(k1, v1, k2, v2, k3, v3, k4, v4); }
/** Returns an immutable multimap containing the given entries, in order. */ public static <K, V> ImmutableMultimap<K, V> of(K k1, V v1, K k2, V v2) { return ImmutableListMultimap.of(k1, v1, k2, v2); }
/** Returns an immutable multimap containing a single entry. */ public static <K, V> ImmutableMultimap<K, V> of(K k1, V v1) { return ImmutableListMultimap.of(k1, v1); }
/** Returns an empty multimap. */ public static <K, V> ImmutableMultimap<K, V> of() { return ImmutableListMultimap.of(); }
/** * Creates a new media type with the given type and subtype. * * @throws IllegalArgumentException if type or subtype is invalid or if a wildcard is used for the * type, but not the subtype. */ public static MediaType create(String type, String subtype) { MediaType mediaType = create(type, subtype, ImmutableListMultimap.<String, String>of()); mediaType.parsedCharset = Optional.absent(); return mediaType; }
@Generates private static <K, V> ImmutableListMultimap<K, V> generateImmutableListMultimap(K key, V value) { return ImmutableListMultimap.of(key, value); }
private static MediaType createConstant(String type, String subtype) { MediaType mediaType = addKnownType(new MediaType(type, subtype, ImmutableListMultimap.<String, String>of())); mediaType.parsedCharset = Optional.absent(); return mediaType; }
public void testEmptyMultimapWrites() { Multimap<String, Integer> multimap = ImmutableListMultimap.of(); UnmodifiableCollectionTests.assertMultimapIsUnmodifiable(multimap, "foo", 1); }
public void testInverse() { assertEquals( ImmutableListMultimap.<Integer, String>of(), ImmutableListMultimap.<String, Integer>of().inverse()); assertEquals(ImmutableListMultimap.of(1, "one"), ImmutableListMultimap.of("one", 1).inverse()); assertEquals( ImmutableListMultimap.of(1, "one", 2, "two"), ImmutableListMultimap.of("one", 1, "two", 2).inverse()); assertEquals( ImmutableListMultimap.of("of", 'o', "of", 'f', "to", 't', "to", 'o').inverse(), ImmutableListMultimap.of('o', "of", 'f', "of", 't', "to", 'o', "to")); assertEquals( ImmutableListMultimap.of('f', "foo", 'o', "foo", 'o', "foo"), ImmutableListMultimap.of("foo", 'f', "foo", 'o', "foo", 'o').inverse()); }
@GwtIncompatible(value = "untested") public void testTransformListEntries() { ListMultimap<String, Integer> multimap = ImmutableListMultimap.of("a", 1, "a", 4, "b", 6, "a", 4); EntryTransformer<String, Integer, String> transformer = new EntryTransformer<String, Integer, String>() { @Override public String transformEntry(String key, Integer value) { return key + value; } }; ListMultimap<String, String> transformed = Multimaps.transformEntries(multimap, transformer); assertEquals(ImmutableListMultimap.of("a", "a1", "a", "a4", "a", "a4", "b", "b6"), transformed); assertEquals("{a=[a1, a4, a4], b=[b6]}", transformed.toString()); }
@GwtIncompatible // SerializableTester public void testEmptySerialization() { Multimap<String, Integer> multimap = ImmutableListMultimap.of(); assertSame(multimap, SerializableTester.reserialize(multimap)); } }
public void testWithParameters_invalidAttribute() { MediaType mediaType = MediaType.parse("text/plain"); ImmutableListMultimap<String, String> parameters = ImmutableListMultimap.of("a", "1", "@", "2", "b", "3"); try { mediaType.withParameters(parameters); fail(); } catch (IllegalArgumentException expected) { } }
public void testEmptyMultimapReads() { Multimap<String, Integer> multimap = ImmutableListMultimap.of(); assertFalse(multimap.containsKey("foo")); assertFalse(multimap.containsValue(1)); assertFalse(multimap.containsEntry("foo", 1)); assertTrue(multimap.entries().isEmpty()); assertTrue(multimap.equals(ArrayListMultimap.create())); assertEquals(Collections.emptyList(), multimap.get("foo")); assertEquals(0, multimap.hashCode()); assertTrue(multimap.isEmpty()); assertEquals(HashMultiset.create(), multimap.keys()); assertEquals(Collections.emptySet(), multimap.keySet()); assertEquals(0, multimap.size()); assertTrue(multimap.values().isEmpty()); assertEquals("{}", multimap.toString()); }
public void testGetParameters() { assertEquals(ImmutableListMultimap.of(), MediaType.parse("text/plain").parameters()); assertEquals( ImmutableListMultimap.of("charset", "utf-8"), MediaType.parse("application/atom+xml; charset=utf-8").parameters()); assertEquals(PARAMETERS, MediaType.parse("application/atom+xml; a=1; a=2; b=3").parameters()); }
public void testCopyOf() { ImmutableSetMultimap<String, String> setMultimap = ImmutableSetMultimap.of("k1", "v1"); ImmutableMultimap<String, String> setMultimapCopy = ImmutableMultimap.copyOf(setMultimap); assertSame( "copyOf(ImmutableSetMultimap) should not create a new instance", setMultimap, setMultimapCopy); ImmutableListMultimap<String, String> listMultimap = ImmutableListMultimap.of("k1", "v1"); ImmutableMultimap<String, String> listMultimapCopy = ImmutableMultimap.copyOf(listMultimap); assertSame( "copyOf(ImmutableListMultimap) should not create a new instance", listMultimap, listMultimapCopy); }
@SuppressWarnings("deprecation") public void testUnmodifiableListMultimapShortCircuit() { ListMultimap<String, Integer> mod = ArrayListMultimap.create(); ListMultimap<String, Integer> unmod = Multimaps.unmodifiableListMultimap(mod); assertNotSame(mod, unmod); assertSame(unmod, Multimaps.unmodifiableListMultimap(unmod)); ImmutableListMultimap<String, Integer> immutable = ImmutableListMultimap.of("a", 1, "b", 2, "a", 3); assertSame(immutable, Multimaps.unmodifiableListMultimap(immutable)); assertSame( immutable, Multimaps.unmodifiableListMultimap((ListMultimap<String, Integer>) immutable)); }
public void testToImmutableListMultimap() { Collector<Entry<String, Integer>, ?, ImmutableListMultimap<String, Integer>> collector = ImmutableListMultimap.toImmutableListMultimap(Entry::getKey, Entry::getValue); BiPredicate<ImmutableListMultimap<?, ?>, ImmutableListMultimap<?, ?>> equivalence = Equivalence.equals() .onResultOf((ImmutableListMultimap<?, ?> mm) -> mm.asMap().entrySet().asList()) .and(Equivalence.equals()); CollectorTester.of(collector, equivalence) .expectCollects(ImmutableListMultimap.of()) .expectCollects( ImmutableListMultimap.of("a", 1, "b", 2, "a", 3, "c", 4), mapEntry("a", 1), mapEntry("b", 2), mapEntry("a", 3), mapEntry("c", 4)); }