1 |
|
/* |
2 |
< |
* Copyright 1997-2007 Sun Microsystems, Inc. All Rights Reserved. |
2 |
> |
* Copyright (c) 1997, 2008, Oracle and/or its affiliates. All rights reserved. |
3 |
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
|
* |
5 |
|
* This code is free software; you can redistribute it and/or modify it |
18 |
|
* 2 along with this work; if not, write to the Free Software Foundation, |
19 |
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
20 |
|
* |
21 |
< |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
22 |
< |
* CA 95054 USA or visit www.sun.com if you need additional information or |
23 |
< |
* have any questions. |
21 |
> |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
> |
* or visit www.oracle.com if you need additional information or have any |
23 |
> |
* questions. |
24 |
|
*/ |
25 |
|
|
26 |
|
package java.util; |
1021 |
|
} |
1022 |
|
|
1023 |
|
Iterator<K> descendingKeyIterator() { |
1024 |
< |
return new DescendingKeyIterator(getFirstEntry()); |
1024 |
> |
return new DescendingKeyIterator(getLastEntry()); |
1025 |
|
} |
1026 |
|
|
1027 |
|
static final class KeySet<E> extends AbstractSet<E> implements NavigableSet<E> { |
1055 |
|
public Comparator<? super E> comparator() { return m.comparator(); } |
1056 |
|
public E pollFirst() { |
1057 |
|
Map.Entry<E,Object> e = m.pollFirstEntry(); |
1058 |
< |
return e == null? null : e.getKey(); |
1058 |
> |
return (e == null) ? null : e.getKey(); |
1059 |
|
} |
1060 |
|
public E pollLast() { |
1061 |
|
Map.Entry<E,Object> e = m.pollLastEntry(); |
1062 |
< |
return e == null? null : e.getKey(); |
1062 |
> |
return (e == null) ? null : e.getKey(); |
1063 |
|
} |
1064 |
|
public boolean remove(Object o) { |
1065 |
|
int oldSize = size(); |
1068 |
|
} |
1069 |
|
public NavigableSet<E> subSet(E fromElement, boolean fromInclusive, |
1070 |
|
E toElement, boolean toInclusive) { |
1071 |
< |
return new TreeSet<E>(m.subMap(fromElement, fromInclusive, |
1072 |
< |
toElement, toInclusive)); |
1071 |
> |
return new KeySet<E>(m.subMap(fromElement, fromInclusive, |
1072 |
> |
toElement, toInclusive)); |
1073 |
|
} |
1074 |
|
public NavigableSet<E> headSet(E toElement, boolean inclusive) { |
1075 |
< |
return new TreeSet<E>(m.headMap(toElement, inclusive)); |
1075 |
> |
return new KeySet<E>(m.headMap(toElement, inclusive)); |
1076 |
|
} |
1077 |
|
public NavigableSet<E> tailSet(E fromElement, boolean inclusive) { |
1078 |
< |
return new TreeSet<E>(m.tailMap(fromElement, inclusive)); |
1078 |
> |
return new KeySet<E>(m.tailMap(fromElement, inclusive)); |
1079 |
|
} |
1080 |
|
public SortedSet<E> subSet(E fromElement, E toElement) { |
1081 |
|
return subSet(fromElement, true, toElement, false); |
1087 |
|
return tailSet(fromElement, true); |
1088 |
|
} |
1089 |
|
public NavigableSet<E> descendingSet() { |
1090 |
< |
return new TreeSet(m.descendingMap()); |
1090 |
> |
return new KeySet(m.descendingMap()); |
1091 |
|
} |
1092 |
|
} |
1093 |
|
|
1195 |
|
* Test two values for equality. Differs from o1.equals(o2) only in |
1196 |
|
* that it copes with <tt>null</tt> o1 properly. |
1197 |
|
*/ |
1198 |
< |
final static boolean valEquals(Object o1, Object o2) { |
1198 |
> |
static final boolean valEquals(Object o1, Object o2) { |
1199 |
|
return (o1==null ? o2==null : o1.equals(o2)); |
1200 |
|
} |
1201 |
|
|
1203 |
|
* Return SimpleImmutableEntry for entry, or null if null |
1204 |
|
*/ |
1205 |
|
static <K,V> Map.Entry<K,V> exportEntry(TreeMap.Entry<K,V> e) { |
1206 |
< |
return e == null? null : |
1206 |
> |
return (e == null) ? null : |
1207 |
|
new AbstractMap.SimpleImmutableEntry<K,V>(e); |
1208 |
|
} |
1209 |
|
|
1211 |
|
* Return key for entry, or null if null |
1212 |
|
*/ |
1213 |
|
static <K,V> K keyOrNull(TreeMap.Entry<K,V> e) { |
1214 |
< |
return e == null? null : e.key; |
1214 |
> |
return (e == null) ? null : e.key; |
1215 |
|
} |
1216 |
|
|
1217 |
|
/** |
1236 |
|
/** |
1237 |
|
* @serial include |
1238 |
|
*/ |
1239 |
< |
static abstract class NavigableSubMap<K,V> extends AbstractMap<K,V> |
1239 |
> |
abstract static class NavigableSubMap<K,V> extends AbstractMap<K,V> |
1240 |
|
implements NavigableMap<K,V>, java.io.Serializable { |
1241 |
|
/** |
1242 |
|
* The backing map. |
1411 |
|
} |
1412 |
|
|
1413 |
|
public final V get(Object key) { |
1414 |
< |
return !inRange(key)? null : m.get(key); |
1414 |
> |
return !inRange(key) ? null : m.get(key); |
1415 |
|
} |
1416 |
|
|
1417 |
|
public final V remove(Object key) { |
1418 |
< |
return !inRange(key)? null : m.remove(key); |
1418 |
> |
return !inRange(key) ? null : m.remove(key); |
1419 |
|
} |
1420 |
|
|
1421 |
|
public final Map.Entry<K,V> ceilingEntry(K key) { |
1558 |
|
if (!inRange(key)) |
1559 |
|
return false; |
1560 |
|
TreeMap.Entry<K,V> node = m.getEntry(key); |
1561 |
< |
if (node!=null && valEquals(node.getValue(),entry.getValue())){ |
1561 |
> |
if (node!=null && valEquals(node.getValue(), |
1562 |
> |
entry.getValue())) { |
1563 |
|
m.deleteEntry(node); |
1564 |
|
return true; |
1565 |
|
} |
1724 |
|
false, toKey, inclusive); |
1725 |
|
} |
1726 |
|
|
1727 |
< |
public NavigableMap<K,V> tailMap(K fromKey, boolean inclusive){ |
1727 |
> |
public NavigableMap<K,V> tailMap(K fromKey, boolean inclusive) { |
1728 |
|
if (!inRange(fromKey, inclusive)) |
1729 |
|
throw new IllegalArgumentException("fromKey out of range"); |
1730 |
|
return new AscendingSubMap(m, |
1805 |
|
toEnd, hi, hiInclusive); |
1806 |
|
} |
1807 |
|
|
1808 |
< |
public NavigableMap<K,V> tailMap(K fromKey, boolean inclusive){ |
1808 |
> |
public NavigableMap<K,V> tailMap(K fromKey, boolean inclusive) { |
1809 |
|
if (!inRange(fromKey, inclusive)) |
1810 |
|
throw new IllegalArgumentException("fromKey out of range"); |
1811 |
|
return new DescendingSubMap(m, |
2143 |
|
// If strictly internal, copy successor's element to p and then make p |
2144 |
|
// point to successor. |
2145 |
|
if (p.left != null && p.right != null) { |
2146 |
< |
Entry<K,V> s = successor (p); |
2146 |
> |
Entry<K,V> s = successor(p); |
2147 |
|
p.key = s.key; |
2148 |
|
p.value = s.value; |
2149 |
|
p = s; |