@Override public V put(K key, V value) { return putInternal(key, value); }
/** * Create a natural order tree map populated with the key/value pairs of * {@code copyFrom}. This map's keys must be mutually comparable and * non-null. * * <p>Even if {@code copyFrom} is a {@code SortedMap}, the constructed map * <strong>will not</strong> use {@code copyFrom}'s ordering. This * constructor always creates a naturally-ordered map. Because the {@code * TreeMap} constructor overloads are ambiguous, prefer to construct a map * and populate it in two steps: <pre> {@code * TreeMap<String, Integer> customOrderedMap * = new TreeMap<String, Integer>(copyFrom.comparator()); * customOrderedMap.putAll(copyFrom); * }</pre> */ public TreeMap(Map<? extends K, ? extends V> copyFrom) { this(); for (Map.Entry<? extends K, ? extends V> entry : copyFrom.entrySet()) { putInternal(entry.getKey(), entry.getValue()); } }
/** * Create a tree map with the ordering and key/value pairs of {@code * copyFrom}. This map's keys may only be null if the {@code copyFrom}'s * ordering permits. * * <p>The constructed map <strong>will always use</strong> {@code * copyFrom}'s ordering. Because the {@code TreeMap} constructor overloads * are ambiguous, prefer to construct a map and populate it in two steps: * <pre> {@code * TreeMap<String, Integer> customOrderedMap * = new TreeMap<String, Integer>(copyFrom.comparator()); * customOrderedMap.putAll(copyFrom); * }</pre> */ @SuppressWarnings("unchecked") // if copyFrom's keys are comparable this map's keys must be also public TreeMap(SortedMap<K, ? extends V> copyFrom) { Comparator<? super K> sourceComparator = copyFrom.comparator(); if (sourceComparator != null) { this.comparator = sourceComparator; } else { this.comparator = (Comparator<? super K>) NATURAL_ORDER; } for (Map.Entry<K, ? extends V> entry : copyFrom.entrySet()) { putInternal(entry.getKey(), entry.getValue()); } }
@SuppressWarnings("unchecked") // we have to trust that keys are Ks and values are Vs private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { GetField fields = stream.readFields(); comparator = (Comparator<? super K>) fields.get("comparator", null); if (comparator == null) { comparator = (Comparator<? super K>) NATURAL_ORDER; } int size = stream.readInt(); for (int i = 0; i < size; i++) { putInternal((K) stream.readObject(), (V) stream.readObject()); } }
@Override public V put(K key, V value) { return putInternal(key, value); }
@Override public V put(K key, V value) { return putInternal(key, value); }
@Override public V put(K key, V value) { return putInternal(key, value); }
@Override public V put(K key, V value) { return putInternal(key, value); }
@Override public V put(K key, V value) { return putInternal(key, value); }
@Override public V put(K key, V value) { return putInternal(key, value); }
@Override public V put(K key, V value) { return putInternal(key, value); }
/** * Create a natural order tree map populated with the key/value pairs of * {@code copyFrom}. This map's keys must be mutually comparable and * non-null. * * <p>Even if {@code copyFrom} is a {@code SortedMap}, the constructed map * <strong>will not</strong> use {@code copyFrom}'s ordering. This * constructor always creates a naturally-ordered map. Because the {@code * TreeMap} constructor overloads are ambiguous, prefer to construct a map * and populate it in two steps: <pre> {@code * TreeMap<String, Integer> customOrderedMap * = new TreeMap<String, Integer>(copyFrom.comparator()); * customOrderedMap.putAll(copyFrom); * }</pre> */ public TreeMap(Map<? extends K, ? extends V> copyFrom) { this(); for (Map.Entry<? extends K, ? extends V> entry : copyFrom.entrySet()) { putInternal(entry.getKey(), entry.getValue()); } }
/** * Create a natural order tree map populated with the key/value pairs of * {@code copyFrom}. This map's keys must be mutually comparable and * non-null. * * <p>Even if {@code copyFrom} is a {@code SortedMap}, the constructed map * <strong>will not</strong> use {@code copyFrom}'s ordering. This * constructor always creates a naturally-ordered map. Because the {@code * TreeMap} constructor overloads are ambiguous, prefer to construct a map * and populate it in two steps: <pre> {@code * TreeMap<String, Integer> customOrderedMap * = new TreeMap<String, Integer>(copyFrom.comparator()); * customOrderedMap.putAll(copyFrom); * }</pre> */ public TreeMap(Map<? extends K, ? extends V> copyFrom) { this(); for (Entry<? extends K, ? extends V> entry : copyFrom.entrySet()) { putInternal(entry.getKey(), entry.getValue()); } }
@SuppressWarnings("unchecked") // we have to trust that keys are Ks and values are Vs private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { GetField fields = stream.readFields(); comparator = (Comparator<? super K>) fields.get("comparator", null); if (comparator == null) { comparator = (Comparator<? super K>) NATURAL_ORDER; } int size = stream.readInt(); for (int i = 0; i < size; i++) { putInternal((K) stream.readObject(), (V) stream.readObject()); } }
@SuppressWarnings("unchecked") // we have to trust that keys are Ks and values are Vs private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { GetField fields = stream.readFields(); comparator = (Comparator<? super K>) fields.get("comparator", null); if (comparator == null) { comparator = (Comparator<? super K>) NATURAL_ORDER; } int size = stream.readInt(); for (int i = 0; i < size; i++) { putInternal((K) stream.readObject(), (V) stream.readObject()); } }
@SuppressWarnings("unchecked") // we have to trust that keys are Ks and values are Vs private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { GetField fields = stream.readFields(); comparator = (Comparator<? super K>) fields.get("comparator", null); if (comparator == null) { comparator = (Comparator<? super K>) NATURAL_ORDER; } int size = stream.readInt(); for (int i = 0; i < size; i++) { putInternal((K) stream.readObject(), (V) stream.readObject()); } }
@SuppressWarnings("unchecked") // we have to trust that keys are Ks and values are Vs private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { GetField fields = stream.readFields(); comparator = (Comparator<? super K>) fields.get("comparator", null); if (comparator == null) { comparator = (Comparator<? super K>) NATURAL_ORDER; } int size = stream.readInt(); for (int i = 0; i < size; i++) { putInternal((K) stream.readObject(), (V) stream.readObject()); } }
@SuppressWarnings("unchecked") // we have to trust that keys are Ks and values are Vs private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { GetField fields = stream.readFields(); comparator = (Comparator<? super K>) fields.get("comparator", null); if (comparator == null) { comparator = (Comparator<? super K>) NATURAL_ORDER; } int size = stream.readInt(); for (int i = 0; i < size; i++) { putInternal((K) stream.readObject(), (V) stream.readObject()); } }
@SuppressWarnings("unchecked") // we have to trust that keys are Ks and values are Vs private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { GetField fields = stream.readFields(); comparator = (Comparator<? super K>) fields.get("comparator", null); if (comparator == null) { comparator = (Comparator<? super K>) NATURAL_ORDER; } int size = stream.readInt(); for (int i = 0; i < size; i++) { putInternal((K) stream.readObject(), (V) stream.readObject()); } }
@SuppressWarnings("unchecked") // we have to trust that keys are Ks and values are Vs private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { GetField fields = stream.readFields(); comparator = (Comparator<? super K>) fields.get("comparator", null); if (comparator == null) { comparator = (Comparator<? super K>) NATURAL_ORDER; } int size = stream.readInt(); for (int i = 0; i < size; i++) { putInternal((K) stream.readObject(), (V) stream.readObject()); } }