Print this page


Split Close
Expand all
Collapse all
          --- old/src/share/classes/java/util/TreeMap.java
          +++ new/src/share/classes/java/util/TreeMap.java
↓ open down ↓ 1048 lines elided ↑ open up ↑
1049 1049          public void clear() { m.clear(); }
1050 1050          public E lower(E e) { return m.lowerKey(e); }
1051 1051          public E floor(E e) { return m.floorKey(e); }
1052 1052          public E ceiling(E e) { return m.ceilingKey(e); }
1053 1053          public E higher(E e) { return m.higherKey(e); }
1054 1054          public E first() { return m.firstKey(); }
1055 1055          public E last() { return m.lastKey(); }
1056 1056          public Comparator<? super E> comparator() { return m.comparator(); }
1057 1057          public E pollFirst() {
1058 1058              Map.Entry<E,Object> e = m.pollFirstEntry();
1059      -            return e == null? null : e.getKey();
     1059 +            return (e == null) ? null : e.getKey();
1060 1060          }
1061 1061          public E pollLast() {
1062 1062              Map.Entry<E,Object> e = m.pollLastEntry();
1063      -            return e == null? null : e.getKey();
     1063 +            return (e == null) ? null : e.getKey();
1064 1064          }
1065 1065          public boolean remove(Object o) {
1066 1066              int oldSize = size();
1067 1067              m.remove(o);
1068 1068              return size() != oldSize;
1069 1069          }
1070 1070          public NavigableSet<E> subSet(E fromElement, boolean fromInclusive,
1071 1071                                        E toElement,   boolean toInclusive) {
1072 1072              return new KeySet<E>(m.subMap(fromElement, fromInclusive,
1073 1073                                            toElement,   toInclusive));
↓ open down ↓ 115 lines elided ↑ open up ↑
1189 1189       */
1190 1190      final int compare(Object k1, Object k2) {
1191 1191          return comparator==null ? ((Comparable<? super K>)k1).compareTo((K)k2)
1192 1192              : comparator.compare((K)k1, (K)k2);
1193 1193      }
1194 1194  
1195 1195      /**
1196 1196       * Test two values for equality.  Differs from o1.equals(o2) only in
1197 1197       * that it copes with {@code null} o1 properly.
1198 1198       */
1199      -    final static boolean valEquals(Object o1, Object o2) {
     1199 +    static final boolean valEquals(Object o1, Object o2) {
1200 1200          return (o1==null ? o2==null : o1.equals(o2));
1201 1201      }
1202 1202  
1203 1203      /**
1204 1204       * Return SimpleImmutableEntry for entry, or null if null
1205 1205       */
1206 1206      static <K,V> Map.Entry<K,V> exportEntry(TreeMap.Entry<K,V> e) {
1207      -        return e == null? null :
     1207 +        return (e == null) ? null :
1208 1208              new AbstractMap.SimpleImmutableEntry<K,V>(e);
1209 1209      }
1210 1210  
1211 1211      /**
1212 1212       * Return key for entry, or null if null
1213 1213       */
1214 1214      static <K,V> K keyOrNull(TreeMap.Entry<K,V> e) {
1215      -        return e == null? null : e.key;
     1215 +        return (e == null) ? null : e.key;
1216 1216      }
1217 1217  
1218 1218      /**
1219 1219       * Returns the key corresponding to the specified Entry.
1220 1220       * @throws NoSuchElementException if the Entry is null
1221 1221       */
1222 1222      static <K> K key(Entry<K,?> e) {
1223 1223          if (e==null)
1224 1224              throw new NoSuchElementException();
1225 1225          return e.key;
↓ open down ↓ 4 lines elided ↑ open up ↑
1230 1230  
1231 1231      /**
1232 1232       * Dummy value serving as unmatchable fence key for unbounded
1233 1233       * SubMapIterators
1234 1234       */
1235 1235      private static final Object UNBOUNDED = new Object();
1236 1236  
1237 1237      /**
1238 1238       * @serial include
1239 1239       */
1240      -    static abstract class NavigableSubMap<K,V> extends AbstractMap<K,V>
     1240 +    abstract static class NavigableSubMap<K,V> extends AbstractMap<K,V>
1241 1241          implements NavigableMap<K,V>, java.io.Serializable {
1242 1242          /**
1243 1243           * The backing map.
1244 1244           */
1245 1245          final TreeMap<K,V> m;
1246 1246  
1247 1247          /**
1248 1248           * Endpoints are represented as triples (fromStart, lo,
1249 1249           * loInclusive) and (toEnd, hi, hiInclusive). If fromStart is
1250 1250           * true, then the low (absolute) bound is the start of the
↓ open down ↓ 154 lines elided ↑ open up ↑
1405 1405              return inRange(key) && m.containsKey(key);
1406 1406          }
1407 1407  
1408 1408          public final V put(K key, V value) {
1409 1409              if (!inRange(key))
1410 1410                  throw new IllegalArgumentException("key out of range");
1411 1411              return m.put(key, value);
1412 1412          }
1413 1413  
1414 1414          public final V get(Object key) {
1415      -            return !inRange(key)? null :  m.get(key);
     1415 +            return !inRange(key) ? null :  m.get(key);
1416 1416          }
1417 1417  
1418 1418          public final V remove(Object key) {
1419      -            return !inRange(key)? null  : m.remove(key);
     1419 +            return !inRange(key) ? null : m.remove(key);
1420 1420          }
1421 1421  
1422 1422          public final Map.Entry<K,V> ceilingEntry(K key) {
1423 1423              return exportEntry(subCeiling(key));
1424 1424          }
1425 1425  
1426 1426          public final K ceilingKey(K key) {
1427 1427              return keyOrNull(subCeiling(key));
1428 1428          }
1429 1429  
↓ open down ↓ 122 lines elided ↑ open up ↑
1552 1552              }
1553 1553  
1554 1554              public boolean remove(Object o) {
1555 1555                  if (!(o instanceof Map.Entry))
1556 1556                      return false;
1557 1557                  Map.Entry<K,V> entry = (Map.Entry<K,V>) o;
1558 1558                  K key = entry.getKey();
1559 1559                  if (!inRange(key))
1560 1560                      return false;
1561 1561                  TreeMap.Entry<K,V> node = m.getEntry(key);
1562      -                if (node!=null && valEquals(node.getValue(),entry.getValue())){
     1562 +                if (node!=null && valEquals(node.getValue(),
     1563 +                                            entry.getValue())) {
1563 1564                      m.deleteEntry(node);
1564 1565                      return true;
1565 1566                  }
1566 1567                  return false;
1567 1568              }
1568 1569          }
1569 1570  
1570 1571          /**
1571 1572           * Iterators for SubMaps
1572 1573           */
↓ open down ↓ 144 lines elided ↑ open up ↑
1717 1718          }
1718 1719  
1719 1720          public NavigableMap<K,V> headMap(K toKey, boolean inclusive) {
1720 1721              if (!inRange(toKey, inclusive))
1721 1722                  throw new IllegalArgumentException("toKey out of range");
1722 1723              return new AscendingSubMap(m,
1723 1724                                         fromStart, lo,    loInclusive,
1724 1725                                         false,     toKey, inclusive);
1725 1726          }
1726 1727  
1727      -        public NavigableMap<K,V> tailMap(K fromKey, boolean inclusive){
     1728 +        public NavigableMap<K,V> tailMap(K fromKey, boolean inclusive) {
1728 1729              if (!inRange(fromKey, inclusive))
1729 1730                  throw new IllegalArgumentException("fromKey out of range");
1730 1731              return new AscendingSubMap(m,
1731 1732                                         false, fromKey, inclusive,
1732 1733                                         toEnd, hi,      hiInclusive);
1733 1734          }
1734 1735  
1735 1736          public NavigableMap<K,V> descendingMap() {
1736 1737              NavigableMap<K,V> mv = descendingMapView;
1737 1738              return (mv != null) ? mv :
↓ open down ↓ 60 lines elided ↑ open up ↑
1798 1799          }
1799 1800  
1800 1801          public NavigableMap<K,V> headMap(K toKey, boolean inclusive) {
1801 1802              if (!inRange(toKey, inclusive))
1802 1803                  throw new IllegalArgumentException("toKey out of range");
1803 1804              return new DescendingSubMap(m,
1804 1805                                          false, toKey, inclusive,
1805 1806                                          toEnd, hi,    hiInclusive);
1806 1807          }
1807 1808  
1808      -        public NavigableMap<K,V> tailMap(K fromKey, boolean inclusive){
     1809 +        public NavigableMap<K,V> tailMap(K fromKey, boolean inclusive) {
1809 1810              if (!inRange(fromKey, inclusive))
1810 1811                  throw new IllegalArgumentException("fromKey out of range");
1811 1812              return new DescendingSubMap(m,
1812 1813                                          fromStart, lo, loInclusive,
1813 1814                                          false, fromKey, inclusive);
1814 1815          }
1815 1816  
1816 1817          public NavigableMap<K,V> descendingMap() {
1817 1818              NavigableMap<K,V> mv = descendingMapView;
1818 1819              return (mv != null) ? mv :
↓ open down ↓ 317 lines elided ↑ open up ↑
2136 2137      /**
2137 2138       * Delete node p, and then rebalance the tree.
2138 2139       */
2139 2140      private void deleteEntry(Entry<K,V> p) {
2140 2141          modCount++;
2141 2142          size--;
2142 2143  
2143 2144          // If strictly internal, copy successor's element to p and then make p
2144 2145          // point to successor.
2145 2146          if (p.left != null && p.right != null) {
2146      -            Entry<K,V> s = successor (p);
     2147 +            Entry<K,V> s = successor(p);
2147 2148              p.key = s.key;
2148 2149              p.value = s.value;
2149 2150              p = s;
2150 2151          } // p has 2 children
2151 2152  
2152 2153          // Start fixup at replacement node, if it exists.
2153 2154          Entry<K,V> replacement = (p.left != null ? p.left : p.right);
2154 2155  
2155 2156          if (replacement != null) {
2156 2157              // Link replacement to parent
↓ open down ↓ 288 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX