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.29 by dl, Thu Apr 20 20:34:37 2006 UTC vs.
Revision 1.30 by jsr166, Thu Apr 20 21:49:36 2006 UTC

# Line 877 | Line 877 | public class TreeMap<K,V>
877      public NavigableMap<K, V> descendingMap() {
878          NavigableMap<K, V> km = descendingMap;
879          return (km != null) ? km :
880 <            (descendingMap = new DescendingSubMap(this,
880 >            (descendingMap = new DescendingSubMap(this,
881                                                    true, null, 0,
882                                                    true, null, 0));
883      }
# Line 892 | Line 892 | public class TreeMap<K,V>
892       */
893      public NavigableMap<K,V> subMap(K fromKey, boolean fromInclusive,
894                                      K toKey,   boolean toInclusive) {
895 <        return new AscendingSubMap(this,
895 >        return new AscendingSubMap(this,
896                                     false, fromKey, excluded(fromInclusive),
897                                     false, toKey,   excluded(toInclusive));
898      }
# Line 906 | Line 906 | public class TreeMap<K,V>
906       * @since 1.6
907       */
908      public NavigableMap<K,V> headMap(K toKey, boolean inclusive) {
909 <        return new AscendingSubMap(this,
910 <                                   true, null, 0,
909 >        return new AscendingSubMap(this,
910 >                                   true, null, 0,
911                                     false, toKey, excluded(inclusive));
912      }
913  
# Line 920 | Line 920 | public class TreeMap<K,V>
920       * @since 1.6
921       */
922      public NavigableMap<K,V> tailMap(K fromKey, boolean inclusive) {
923 <        return new AscendingSubMap(this,
924 <                                   false, fromKey, excluded(inclusive),
923 >        return new AscendingSubMap(this,
924 >                                   false, fromKey, excluded(inclusive),
925                                     true, null, 0);
926      }
927  
# Line 1214 | Line 1214 | public class TreeMap<K,V>
1214          /*
1215           * The backing map.
1216           */
1217 <        final TreeMap<K,V> m;
1217 >        final TreeMap<K,V> m;
1218  
1219          /** True if low point is from start of backing map */
1220          boolean fromStart;
1221  
1222 <        /**
1222 >        /**
1223           * The low endpoint of this submap in absolute terms, or null
1224           * if fromStart.
1225           */
# Line 1234 | Line 1234 | public class TreeMap<K,V>
1234          /** True if high point is to End of backing map */
1235          boolean toEnd;
1236  
1237 <        /**
1237 >        /**
1238           * The high endpoint of this submap in absolute terms, or null
1239           * if toEnd.
1240           */
# Line 1246 | Line 1246 | public class TreeMap<K,V>
1246           */
1247          int hiExcluded;
1248  
1249 <        NavigableSubMap(TreeMap<K,V> m,
1250 <                        boolean fromStart, K lo, int loExcluded,
1249 >        NavigableSubMap(TreeMap<K,V> m,
1250 >                        boolean fromStart, K lo, int loExcluded,
1251                          boolean toEnd, K hi, int hiExcluded) {
1252              if (!fromStart && !toEnd && m.compare(lo, hi) > 0)
1253                  throw new IllegalArgumentException("fromKey > toKey");
# Line 1287 | Line 1287 | public class TreeMap<K,V>
1287  
1288          /** Returns the lowest entry in this submap (absolute ordering) */
1289          final TreeMap.Entry<K,V> loEntry() {
1290 <            TreeMap.Entry<K,V> result =
1290 >            TreeMap.Entry<K,V> result =
1291                  (fromStart ?  m.getFirstEntry() :
1292                   (loExcluded == 0 ? m.getCeilingEntry(lo) :
1293                                      m.getHigherEntry(lo)));
# Line 1434 | Line 1434 | public class TreeMap<K,V>
1434                      return m.size();
1435                  if (size == -1 || sizeModCount != m.modCount) {
1436                      sizeModCount = m.modCount;
1437 <                    size = 0;  
1437 >                    size = 0;
1438                      Iterator i = iterator();
1439                      while (i.hasNext()) {
1440                          size++;
# Line 1499 | Line 1499 | public class TreeMap<K,V>
1499              return tailMap(fromKey, true);
1500          }
1501  
1502 <
1502 >
1503          // The following four definitions are correct only for
1504          // ascending submaps. They are overridden in DescendingSubMap.
1505          // They are defined in the base class because the definitions
# Line 1562 | Line 1562 | public class TreeMap<K,V>
1562              TreeMap.Entry<K,V> next;
1563              final K firstExcludedKey;
1564  
1565 <            SubMapIterator(TreeMap.Entry<K,V> first,
1565 >            SubMapIterator(TreeMap.Entry<K,V> first,
1566                             TreeMap.Entry<K,V> firstExcluded) {
1567                  next = first;
1568                  firstExcludedKey = (firstExcluded == null ? null
# Line 1607 | Line 1607 | public class TreeMap<K,V>
1607          }
1608  
1609          final class SubMapEntryIterator extends SubMapIterator<Map.Entry<K,V>> {
1610 <            SubMapEntryIterator(TreeMap.Entry<K,V> first,
1610 >            SubMapEntryIterator(TreeMap.Entry<K,V> first,
1611                                  TreeMap.Entry<K,V> firstExcluded) {
1612                  super(first, firstExcluded);
1613              }
# Line 1617 | Line 1617 | public class TreeMap<K,V>
1617          }
1618  
1619          final class SubMapKeyIterator extends SubMapIterator<K> {
1620 <            SubMapKeyIterator(TreeMap.Entry<K,V> first,
1620 >            SubMapKeyIterator(TreeMap.Entry<K,V> first,
1621                                TreeMap.Entry<K,V> firstExcluded) {
1622                  super(first, firstExcluded);
1623              }
# Line 1627 | Line 1627 | public class TreeMap<K,V>
1627          }
1628  
1629          final class DescendingSubMapEntryIterator extends SubMapIterator<Map.Entry<K,V>> {
1630 <            DescendingSubMapEntryIterator(TreeMap.Entry<K,V> last,
1630 >            DescendingSubMapEntryIterator(TreeMap.Entry<K,V> last,
1631                                            TreeMap.Entry<K,V> lastExcluded) {
1632                  super(last, lastExcluded);
1633              }
# Line 1638 | Line 1638 | public class TreeMap<K,V>
1638          }
1639  
1640          final class DescendingSubMapKeyIterator extends SubMapIterator<K> {
1641 <            DescendingSubMapKeyIterator(TreeMap.Entry<K,V> last,
1641 >            DescendingSubMapKeyIterator(TreeMap.Entry<K,V> last,
1642                                          TreeMap.Entry<K,V> lastExcluded) {
1643                  super(last, lastExcluded);
1644              }
# Line 1651 | Line 1651 | public class TreeMap<K,V>
1651      static class AscendingSubMap<K,V> extends NavigableSubMap<K,V> {
1652          private static final long serialVersionUID = 912986545866124060L;
1653  
1654 <        AscendingSubMap(TreeMap<K,V> m,
1655 <                        boolean fromStart, K lo, int loExcluded,
1654 >        AscendingSubMap(TreeMap<K,V> m,
1655 >                        boolean fromStart, K lo, int loExcluded,
1656                          boolean toEnd, K hi, int hiExcluded) {
1657              super(m, fromStart, lo, loExcluded, toEnd, hi, hiExcluded);
1658          }
# Line 1661 | Line 1661 | public class TreeMap<K,V>
1661              return m.comparator();
1662          }
1663  
1664 <        public NavigableMap<K,V> subMap(K fromKey, boolean fromInclusive,
1664 >        public NavigableMap<K,V> subMap(K fromKey, boolean fromInclusive,
1665                                          K toKey, boolean toInclusive) {
1666              if (!inRange(fromKey, fromInclusive))
1667                  throw new IllegalArgumentException("fromKey out of range");
1668              if (!inRange(toKey, toInclusive))
1669                  throw new IllegalArgumentException("toKey out of range");
1670 <            return new AscendingSubMap(m,
1670 >            return new AscendingSubMap(m,
1671                                         false, fromKey, excluded(fromInclusive),
1672                                         false, toKey,   excluded(toInclusive));
1673          }
# Line 1675 | Line 1675 | public class TreeMap<K,V>
1675          public NavigableMap<K,V> headMap(K toKey, boolean inclusive) {
1676              if (!inClosedRange(toKey))
1677                  throw new IllegalArgumentException("toKey out of range");
1678 <            return new AscendingSubMap(m,
1678 >            return new AscendingSubMap(m,
1679                                         fromStart, lo,    loExcluded,
1680                                         false, toKey, excluded(inclusive));
1681          }
# Line 1683 | Line 1683 | public class TreeMap<K,V>
1683          public NavigableMap<K,V> tailMap(K fromKey, boolean inclusive){
1684              if (!inRange(fromKey, inclusive))
1685                  throw new IllegalArgumentException("fromKey out of range");
1686 <            return new AscendingSubMap(m,
1686 >            return new AscendingSubMap(m,
1687                                         false, fromKey, excluded(inclusive),
1688                                         toEnd, hi,      hiExcluded);
1689          }
# Line 1735 | Line 1735 | public class TreeMap<K,V>
1735              NavigableMap<K,V> mv = descendingMapView;
1736              return (mv != null) ? mv :
1737                  (descendingMapView =
1738 <                 new DescendingSubMap(m,
1739 <                                      fromStart, lo, loExcluded,
1738 >                 new DescendingSubMap(m,
1739 >                                      fromStart, lo, loExcluded,
1740                                        toEnd, hi, hiExcluded));
1741          }
1742      }
1743  
1744      static class DescendingSubMap<K,V> extends NavigableSubMap<K,V> {
1745          private static final long serialVersionUID = 912986545866120460L;
1746 <        DescendingSubMap(TreeMap<K,V> m,
1747 <                        boolean fromStart, K lo, int loExcluded,
1746 >        DescendingSubMap(TreeMap<K,V> m,
1747 >                        boolean fromStart, K lo, int loExcluded,
1748                          boolean toEnd, K hi, int hiExcluded) {
1749              super(m, fromStart, lo, loExcluded, toEnd, hi, hiExcluded);
1750          }
# Line 1756 | Line 1756 | public class TreeMap<K,V>
1756              return reverseComparator;
1757          }
1758  
1759 <        public NavigableMap<K,V> subMap(K fromKey, boolean fromInclusive,
1759 >        public NavigableMap<K,V> subMap(K fromKey, boolean fromInclusive,
1760                                          K toKey, boolean toInclusive) {
1761              if (!inRange(fromKey, fromInclusive))
1762                  throw new IllegalArgumentException("fromKey out of range");
1763              if (!inRange(toKey, toInclusive))
1764                  throw new IllegalArgumentException("toKey out of range");
1765 <            return new DescendingSubMap(m,
1765 >            return new DescendingSubMap(m,
1766                                          false, toKey,   excluded(toInclusive),
1767                                          false, fromKey, excluded(fromInclusive));
1768          }
# Line 1770 | Line 1770 | public class TreeMap<K,V>
1770          public NavigableMap<K,V> headMap(K toKey, boolean inclusive) {
1771              if (!inRange(toKey, inclusive))
1772                  throw new IllegalArgumentException("toKey out of range");
1773 <            return new DescendingSubMap(m,
1774 <                                        false, toKey, excluded(inclusive),
1773 >            return new DescendingSubMap(m,
1774 >                                        false, toKey, excluded(inclusive),
1775                                          toEnd, hi, hiExcluded);
1776          }
1777  
1778          public NavigableMap<K,V> tailMap(K fromKey, boolean inclusive){
1779              if (!inRange(fromKey, inclusive))
1780                  throw new IllegalArgumentException("fromKey out of range");
1781 <            return new DescendingSubMap(m,
1781 >            return new DescendingSubMap(m,
1782                                          fromStart, lo,      loExcluded,
1783                                          false, fromKey, excluded(inclusive));
1784          }
# Line 1830 | Line 1830 | public class TreeMap<K,V>
1830              NavigableMap<K,V> mv = descendingMapView;
1831              return (mv != null) ? mv :
1832                  (descendingMapView =
1833 <                 new AscendingSubMap(m,
1834 <                                     fromStart, lo, loExcluded,
1833 >                 new AscendingSubMap(m,
1834 >                                     fromStart, lo, loExcluded,
1835                                       toEnd, hi, hiExcluded));
1836          }
1837  
# Line 1881 | Line 1881 | public class TreeMap<K,V>
1881          private boolean fromStart = false, toEnd = false;
1882          private K fromKey, toKey;
1883          private Object readResolve() {
1884 <            return new AscendingSubMap(TreeMap.this,
1885 <                                       fromStart, fromKey, 0,
1884 >            return new AscendingSubMap(TreeMap.this,
1885 >                                       fromStart, fromKey, 0,
1886                                         toEnd, toKey, 1);
1887          }
1888          public Set<Map.Entry<K,V>> entrySet() { throw new InternalError(); }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines