提交 3d6533a5 编写于 作者: L lagergren

8022412: Fixed warnings in java.util root, except for HashMap

Reviewed-by: mduigou, darcy
Contributed-by: marcus.lagergren@oracle.com
上级 e4559fae
...@@ -128,6 +128,7 @@ class ArrayPrefixHelpers { ...@@ -128,6 +128,7 @@ class ArrayPrefixHelpers {
this.lo = lo; this.hi = hi; this.lo = lo; this.hi = hi;
} }
@SuppressWarnings("unchecked")
public final void compute() { public final void compute() {
final BinaryOperator<T> fn; final BinaryOperator<T> fn;
final T[] a; final T[] a;
...@@ -692,6 +693,4 @@ class ArrayPrefixHelpers { ...@@ -692,6 +693,4 @@ class ArrayPrefixHelpers {
} }
} }
} }
}
}
\ No newline at end of file
...@@ -1143,6 +1143,7 @@ public class Collections { ...@@ -1143,6 +1143,7 @@ public class Collections {
public boolean removeIf(Predicate<? super E> filter) { public boolean removeIf(Predicate<? super E> filter) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
@SuppressWarnings("unchecked")
@Override @Override
public Spliterator<E> spliterator() { public Spliterator<E> spliterator() {
return (Spliterator<E>)c.spliterator(); return (Spliterator<E>)c.spliterator();
...@@ -1900,7 +1901,7 @@ public class Collections { ...@@ -1900,7 +1901,7 @@ public class Collections {
private static final long serialVersionUID = -2239321462712562324L; private static final long serialVersionUID = -2239321462712562324L;
EmptyNavigableMap() { super(new TreeMap()); } EmptyNavigableMap() { super(new TreeMap<K,V>()); }
@Override @Override
public NavigableSet<K> navigableKeySet() public NavigableSet<K> navigableKeySet()
...@@ -1928,46 +1929,52 @@ public class Collections { ...@@ -1928,46 +1929,52 @@ public class Collections {
public K ceilingKey(K key) { return nm.ceilingKey(key); } public K ceilingKey(K key) { return nm.ceilingKey(key); }
public K higherKey(K key) { return nm.higherKey(key); } public K higherKey(K key) { return nm.higherKey(key); }
@SuppressWarnings("unchecked")
public Entry<K, V> lowerEntry(K key) { public Entry<K, V> lowerEntry(K key) {
Entry<K,V> lower = (Entry<K, V>) nm.lowerEntry(key); Entry<K,V> lower = (Entry<K, V>) nm.lowerEntry(key);
return (null != lower) return (null != lower)
? new UnmodifiableEntrySet.UnmodifiableEntry(lower) ? new UnmodifiableEntrySet.UnmodifiableEntry<>(lower)
: null; : null;
} }
@SuppressWarnings("unchecked")
public Entry<K, V> floorEntry(K key) { public Entry<K, V> floorEntry(K key) {
Entry<K,V> floor = (Entry<K, V>) nm.floorEntry(key); Entry<K,V> floor = (Entry<K, V>) nm.floorEntry(key);
return (null != floor) return (null != floor)
? new UnmodifiableEntrySet.UnmodifiableEntry(floor) ? new UnmodifiableEntrySet.UnmodifiableEntry<>(floor)
: null; : null;
} }
@SuppressWarnings("unchecked")
public Entry<K, V> ceilingEntry(K key) { public Entry<K, V> ceilingEntry(K key) {
Entry<K,V> ceiling = (Entry<K, V>) nm.ceilingEntry(key); Entry<K,V> ceiling = (Entry<K, V>) nm.ceilingEntry(key);
return (null != ceiling) return (null != ceiling)
? new UnmodifiableEntrySet.UnmodifiableEntry(ceiling) ? new UnmodifiableEntrySet.UnmodifiableEntry<>(ceiling)
: null; : null;
} }
@SuppressWarnings("unchecked")
public Entry<K, V> higherEntry(K key) { public Entry<K, V> higherEntry(K key) {
Entry<K,V> higher = (Entry<K, V>) nm.higherEntry(key); Entry<K,V> higher = (Entry<K, V>) nm.higherEntry(key);
return (null != higher) return (null != higher)
? new UnmodifiableEntrySet.UnmodifiableEntry(higher) ? new UnmodifiableEntrySet.UnmodifiableEntry<>(higher)
: null; : null;
} }
@SuppressWarnings("unchecked")
public Entry<K, V> firstEntry() { public Entry<K, V> firstEntry() {
Entry<K,V> first = (Entry<K, V>) nm.firstEntry(); Entry<K,V> first = (Entry<K, V>) nm.firstEntry();
return (null != first) return (null != first)
? new UnmodifiableEntrySet.UnmodifiableEntry(first) ? new UnmodifiableEntrySet.UnmodifiableEntry<>(first)
: null; : null;
} }
@SuppressWarnings("unchecked")
public Entry<K, V> lastEntry() { public Entry<K, V> lastEntry() {
Entry<K,V> last = (Entry<K, V>) nm.lastEntry(); Entry<K,V> last = (Entry<K, V>) nm.lastEntry();
return (null != last) return (null != last)
? new UnmodifiableEntrySet.UnmodifiableEntry(last) ? new UnmodifiableEntrySet.UnmodifiableEntry<>(last)
: null; : null;
} }
...@@ -2360,7 +2367,7 @@ public class Collections { ...@@ -2360,7 +2367,7 @@ public class Collections {
} }
public NavigableSet<E> tailSet(E fromElement) { public NavigableSet<E> tailSet(E fromElement) {
synchronized (mutex) { synchronized (mutex) {
return new SynchronizedNavigableSet(ns.tailSet(fromElement, true), mutex); return new SynchronizedNavigableSet<>(ns.tailSet(fromElement, true), mutex);
} }
} }
...@@ -2925,7 +2932,7 @@ public class Collections { ...@@ -2925,7 +2932,7 @@ public class Collections {
public NavigableMap<K, V> descendingMap() { public NavigableMap<K, V> descendingMap() {
synchronized (mutex) { synchronized (mutex) {
return return
new SynchronizedNavigableMap(nm.descendingMap(), mutex); new SynchronizedNavigableMap<>(nm.descendingMap(), mutex);
} }
} }
...@@ -2935,13 +2942,13 @@ public class Collections { ...@@ -2935,13 +2942,13 @@ public class Collections {
public NavigableSet<K> navigableKeySet() { public NavigableSet<K> navigableKeySet() {
synchronized (mutex) { synchronized (mutex) {
return new SynchronizedNavigableSet(nm.navigableKeySet(), mutex); return new SynchronizedNavigableSet<>(nm.navigableKeySet(), mutex);
} }
} }
public NavigableSet<K> descendingKeySet() { public NavigableSet<K> descendingKeySet() {
synchronized (mutex) { synchronized (mutex) {
return new SynchronizedNavigableSet(nm.descendingKeySet(), mutex); return new SynchronizedNavigableSet<>(nm.descendingKeySet(), mutex);
} }
} }
...@@ -2959,27 +2966,27 @@ public class Collections { ...@@ -2959,27 +2966,27 @@ public class Collections {
} }
public SortedMap<K,V> tailMap(K fromKey) { public SortedMap<K,V> tailMap(K fromKey) {
synchronized (mutex) { synchronized (mutex) {
return new SynchronizedNavigableMap<>(nm.tailMap(fromKey, true),mutex); return new SynchronizedNavigableMap<>(nm.tailMap(fromKey, true),mutex);
} }
} }
public NavigableMap<K, V> subMap(K fromKey, boolean fromInclusive, K toKey, boolean toInclusive) { public NavigableMap<K, V> subMap(K fromKey, boolean fromInclusive, K toKey, boolean toInclusive) {
synchronized (mutex) { synchronized (mutex) {
return new SynchronizedNavigableMap( return new SynchronizedNavigableMap<>(
nm.subMap(fromKey, fromInclusive, toKey, toInclusive), mutex); nm.subMap(fromKey, fromInclusive, toKey, toInclusive), mutex);
} }
} }
public NavigableMap<K, V> headMap(K toKey, boolean inclusive) { public NavigableMap<K, V> headMap(K toKey, boolean inclusive) {
synchronized (mutex) { synchronized (mutex) {
return new SynchronizedNavigableMap( return new SynchronizedNavigableMap<>(
nm.headMap(toKey, inclusive), mutex); nm.headMap(toKey, inclusive), mutex);
} }
} }
public NavigableMap<K, V> tailMap(K fromKey, boolean inclusive) { public NavigableMap<K, V> tailMap(K fromKey, boolean inclusive) {
synchronized (mutex) { synchronized (mutex) {
return new SynchronizedNavigableMap( return new SynchronizedNavigableMap<>(
nm.tailMap(fromKey, inclusive), mutex); nm.tailMap(fromKey, inclusive), mutex);
} }
} }
...@@ -4081,7 +4088,7 @@ public class Collections { ...@@ -4081,7 +4088,7 @@ public class Collections {
public Entry<K, V> lowerEntry(K key) { public Entry<K, V> lowerEntry(K key) {
Entry<K,V> lower = nm.lowerEntry(key); Entry<K,V> lower = nm.lowerEntry(key);
return (null != lower) return (null != lower)
? new CheckedMap.CheckedEntrySet.CheckedEntry(lower, valueType) ? new CheckedMap.CheckedEntrySet.CheckedEntry<>(lower, valueType)
: null; : null;
} }
...@@ -4090,7 +4097,7 @@ public class Collections { ...@@ -4090,7 +4097,7 @@ public class Collections {
public Entry<K, V> floorEntry(K key) { public Entry<K, V> floorEntry(K key) {
Entry<K,V> floor = nm.floorEntry(key); Entry<K,V> floor = nm.floorEntry(key);
return (null != floor) return (null != floor)
? new CheckedMap.CheckedEntrySet.CheckedEntry(floor, valueType) ? new CheckedMap.CheckedEntrySet.CheckedEntry<>(floor, valueType)
: null; : null;
} }
...@@ -4099,7 +4106,7 @@ public class Collections { ...@@ -4099,7 +4106,7 @@ public class Collections {
public Entry<K, V> ceilingEntry(K key) { public Entry<K, V> ceilingEntry(K key) {
Entry<K,V> ceiling = nm.ceilingEntry(key); Entry<K,V> ceiling = nm.ceilingEntry(key);
return (null != ceiling) return (null != ceiling)
? new CheckedMap.CheckedEntrySet.CheckedEntry(ceiling, valueType) ? new CheckedMap.CheckedEntrySet.CheckedEntry<>(ceiling, valueType)
: null; : null;
} }
...@@ -4108,7 +4115,7 @@ public class Collections { ...@@ -4108,7 +4115,7 @@ public class Collections {
public Entry<K, V> higherEntry(K key) { public Entry<K, V> higherEntry(K key) {
Entry<K,V> higher = nm.higherEntry(key); Entry<K,V> higher = nm.higherEntry(key);
return (null != higher) return (null != higher)
? new CheckedMap.CheckedEntrySet.CheckedEntry(higher, valueType) ? new CheckedMap.CheckedEntrySet.CheckedEntry<>(higher, valueType)
: null; : null;
} }
...@@ -4117,14 +4124,14 @@ public class Collections { ...@@ -4117,14 +4124,14 @@ public class Collections {
public Entry<K, V> firstEntry() { public Entry<K, V> firstEntry() {
Entry<K,V> first = nm.firstEntry(); Entry<K,V> first = nm.firstEntry();
return (null != first) return (null != first)
? new CheckedMap.CheckedEntrySet.CheckedEntry(first, valueType) ? new CheckedMap.CheckedEntrySet.CheckedEntry<>(first, valueType)
: null; : null;
} }
public Entry<K, V> lastEntry() { public Entry<K, V> lastEntry() {
Entry<K,V> last = nm.lastEntry(); Entry<K,V> last = nm.lastEntry();
return (null != last) return (null != last)
? new CheckedMap.CheckedEntrySet.CheckedEntry(last, valueType) ? new CheckedMap.CheckedEntrySet.CheckedEntry<>(last, valueType)
: null; : null;
} }
...@@ -4132,14 +4139,14 @@ public class Collections { ...@@ -4132,14 +4139,14 @@ public class Collections {
Entry<K,V> entry = nm.pollFirstEntry(); Entry<K,V> entry = nm.pollFirstEntry();
return (null == entry) return (null == entry)
? null ? null
: new CheckedMap.CheckedEntrySet.CheckedEntry(entry, valueType); : new CheckedMap.CheckedEntrySet.CheckedEntry<>(entry, valueType);
} }
public Entry<K, V> pollLastEntry() { public Entry<K, V> pollLastEntry() {
Entry<K,V> entry = nm.pollLastEntry(); Entry<K,V> entry = nm.pollLastEntry();
return (null == entry) return (null == entry)
? null ? null
: new CheckedMap.CheckedEntrySet.CheckedEntry(entry, valueType); : new CheckedMap.CheckedEntrySet.CheckedEntry<>(entry, valueType);
} }
public NavigableMap<K, V> descendingMap() { public NavigableMap<K, V> descendingMap() {
......
...@@ -352,6 +352,7 @@ public interface Comparator<T> { ...@@ -352,6 +352,7 @@ public interface Comparator<T> {
* @see Comparable * @see Comparable
* @since 1.8 * @since 1.8
*/ */
@SuppressWarnings("unchecked")
public static <T extends Comparable<? super T>> Comparator<T> naturalOrder() { public static <T extends Comparable<? super T>> Comparator<T> naturalOrder() {
return (Comparator<T>) Comparators.NaturalOrderComparator.INSTANCE; return (Comparator<T>) Comparators.NaturalOrderComparator.INSTANCE;
} }
...@@ -374,7 +375,7 @@ public interface Comparator<T> { ...@@ -374,7 +375,7 @@ public interface Comparator<T> {
* @since 1.8 * @since 1.8
*/ */
public static <T> Comparator<T> nullsFirst(Comparator<? super T> comparator) { public static <T> Comparator<T> nullsFirst(Comparator<? super T> comparator) {
return new Comparators.NullComparator(true, comparator); return new Comparators.NullComparator<>(true, comparator);
} }
/** /**
...@@ -395,7 +396,7 @@ public interface Comparator<T> { ...@@ -395,7 +396,7 @@ public interface Comparator<T> {
* @since 1.8 * @since 1.8
*/ */
public static <T> Comparator<T> nullsLast(Comparator<? super T> comparator) { public static <T> Comparator<T> nullsLast(Comparator<? super T> comparator) {
return new Comparators.NullComparator(false, comparator); return new Comparators.NullComparator<>(false, comparator);
} }
/** /**
......
...@@ -87,12 +87,12 @@ class Comparators { ...@@ -87,12 +87,12 @@ class Comparators {
@Override @Override
public Comparator<T> thenComparing(Comparator<? super T> other) { public Comparator<T> thenComparing(Comparator<? super T> other) {
Objects.requireNonNull(other); Objects.requireNonNull(other);
return new NullComparator(nullFirst, real == null ? other : real.thenComparing(other)); return new NullComparator<>(nullFirst, real == null ? other : real.thenComparing(other));
} }
@Override @Override
public Comparator<T> reversed() { public Comparator<T> reversed() {
return new NullComparator(!nullFirst, real == null ? null : real.reversed()); return new NullComparator<>(!nullFirst, real == null ? null : real.reversed());
} }
} }
} }
...@@ -928,6 +928,7 @@ public class Hashtable<K,V> ...@@ -928,6 +928,7 @@ public class Hashtable<K,V>
return (null == result) ? defaultValue : result; return (null == result) ? defaultValue : result;
} }
@SuppressWarnings("unchecked")
@Override @Override
public synchronized void forEach(BiConsumer<? super K, ? super V> action) { public synchronized void forEach(BiConsumer<? super K, ? super V> action) {
Objects.requireNonNull(action); // explicit check required in case Objects.requireNonNull(action); // explicit check required in case
...@@ -947,6 +948,7 @@ public class Hashtable<K,V> ...@@ -947,6 +948,7 @@ public class Hashtable<K,V>
} }
} }
@SuppressWarnings("unchecked")
@Override @Override
public synchronized void replaceAll(BiFunction<? super K, ? super V, ? extends V> function) { public synchronized void replaceAll(BiFunction<? super K, ? super V, ? extends V> function) {
Objects.requireNonNull(function); // explicit check required in case Objects.requireNonNull(function); // explicit check required in case
......
...@@ -1339,6 +1339,7 @@ public class IdentityHashMap<K,V> ...@@ -1339,6 +1339,7 @@ public class IdentityHashMap<K,V>
tab[i + 1] = value; tab[i + 1] = value;
} }
@SuppressWarnings("unchecked")
@Override @Override
public void forEach(BiConsumer<? super K, ? super V> action) { public void forEach(BiConsumer<? super K, ? super V> action) {
Objects.requireNonNull(action); Objects.requireNonNull(action);
...@@ -1357,6 +1358,7 @@ public class IdentityHashMap<K,V> ...@@ -1357,6 +1358,7 @@ public class IdentityHashMap<K,V>
} }
} }
@SuppressWarnings("unchecked")
@Override @Override
public void replaceAll(BiFunction<? super K, ? super V, ? extends V> function) { public void replaceAll(BiFunction<? super K, ? super V, ? extends V> function) {
Objects.requireNonNull(function); Objects.requireNonNull(function);
......
...@@ -1164,12 +1164,13 @@ public class Vector<E> ...@@ -1164,12 +1164,13 @@ public class Vector<E>
if (i >= size) { if (i >= size) {
return; return;
} }
final Object[] elementData = Vector.this.elementData; @SuppressWarnings("unchecked")
final E[] elementData = (E[]) Vector.this.elementData;
if (i >= elementData.length) { if (i >= elementData.length) {
throw new ConcurrentModificationException(); throw new ConcurrentModificationException();
} }
while (i != size && modCount == expectedModCount) { while (i != size && modCount == expectedModCount) {
action.accept((E) elementData[i++]); action.accept(elementData[i++]);
} }
// update once at end of iteration to reduce heap write traffic // update once at end of iteration to reduce heap write traffic
cursor = i; cursor = i;
...@@ -1311,8 +1312,8 @@ public class Vector<E> ...@@ -1311,8 +1312,8 @@ public class Vector<E>
modCount++; modCount++;
} }
@Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override
public synchronized void sort(Comparator<? super E> c) { public synchronized void sort(Comparator<? super E> c) {
final int expectedModCount = modCount; final int expectedModCount = modCount;
Arrays.sort((E[]) elementData, 0, elementCount, c); Arrays.sort((E[]) elementData, 0, elementCount, c);
......
...@@ -1038,6 +1038,7 @@ public class WeakHashMap<K,V> ...@@ -1038,6 +1038,7 @@ public class WeakHashMap<K,V>
} }
} }
@SuppressWarnings("unchecked")
@Override @Override
public void forEach(BiConsumer<? super K, ? super V> action) { public void forEach(BiConsumer<? super K, ? super V> action) {
Objects.requireNonNull(action); Objects.requireNonNull(action);
...@@ -1059,6 +1060,7 @@ public class WeakHashMap<K,V> ...@@ -1059,6 +1060,7 @@ public class WeakHashMap<K,V>
} }
} }
@SuppressWarnings("unchecked")
@Override @Override
public void replaceAll(BiFunction<? super K, ? super V, ? extends V> function) { public void replaceAll(BiFunction<? super K, ? super V, ? extends V> function) {
Objects.requireNonNull(function); Objects.requireNonNull(function);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册