196 */ |
196 */ |
197 public TreeMap(SortedMap<K, ? extends V> m) { |
197 public TreeMap(SortedMap<K, ? extends V> m) { |
198 comparator = m.comparator(); |
198 comparator = m.comparator(); |
199 try { |
199 try { |
200 buildFromSorted(m.size(), m.entrySet().iterator(), null, null); |
200 buildFromSorted(m.size(), m.entrySet().iterator(), null, null); |
201 } catch (java.io.IOException cannotHappen) { |
201 } catch (java.io.IOException | ClassNotFoundException cannotHappen) { |
202 } catch (ClassNotFoundException cannotHappen) { |
|
203 } |
202 } |
204 } |
203 } |
205 |
204 |
206 |
205 |
207 // Query Operations |
206 // Query Operations |
642 clone.descendingMap = null; |
640 clone.descendingMap = null; |
643 |
641 |
644 // Initialize clone with our mappings |
642 // Initialize clone with our mappings |
645 try { |
643 try { |
646 clone.buildFromSorted(size, entrySet().iterator(), null, null); |
644 clone.buildFromSorted(size, entrySet().iterator(), null, null); |
647 } catch (java.io.IOException cannotHappen) { |
645 } catch (java.io.IOException | ClassNotFoundException cannotHappen) { |
648 } catch (ClassNotFoundException cannotHappen) { |
|
649 } |
646 } |
650 |
647 |
651 return clone; |
648 return clone; |
652 } |
649 } |
653 |
650 |
1048 public void clear() { |
1045 public void clear() { |
1049 TreeMap.this.clear(); |
1046 TreeMap.this.clear(); |
1050 } |
1047 } |
1051 |
1048 |
1052 public Spliterator<V> spliterator() { |
1049 public Spliterator<V> spliterator() { |
1053 return new ValueSpliterator<K,V>(TreeMap.this, null, null, 0, -1, 0); |
1050 return new ValueSpliterator<>(TreeMap.this, null, null, 0, -1, 0); |
1054 } |
1051 } |
1055 } |
1052 } |
1056 |
1053 |
1057 class EntrySet extends AbstractSet<Map.Entry<K,V>> { |
1054 class EntrySet extends AbstractSet<Map.Entry<K,V>> { |
1058 public Iterator<Map.Entry<K,V>> iterator() { |
1055 public Iterator<Map.Entry<K,V>> iterator() { |
1088 public void clear() { |
1085 public void clear() { |
1089 TreeMap.this.clear(); |
1086 TreeMap.this.clear(); |
1090 } |
1087 } |
1091 |
1088 |
1092 public Spliterator<Map.Entry<K,V>> spliterator() { |
1089 public Spliterator<Map.Entry<K,V>> spliterator() { |
1093 return new EntrySpliterator<K,V>(TreeMap.this, null, null, 0, -1, 0); |
1090 return new EntrySpliterator<>(TreeMap.this, null, null, 0, -1, 0); |
1094 } |
1091 } |
1095 } |
1092 } |
1096 |
1093 |
1097 /* |
1094 /* |
1098 * Unlike Values and EntrySet, the KeySet class is static, |
1095 * Unlike Values and EntrySet, the KeySet class is static, |
2425 |
2422 |
2426 // Write out size (number of Mappings) |
2423 // Write out size (number of Mappings) |
2427 s.writeInt(size); |
2424 s.writeInt(size); |
2428 |
2425 |
2429 // Write out keys and values (alternating) |
2426 // Write out keys and values (alternating) |
2430 for (Iterator<Map.Entry<K,V>> i = entrySet().iterator(); i.hasNext(); ) { |
2427 for (Map.Entry<K, V> e : entrySet()) { |
2431 Map.Entry<K,V> e = i.next(); |
|
2432 s.writeObject(e.getKey()); |
2428 s.writeObject(e.getKey()); |
2433 s.writeObject(e.getValue()); |
2429 s.writeObject(e.getValue()); |
2434 } |
2430 } |
2435 } |
2431 } |
2436 |
2432 |
2457 |
2453 |
2458 /** Intended to be called only from TreeSet.addAll */ |
2454 /** Intended to be called only from TreeSet.addAll */ |
2459 void addAllForTreeSet(SortedSet<? extends K> set, V defaultVal) { |
2455 void addAllForTreeSet(SortedSet<? extends K> set, V defaultVal) { |
2460 try { |
2456 try { |
2461 buildFromSorted(set.size(), set.iterator(), null, defaultVal); |
2457 buildFromSorted(set.size(), set.iterator(), null, defaultVal); |
2462 } catch (java.io.IOException cannotHappen) { |
2458 } catch (java.io.IOException | ClassNotFoundException cannotHappen) { |
2463 } catch (ClassNotFoundException cannotHappen) { |
|
2464 } |
2459 } |
2465 } |
2460 } |
2466 |
2461 |
2467 |
2462 |
2468 /** |
2463 /** |
2629 (NavigableSubMap<K,?>) m; |
2624 (NavigableSubMap<K,?>) m; |
2630 return sm.keySpliterator(); |
2625 return sm.keySpliterator(); |
2631 } |
2626 } |
2632 |
2627 |
2633 final Spliterator<K> keySpliterator() { |
2628 final Spliterator<K> keySpliterator() { |
2634 return new KeySpliterator<K,V>(this, null, null, 0, -1, 0); |
2629 return new KeySpliterator<>(this, null, null, 0, -1, 0); |
2635 } |
2630 } |
2636 |
2631 |
2637 final Spliterator<K> descendingKeySpliterator() { |
2632 final Spliterator<K> descendingKeySpliterator() { |
2638 return new DescendingKeySpliterator<K,V>(this, null, null, 0, -2, 0); |
2633 return new DescendingKeySpliterator<>(this, null, null, 0, -2, 0); |
2639 } |
2634 } |
2640 |
2635 |
2641 /** |
2636 /** |
2642 * Base class for spliterators. Iteration starts at a given |
2637 * Base class for spliterators. Iteration starts at a given |
2643 * origin and continues up to but not including a given fence (or |
2638 * origin and continues up to but not including a given fence (or |