@GwtIncompatible("java.io.ObjectInputStream") private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); expectedValuesPerKey = stream.readInt(); int distinctKeys = Serialization.readCount(stream); setMap(new LinkedHashMap<K, Collection<V>>(Maps.capacity(distinctKeys))); linkedEntries = new LinkedHashSet<Map.Entry<K, V>>(distinctKeys * expectedValuesPerKey); Serialization.populateMultimap(this, stream, distinctKeys); linkedEntries.clear(); // will clear and repopulate entries for (int i = 0; i < size(); i++) { @SuppressWarnings("unchecked") // reading data stored by writeObject K key = (K) stream.readObject(); @SuppressWarnings("unchecked") // reading data stored by writeObject V value = (V) stream.readObject(); linkedEntries.add(Maps.immutableEntry(key, value)); } }
/** * {@inheritDoc} * * <p>Creates an empty {@code LinkedHashSet} for a collection of values for one key. * * @return a new {@code LinkedHashSet} containing a collection of values for one key */ @Override Set<V> createCollection() { return new LinkedHashSet<V>(Maps.capacity(expectedValuesPerKey)); }
private LinkedHashMultimap(Multimap<? extends K, ? extends V> multimap) { super(new LinkedHashMap<K, Collection<V>>(Maps.capacity(multimap.keySet().size()))); linkedEntries = new LinkedHashSet<Map.Entry<K, V>>(Maps.capacity(multimap.size())); putAll(multimap); }