private EnumHashBiMap(Class<K> keyType) { super( WellBehavedMap.wrap(new EnumMap<K, V>(keyType)), Maps.<V, K>newHashMapWithExpectedSize(keyType.getEnumConstants().length)); this.keyType = keyType; }
@SuppressWarnings("unchecked") // reading fields populated by writeObject @GwtIncompatible // java.io.ObjectInputStream private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); keyType = (Class<K>) stream.readObject(); valueType = (Class<V>) stream.readObject(); setDelegates( WellBehavedMap.wrap(new EnumMap<K, V>(keyType)), WellBehavedMap.wrap(new EnumMap<V, K>(valueType))); Serialization.populateMap(this, stream); }
private EnumHashBiMap(Class<K> keyType) { super( WellBehavedMap.wrap(new EnumMap<K, V>(keyType)), Maps.<V, K>newHashMapWithExpectedSize(keyType.getEnumConstants().length)); this.keyType = keyType; }
@SuppressWarnings("unchecked") // reading field populated by writeObject @GwtIncompatible // java.io.ObjectInputStream private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); keyType = (Class<K>) stream.readObject(); setDelegates( WellBehavedMap.wrap(new EnumMap<K, V>(keyType)), new HashMap<V, K>(keyType.getEnumConstants().length * 3 / 2)); Serialization.populateMap(this, stream); }
private EnumHashBiMap(Class<K> keyType) { super( WellBehavedMap.wrap(new EnumMap<K, V>(keyType)), Maps.<V, K>newHashMapWithExpectedSize(keyType.getEnumConstants().length)); this.keyType = keyType; }
@SuppressWarnings("unchecked") // reading fields populated by writeObject @GwtIncompatible // java.io.ObjectInputStream private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); keyType = (Class<K>) stream.readObject(); valueType = (Class<V>) stream.readObject(); setDelegates( WellBehavedMap.wrap(new EnumMap<K, V>(keyType)), WellBehavedMap.wrap(new EnumMap<V, K>(valueType))); Serialization.populateMap(this, stream); }
@SuppressWarnings("unchecked") // reading field populated by writeObject @GwtIncompatible // java.io.ObjectInputStream private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); keyType = (Class<K>) stream.readObject(); setDelegates( WellBehavedMap.wrap(new EnumMap<K, V>(keyType)), new HashMap<V, K>(keyType.getEnumConstants().length * 3 / 2)); Serialization.populateMap(this, stream); }
@SuppressWarnings("unchecked") // reading fields populated by writeObject @GwtIncompatible // java.io.ObjectInputStream private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); keyType = (Class<K>) stream.readObject(); valueType = (Class<V>) stream.readObject(); setDelegates( WellBehavedMap.wrap(new EnumMap<K, V>(keyType)), WellBehavedMap.wrap(new EnumMap<V, K>(valueType))); Serialization.populateMap(this, stream); }
@SuppressWarnings("unchecked") // reading field populated by writeObject @GwtIncompatible // java.io.ObjectInputStream private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); keyType = (Class<K>) stream.readObject(); setDelegates( WellBehavedMap.wrap(new EnumMap<K, V>(keyType)), new HashMap<V, K>(keyType.getEnumConstants().length * 3 / 2)); Serialization.populateMap(this, stream); }
public void testEntry_setValue() { WellBehavedMap<Foo, Integer> map = WellBehavedMap.wrap(new EnumMap<Foo, Integer>(Foo.class)); map.putAll(ImmutableMap.of(Foo.X, 1, Foo.Y, 2, Foo.Z, 3)); for (Entry<Foo, Integer> entry : map.entrySet()) { entry.setValue(entry.getValue() + 5); } assertEquals(ImmutableMap.of(Foo.X, 6, Foo.Y, 7, Foo.Z, 8), map); }
public void testEntrySet_contain() { WellBehavedMap<Foo, Integer> map = WellBehavedMap.wrap(new EnumMap<Foo, Integer>(Foo.class)); map.putAll(ImmutableMap.of(Foo.X, 1, Foo.Y, 2, Foo.Z, 3)); // testing with the exact entry assertTrue(map.entrySet().contains(Maps.immutableEntry(Foo.X, 1))); assertTrue(map.entrySet().contains(Maps.immutableEntry(Foo.Y, new Integer(2)))); // testing an entry with a contained key, but not the same value assertFalse(map.entrySet().contains(Maps.immutableEntry(Foo.X, 5))); // testing a non-existent key assertFalse(map.entrySet().contains(Maps.immutableEntry(Foo.T, 0))); }
public void testEntriesAreMutableAndConsistent() { WellBehavedMap<Foo, Integer> map = WellBehavedMap.wrap(new EnumMap<Foo, Integer>(Foo.class)); map.putAll(ImmutableMap.of(Foo.X, 1)); Entry<Foo, Integer> entry1 = Iterables.getOnlyElement(map.entrySet()); Entry<Foo, Integer> entry2 = Iterables.getOnlyElement(map.entrySet()); // the entries are constructed and forgotten, thus different assertNotSame(entry1, entry2); Set<Entry<Foo, Integer>> entrySet = map.entrySet(); assertTrue(entrySet.contains(entry1)); assertTrue(entrySet.contains(entry2)); // mutating entry entry1.setValue(2); // entry2 is also modified assertEquals(entry1.getValue(), entry2.getValue()); // and both are still contained in the set assertTrue(entrySet.contains(entry1)); assertTrue(entrySet.contains(entry2)); }
public void testEntrySet_remove() { WellBehavedMap<Foo, Integer> map = WellBehavedMap.wrap(new EnumMap<Foo, Integer>(Foo.class)); map.putAll(ImmutableMap.of(Foo.X, 1, Foo.Y, 2, Foo.Z, 3)); Set<Entry<Foo, Integer>> entrySet = map.entrySet(); // removing an existing entry, verifying consistency Entry<Foo, Integer> entry = Maps.immutableEntry(Foo.Y, 2); assertTrue(entrySet.remove(entry)); assertFalse(map.containsKey(Foo.Y)); assertNull(map.get(Foo.Y)); assertFalse(entrySet.contains(entry)); // we didn't have that entry, not removed assertFalse(entrySet.remove(Maps.immutableEntry(Foo.T, 4))); // we didn't have that entry, only <Z, 3>, must not remove assertFalse(entrySet.remove(Maps.immutableEntry(Foo.Z, 5))); } }
/** Creates an empty {@code EnumMultiset}. */ private EnumMultiset(Class<E> type) { super(WellBehavedMap.wrap(new EnumMap<E, Count>(type))); this.type = type; }
private EnumHashBiMap(Class<K> keyType) { super(WellBehavedMap.wrap( new EnumMap<K, V>(keyType)), Maps.<V, K>newHashMapWithExpectedSize( keyType.getEnumConstants().length)); this.keyType = keyType; }
@SuppressWarnings("unchecked") // reading fields populated by writeObject @GwtIncompatible("java.io.ObjectInputStream") private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); keyType = (Class<K>) stream.readObject(); valueType = (Class<V>) stream.readObject(); setDelegates( WellBehavedMap.wrap(new EnumMap<K, V>(keyType)), WellBehavedMap.wrap(new EnumMap<V, K>(valueType))); Serialization.populateMap(this, stream); }
@SuppressWarnings("unchecked") // reading field populated by writeObject @GwtIncompatible("java.io.ObjectInputStream") private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); keyType = (Class<K>) stream.readObject(); setDelegates(WellBehavedMap.wrap(new EnumMap<K, V>(keyType)), new HashMap<V, K>(keyType.getEnumConstants().length * 3 / 2)); Serialization.populateMap(this, stream); }