@Override protected BiMap<String, String> create(Entry<String, String>[] entries) { return ImmutableBiMap.copyOf(Arrays.asList(entries)); } }
@Override protected BiMap<String, String> create(Entry<String, String>[] entries) { Map<String, String> builder = Maps.newLinkedHashMap(); for (Entry<String, String> entry : entries) { builder.put(entry.getKey(), entry.getValue()); } return ImmutableBiMap.copyOf(builder); } }
public static ImmutableBiMap<Object, Object> instantiate(SerializationStreamReader reader) throws SerializationException { Map<Object, Object> entries = new LinkedHashMap<>(); Map_CustomFieldSerializerBase.deserialize(reader, entries); return ImmutableBiMap.copyOf(entries); }
public static ImmutableBiMap<Object, Object> instantiate(SerializationStreamReader reader) throws SerializationException { Map<Object, Object> entries = new LinkedHashMap<>(); Map_CustomFieldSerializerBase.deserialize(reader, entries); return ImmutableBiMap.copyOf(entries); }
@Override ImmutableBiMap<?, ?> create(List<? extends Entry<?, ?>> entries, CallsCounter counter) { return ImmutableBiMap.copyOf(entries); } },
@Override public <K extends Comparable<K>, V> BiMap<K, V> create(Map<K, V> map) { return ImmutableBiMap.copyOf(map); } };
static <N, E> UndirectedNetworkConnections<N, E> ofImmutable(Map<E, N> incidentEdges) { return new UndirectedNetworkConnections<>(ImmutableBiMap.copyOf(incidentEdges)); }
public void testCopyOf() { Map<String, Integer> original = new LinkedHashMap<>(); original.put("one", 1); original.put("two", 2); original.put("three", 3); ImmutableBiMap<String, Integer> copy = ImmutableBiMap.copyOf(original); assertMapEquals(copy, "one", 1, "two", 2, "three", 3); assertSame(copy, ImmutableBiMap.copyOf(copy)); }
public void testFromHashMap() { Map<String, Integer> hashMap = Maps.newLinkedHashMap(); hashMap.put("one", 1); hashMap.put("two", 2); ImmutableBiMap<String, Integer> bimap = ImmutableBiMap.copyOf(ImmutableMap.of("one", 1, "two", 2)); assertMapEquals(bimap, "one", 1, "two", 2); assertMapEquals(bimap.inverse(), 1, "one", 2, "two"); }
@Override ImmutableBiMap<?, ?> create(List<? extends Entry<?, ?>> entries, CallsCounter counter) { Map<Object, Object> sourceMap = new LinkedHashMap<>(); for (Entry<?, ?> entry : entries) { if (sourceMap.put(entry.getKey(), entry.getValue()) != null) { throw new UnsupportedOperationException("duplicate key"); } } counter.zero(); return ImmutableBiMap.copyOf(sourceMap); } },
public void testFromImmutableMap() { ImmutableBiMap<String, Integer> bimap = ImmutableBiMap.copyOf( new ImmutableMap.Builder<String, Integer>() .put("one", 1) .put("two", 2) .put("three", 3) .put("four", 4) .put("five", 5) .build()); assertMapEquals(bimap, "one", 1, "two", 2, "three", 3, "four", 4, "five", 5); assertMapEquals(bimap.inverse(), 1, "one", 2, "two", 3, "three", 4, "four", 5, "five"); }
public void testForcePut() { BiMap<String, Integer> bimap = ImmutableBiMap.copyOf(ImmutableMap.of("one", 1, "two", 2)); try { bimap.forcePut("three", 3); fail(); } catch (UnsupportedOperationException expected) { } }
public void testValues() { ImmutableBiMap<String, Integer> bimap = ImmutableBiMap.copyOf(ImmutableMap.of("one", 1, "two", 2, "three", 3, "four", 4)); Set<Integer> values = bimap.values(); assertEquals(Sets.newHashSet(1, 2, 3, 4), values); assertThat(values).containsExactly(1, 2, 3, 4).inOrder(); }
public void testKeySet() { ImmutableBiMap<String, Integer> bimap = ImmutableBiMap.copyOf(ImmutableMap.of("one", 1, "two", 2, "three", 3, "four", 4)); Set<String> keys = bimap.keySet(); assertEquals(Sets.newHashSet("one", "two", "three", "four"), keys); assertThat(keys).containsExactly("one", "two", "three", "four").inOrder(); }
public void testDoubleInverse() { ImmutableBiMap<String, Integer> bimap = ImmutableBiMap.copyOf(ImmutableMap.of("one", 1, "two", 2)); assertSame(bimap, bimap.inverse().inverse()); }
@GwtIncompatible // SerializableTester public void testSerialization() { ImmutableBiMap<String, Integer> bimap = ImmutableBiMap.copyOf(ImmutableMap.of("one", 1, "two", 2)); ImmutableBiMap<String, Integer> copy = SerializableTester.reserializeAndAssert(bimap); assertEquals(Integer.valueOf(1), copy.get("one")); assertEquals("one", copy.inverse().get(1)); assertSame(copy, copy.inverse().inverse()); }
@GwtIncompatible // SerializableTester public void testInverseSerialization() { ImmutableBiMap<String, Integer> bimap = ImmutableBiMap.copyOf(ImmutableMap.of(1, "one", 2, "two")).inverse(); ImmutableBiMap<String, Integer> copy = SerializableTester.reserializeAndAssert(bimap); assertEquals(Integer.valueOf(1), copy.get("one")); assertEquals("one", copy.inverse().get(1)); assertSame(copy, copy.inverse().inverse()); } }