931 * and this map uses natural ordering, or its comparator
932 * does not permit null keys
933 * @throws IllegalArgumentException {@inheritDoc}
934 */
935 public SortedMap<K,V> headMap(K toKey) {
936 return headMap(toKey, false);
937 }
938
939 /**
940 * @throws ClassCastException {@inheritDoc}
941 * @throws NullPointerException if {@code fromKey} is null
942 * and this map uses natural ordering, or its comparator
943 * does not permit null keys
944 * @throws IllegalArgumentException {@inheritDoc}
945 */
946 public SortedMap<K,V> tailMap(K fromKey) {
947 return tailMap(fromKey, true);
948 }
949
950 @Override
951 public void forEach(BiConsumer<? super K, ? super V> action) {
952 Objects.requireNonNull(action);
953 int expectedModCount = modCount;
954 for (Entry<K, V> e = getFirstEntry(); e != null; e = successor(e)) {
955 action.accept(e.key, e.value);
956
957 if (expectedModCount != modCount) {
958 throw new ConcurrentModificationException();
959 }
960 }
961 }
962
963 @Override
964 public void replaceAll(BiFunction<? super K, ? super V, ? extends V> function) {
965 Objects.requireNonNull(function);
966 int expectedModCount = modCount;
967
968 for (Entry<K, V> e = getFirstEntry(); e != null; e = successor(e)) {
969 e.value = Objects.requireNonNull(function.apply(e.key, e.value));
970
971 if (expectedModCount != modCount) {
972 throw new ConcurrentModificationException();
973 }
974 }
975 }
976
977 // View class support
978
979 class Values extends AbstractCollection<V> {
980 public Iterator<V> iterator() {
981 return new ValueIterator(getFirstEntry());
982 }
983
984 public int size() {
985 return TreeMap.this.size();
986 }
987
988 public boolean contains(Object o) {
989 return TreeMap.this.containsValue(o);
|
931 * and this map uses natural ordering, or its comparator
932 * does not permit null keys
933 * @throws IllegalArgumentException {@inheritDoc}
934 */
935 public SortedMap<K,V> headMap(K toKey) {
936 return headMap(toKey, false);
937 }
938
939 /**
940 * @throws ClassCastException {@inheritDoc}
941 * @throws NullPointerException if {@code fromKey} is null
942 * and this map uses natural ordering, or its comparator
943 * does not permit null keys
944 * @throws IllegalArgumentException {@inheritDoc}
945 */
946 public SortedMap<K,V> tailMap(K fromKey) {
947 return tailMap(fromKey, true);
948 }
949
950 @Override
951 public synchronized boolean replace(K key, V oldValue, V newValue) {
952 Entry<K,V> p = getEntry(key);
953 if (p!=null && Objects.equals(oldValue, p.value)) {
954 p.value = newValue;
955 return true;
956 }
957 return false;
958 }
959
960 @Override
961 public synchronized V replace(K key, V value) {
962 Entry<K,V> p = getEntry(key);
963 if (p!=null) {
964 V oldValue = p.value;
965 p.value = value;
966 return oldValue;
967 }
968 return null;
969 }
970
971 @Override
972 public void forEach(BiConsumer<? super K, ? super V> action) {
973 Objects.requireNonNull(action);
974 int expectedModCount = modCount;
975 for (Entry<K, V> e = getFirstEntry(); e != null; e = successor(e)) {
976 action.accept(e.key, e.value);
977
978 if (expectedModCount != modCount) {
979 throw new ConcurrentModificationException();
980 }
981 }
982 }
983
984 @Override
985 public void replaceAll(BiFunction<? super K, ? super V, ? extends V> function) {
986 Objects.requireNonNull(function);
987 int expectedModCount = modCount;
988
989 for (Entry<K, V> e = getFirstEntry(); e != null; e = successor(e)) {
990 e.value = function.apply(e.key, e.value);
991
992 if (expectedModCount != modCount) {
993 throw new ConcurrentModificationException();
994 }
995 }
996 }
997
998 // View class support
999
1000 class Values extends AbstractCollection<V> {
1001 public Iterator<V> iterator() {
1002 return new ValueIterator(getFirstEntry());
1003 }
1004
1005 public int size() {
1006 return TreeMap.this.size();
1007 }
1008
1009 public boolean contains(Object o) {
1010 return TreeMap.this.containsValue(o);
|