@Override BiMap<String, Integer> createUnfiltered() { return HashBiMap.create(); } }
/** * Constructs a new bimap containing initial values from {@code map}. The bimap is created with an * initial capacity sufficient to hold the mappings in the specified map. */ public static <K, V> HashBiMap<K, V> create(Map<? extends K, ? extends V> map) { HashBiMap<K, V> bimap = create(map.size()); bimap.putAll(map); return bimap; }
@Generates private static <K, V> HashBiMap<K, V> generateHashBiMap(K key, V value) { HashBiMap<K, V> bimap = HashBiMap.create(); bimap.put(key, value); return bimap; }
@Override protected BiMap<String, String> create(Entry<String, String>[] entries) { Object mutex = new Object(); BiMap<String, String> result = HashBiMap.create(); for (Entry<String, String> entry : entries) { checkArgument(!result.containsKey(entry.getKey())); result.put(entry.getKey(), entry.getValue()); } return Maps.synchronizedBiMap(result); } }
@Override protected BiMap<String, String> create(Entry<String, String>[] entries) { BiMap<String, String> bimap = HashBiMap.create(entries.length); for (Entry<String, String> entry : entries) { checkArgument(!bimap.containsKey(entry.getKey())); bimap.put(entry.getKey(), entry.getValue()); } return Maps.unmodifiableBiMap(bimap); } })
public void testInsertionOrder() { BiMap<String, Integer> map = HashBiMap.create(); map.put("foo", 1); map.put("bar", 2); map.put("quux", 3); assertThat(map.entrySet()) .containsExactly( Maps.immutableEntry("foo", 1), Maps.immutableEntry("bar", 2), Maps.immutableEntry("quux", 3)) .inOrder(); }
public void testInverseInsertionOrderAfterInverse() { BiMap<String, Integer> map = HashBiMap.create(); map.put("bar", 2); map.put("quux", 1); assertThat(map.inverse().entrySet()) .containsExactly(Maps.immutableEntry(2, "bar"), Maps.immutableEntry(1, "quux")) .inOrder(); }
@Override protected BiMap<String, String> create(Entry<String, String>[] entries) { Object mutex = new Object(); BiMap<String, String> backing = new TestBiMap<>(HashBiMap.<String, String>create(), mutex); BiMap<String, String> result = Synchronized.biMap(backing, mutex); for (Entry<String, String> entry : entries) { checkArgument(!result.containsKey(entry.getKey())); result.put(entry.getKey(), entry.getValue()); } return result; } }
public void testInverseInsertionOrderAfterInverseForcePut() { BiMap<String, Integer> map = HashBiMap.create(); map.put("foo", 1); map.put("bar", 2); map.put("quux", 3); map.inverse().forcePut(1, "quux"); assertThat(map.inverse().entrySet()) .containsExactly(Maps.immutableEntry(2, "bar"), Maps.immutableEntry(1, "quux")) .inOrder(); }
@Override protected BiMap<String, String> create(Entry<String, String>[] entries) { BiMap<String, String> map = HashBiMap.create(); putEntries(map, entries); map.putAll(ENTRIES_TO_FILTER); return Maps.filterKeys(map, FILTER_KEYS); } })
public void testInsertionOrderAfterInverseForcePut() { BiMap<String, Integer> map = HashBiMap.create(); map.put("foo", 1); map.put("bar", 2); map.put("quux", 3); map.inverse().forcePut(1, "quux"); assertThat(map.entrySet()) .containsExactly(Maps.immutableEntry("bar", 2), Maps.immutableEntry("quux", 1)) .inOrder(); }
public void testInsertionOrderAfterForcePut() { BiMap<String, Integer> map = HashBiMap.create(); map.put("foo", 1); map.put("bar", 2); map.put("quux", 3); map.forcePut("quux", 1); assertThat(map.entrySet()) .containsExactly(Maps.immutableEntry("bar", 2), Maps.immutableEntry("quux", 1)) .inOrder(); }
public void testBiMapEntrySetIteratorRemove() { BiMap<Integer, String> map = HashBiMap.create(); map.put(1, "one"); Set<Entry<Integer, String>> entries = map.entrySet(); Iterator<Entry<Integer, String>> iterator = entries.iterator(); Entry<Integer, String> entry = iterator.next(); entry.setValue("two"); // changes the iterator's current entry value assertEquals("two", map.get(1)); assertEquals(Integer.valueOf(1), map.inverse().get("two")); iterator.remove(); // removes the updated entry assertTrue(map.isEmpty()); }
public void testInsertionOrderAfterRemoveMiddle() { BiMap<String, Integer> map = HashBiMap.create(); map.put("foo", 1); map.put("bar", 2); map.put("quux", 3); map.remove("bar"); assertThat(map.entrySet()) .containsExactly(Maps.immutableEntry("foo", 1), Maps.immutableEntry("quux", 3)) .inOrder(); }
public void testInsertionOrderAfterRemoveLast() { BiMap<String, Integer> map = HashBiMap.create(); map.put("foo", 1); map.put("bar", 2); map.put("quux", 3); map.remove("quux"); assertThat(map.entrySet()) .containsExactly(Maps.immutableEntry("foo", 1), Maps.immutableEntry("bar", 2)) .inOrder(); }
/** See {@link SynchronizedBiMapTest} for more tests. */ public void testSynchronizedBiMap() { BiMap<String, Integer> bimap = HashBiMap.create(); bimap.put("one", 1); BiMap<String, Integer> sync = Maps.synchronizedBiMap(bimap); bimap.put("two", 2); sync.put("three", 3); assertEquals(ImmutableSet.of(1, 2, 3), bimap.inverse().keySet()); assertEquals(ImmutableSet.of(1, 2, 3), sync.inverse().keySet()); }
@Override protected BiMap<String, String> create(Entry<String, String>[] entries) { BiMap<String, String> map = HashBiMap.create(); putEntries(map, entries); map.putAll(ENTRIES_TO_FILTER); return Maps.filterValues(map, FILTER_VALUES); } })
@Override protected BiMap<String, String> create(Entry<String, String>[] entries) { BiMap<String, String> map = HashBiMap.create(); putEntries(map, entries); map.putAll(ENTRIES_TO_FILTER); return Maps.filterEntries(map, FILTER_ENTRIES); } })
public void testCreate() { EnumBiMap<Currency, Country> bimap = EnumBiMap.create(Currency.class, Country.class); assertTrue(bimap.isEmpty()); assertEquals("{}", bimap.toString()); assertEquals(HashBiMap.create(), bimap); bimap.put(Currency.DOLLAR, Country.CANADA); assertEquals(Country.CANADA, bimap.get(Currency.DOLLAR)); assertEquals(Currency.DOLLAR, bimap.inverse().get(Country.CANADA)); }
public void testCreate() { EnumHashBiMap<Currency, String> bimap = EnumHashBiMap.create(Currency.class); assertTrue(bimap.isEmpty()); assertEquals("{}", bimap.toString()); assertEquals(HashBiMap.create(), bimap); bimap.put(Currency.DOLLAR, "dollar"); assertEquals("dollar", bimap.get(Currency.DOLLAR)); assertEquals(Currency.DOLLAR, bimap.inverse().get("dollar")); }