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 |
|
} |
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 |
|
} |
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 |
|
|
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 |
|
|
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 |
|
*/ |
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 |
|
*/ |
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"); |
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))); |
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++; |
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 |
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 |
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 |
|
} |
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 |
|
} |
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 |
|
} |
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 |
|
} |
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 |
|
} |
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 |
|
} |
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 |
|
} |
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 |
|
} |
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 |
|
} |
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 |
|
} |
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 |
|
} |
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 |
|
|
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(); } |