@Override protected BiMap<String, String> create(Entry<String, String>[] entries) { BiMap<String, String> result = HashBiMap.create(); for (Entry<String, String> entry : entries) { result.put(entry.getKey(), entry.getValue()); } return result; } }
@SuppressWarnings("unchecked") @Override public BiMap<Country, String> create(Object... entries) { BiMap<Country, String> result = EnumHashBiMap.create(Country.class); for (Object o : entries) { Entry<Country, String> entry = (Entry<Country, String>) o; result.put(entry.getKey(), entry.getValue()); } return result; }
@SuppressWarnings("unchecked") @Override public BiMap<Country, Currency> create(Object... entries) { BiMap<Country, Currency> result = EnumBiMap.create(Country.class, Currency.class); for (Object object : entries) { Entry<Country, Currency> entry = (Entry<Country, Currency>) object; 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(); }
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(); }
@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); } })
/** 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) { 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 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()); }
@SuppressWarnings("unchecked") @MapFeature.Require(SUPPORTS_PUT) @CollectionSize.Require(ZERO) public void testPutPresentKeyDifferentValue() { getMap().put(k0(), v0()); getMap().put(k0(), v1()); // verify that the bimap is changed, and that the old inverse mapping // from v1 -> v0 is deleted expectContents(Helpers.mapEntry(k0(), v1())); }