ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/TreeMap.java
(Generate patch)

Comparing jsr166/src/main/java/util/TreeMap.java (file contents):
Revision 1.36 by jsr166, Tue May 9 16:35:40 2006 UTC vs.
Revision 1.41 by jsr166, Sun Jan 7 07:38:27 2007 UTC

# Line 1 | Line 1
1   /*
2   * %W% %E%
3   *
4 < * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
4 > * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
5   * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6   */
7  
# Line 1117 | Line 1117 | public class TreeMap<K,V>
1117                  throw new IllegalStateException();
1118              if (modCount != expectedModCount)
1119                  throw new ConcurrentModificationException();
1120 +            // deleted entries are replaced by their successors
1121              if (lastReturned.left != null && lastReturned.right != null)
1122                  next = lastReturned;
1123              deleteEntry(lastReturned);
1124 <            expectedModCount++;
1124 >            expectedModCount = modCount;
1125              lastReturned = null;
1126          }
1127      }
# Line 1581 | Line 1582 | public class TreeMap<K,V>
1582                  return e;
1583              }
1584  
1585 <            public void remove() {
1585 >            final void removeAscending() {
1586                  if (lastReturned == null)
1587                      throw new IllegalStateException();
1588                  if (m.modCount != expectedModCount)
1589                      throw new ConcurrentModificationException();
1590 +                // deleted entries are replaced by their successors
1591                  if (lastReturned.left != null && lastReturned.right != null)
1592                      next = lastReturned;
1593                  m.deleteEntry(lastReturned);
1592                expectedModCount++;
1594                  lastReturned = null;
1595 +                expectedModCount = m.modCount;
1596 +            }
1597 +
1598 +            final void removeDescending() {
1599 +                if (lastReturned == null)
1600 +                    throw new IllegalStateException();
1601 +                if (m.modCount != expectedModCount)
1602 +                    throw new ConcurrentModificationException();
1603 +                m.deleteEntry(lastReturned);
1604 +                lastReturned = null;
1605 +                expectedModCount = m.modCount;
1606              }
1607 +
1608          }
1609  
1610          final class SubMapEntryIterator extends SubMapIterator<Map.Entry<K,V>> {
# Line 1602 | Line 1615 | public class TreeMap<K,V>
1615              public Map.Entry<K,V> next() {
1616                  return nextEntry();
1617              }
1618 +            public void remove() {
1619 +                removeAscending();
1620 +            }
1621          }
1622  
1623          final class SubMapKeyIterator extends SubMapIterator<K> {
# Line 1612 | Line 1628 | public class TreeMap<K,V>
1628              public K next() {
1629                  return nextEntry().key;
1630              }
1631 +            public void remove() {
1632 +                removeAscending();
1633 +            }
1634          }
1635  
1636          final class DescendingSubMapEntryIterator extends SubMapIterator<Map.Entry<K,V>> {
# Line 1623 | Line 1642 | public class TreeMap<K,V>
1642              public Map.Entry<K,V> next() {
1643                  return prevEntry();
1644              }
1645 +            public void remove() {
1646 +                removeDescending();
1647 +            }
1648          }
1649  
1650          final class DescendingSubMapKeyIterator extends SubMapIterator<K> {
# Line 1633 | Line 1655 | public class TreeMap<K,V>
1655              public K next() {
1656                  return prevEntry().key;
1657              }
1658 +            public void remove() {
1659 +                removeDescending();
1660 +            }
1661          }
1662      }
1663  
# Line 1664 | Line 1689 | public class TreeMap<K,V>
1689          }
1690  
1691          public NavigableMap<K,V> headMap(K toKey, boolean inclusive) {
1692 <            if (!inClosedRange(toKey))
1692 >            if (!inRange(toKey, inclusive))
1693                  throw new IllegalArgumentException("toKey out of range");
1694              return new AscendingSubMap(m,
1695                                         fromStart, lo,    loInclusive,
# Line 2328 | Line 2353 | public class TreeMap<K,V>
2353  
2354          if (hi < lo) return null;
2355  
2356 <        int mid = (lo + hi) / 2;
2356 >        int mid = (lo + hi) >>> 1;
2357  
2358          Entry<K,V> left  = null;
2359          if (lo < mid)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines