mirror of
https://github.com/openjdk/jdk.git
synced 2026-04-10 06:59:05 +00:00
8022412: Fixed warnings in java.util root, except for HashMap
Reviewed-by: mduigou, darcy
This commit is contained in:
parent
ae54a3c965
commit
cd162a777d
@ -128,6 +128,7 @@ class ArrayPrefixHelpers {
|
||||
this.lo = lo; this.hi = hi;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public final void compute() {
|
||||
final BinaryOperator<T> fn;
|
||||
final T[] a;
|
||||
@ -692,6 +693,4 @@ class ArrayPrefixHelpers {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -1143,6 +1143,7 @@ public class Collections {
|
||||
public boolean removeIf(Predicate<? super E> filter) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Spliterator<E> spliterator() {
|
||||
return (Spliterator<E>)c.spliterator();
|
||||
@ -1900,7 +1901,7 @@ public class Collections {
|
||||
|
||||
private static final long serialVersionUID = -2239321462712562324L;
|
||||
|
||||
EmptyNavigableMap() { super(new TreeMap()); }
|
||||
EmptyNavigableMap() { super(new TreeMap<K,V>()); }
|
||||
|
||||
@Override
|
||||
public NavigableSet<K> navigableKeySet()
|
||||
@ -1928,46 +1929,52 @@ public class Collections {
|
||||
public K ceilingKey(K key) { return nm.ceilingKey(key); }
|
||||
public K higherKey(K key) { return nm.higherKey(key); }
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Entry<K, V> lowerEntry(K key) {
|
||||
Entry<K,V> lower = (Entry<K, V>) nm.lowerEntry(key);
|
||||
return (null != lower)
|
||||
? new UnmodifiableEntrySet.UnmodifiableEntry(lower)
|
||||
? new UnmodifiableEntrySet.UnmodifiableEntry<>(lower)
|
||||
: null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Entry<K, V> floorEntry(K key) {
|
||||
Entry<K,V> floor = (Entry<K, V>) nm.floorEntry(key);
|
||||
return (null != floor)
|
||||
? new UnmodifiableEntrySet.UnmodifiableEntry(floor)
|
||||
? new UnmodifiableEntrySet.UnmodifiableEntry<>(floor)
|
||||
: null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Entry<K, V> ceilingEntry(K key) {
|
||||
Entry<K,V> ceiling = (Entry<K, V>) nm.ceilingEntry(key);
|
||||
return (null != ceiling)
|
||||
? new UnmodifiableEntrySet.UnmodifiableEntry(ceiling)
|
||||
? new UnmodifiableEntrySet.UnmodifiableEntry<>(ceiling)
|
||||
: null;
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Entry<K, V> higherEntry(K key) {
|
||||
Entry<K,V> higher = (Entry<K, V>) nm.higherEntry(key);
|
||||
return (null != higher)
|
||||
? new UnmodifiableEntrySet.UnmodifiableEntry(higher)
|
||||
? new UnmodifiableEntrySet.UnmodifiableEntry<>(higher)
|
||||
: null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Entry<K, V> firstEntry() {
|
||||
Entry<K,V> first = (Entry<K, V>) nm.firstEntry();
|
||||
return (null != first)
|
||||
? new UnmodifiableEntrySet.UnmodifiableEntry(first)
|
||||
? new UnmodifiableEntrySet.UnmodifiableEntry<>(first)
|
||||
: null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Entry<K, V> lastEntry() {
|
||||
Entry<K,V> last = (Entry<K, V>) nm.lastEntry();
|
||||
return (null != last)
|
||||
? new UnmodifiableEntrySet.UnmodifiableEntry(last)
|
||||
? new UnmodifiableEntrySet.UnmodifiableEntry<>(last)
|
||||
: null;
|
||||
}
|
||||
|
||||
@ -2360,7 +2367,7 @@ public class Collections {
|
||||
}
|
||||
public NavigableSet<E> tailSet(E fromElement) {
|
||||
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 {
|
||||
public NavigableMap<K, V> descendingMap() {
|
||||
synchronized (mutex) {
|
||||
return
|
||||
new SynchronizedNavigableMap(nm.descendingMap(), mutex);
|
||||
new SynchronizedNavigableMap<>(nm.descendingMap(), mutex);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2935,13 +2942,13 @@ public class Collections {
|
||||
|
||||
public NavigableSet<K> navigableKeySet() {
|
||||
synchronized (mutex) {
|
||||
return new SynchronizedNavigableSet(nm.navigableKeySet(), mutex);
|
||||
return new SynchronizedNavigableSet<>(nm.navigableKeySet(), mutex);
|
||||
}
|
||||
}
|
||||
|
||||
public NavigableSet<K> descendingKeySet() {
|
||||
synchronized (mutex) {
|
||||
return new SynchronizedNavigableSet(nm.descendingKeySet(), mutex);
|
||||
return new SynchronizedNavigableSet<>(nm.descendingKeySet(), mutex);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2959,27 +2966,27 @@ public class Collections {
|
||||
}
|
||||
public SortedMap<K,V> tailMap(K fromKey) {
|
||||
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) {
|
||||
synchronized (mutex) {
|
||||
return new SynchronizedNavigableMap(
|
||||
return new SynchronizedNavigableMap<>(
|
||||
nm.subMap(fromKey, fromInclusive, toKey, toInclusive), mutex);
|
||||
}
|
||||
}
|
||||
|
||||
public NavigableMap<K, V> headMap(K toKey, boolean inclusive) {
|
||||
synchronized (mutex) {
|
||||
return new SynchronizedNavigableMap(
|
||||
return new SynchronizedNavigableMap<>(
|
||||
nm.headMap(toKey, inclusive), mutex);
|
||||
}
|
||||
}
|
||||
|
||||
public NavigableMap<K, V> tailMap(K fromKey, boolean inclusive) {
|
||||
synchronized (mutex) {
|
||||
return new SynchronizedNavigableMap(
|
||||
return new SynchronizedNavigableMap<>(
|
||||
nm.tailMap(fromKey, inclusive), mutex);
|
||||
}
|
||||
}
|
||||
@ -4081,7 +4088,7 @@ public class Collections {
|
||||
public Entry<K, V> lowerEntry(K key) {
|
||||
Entry<K,V> lower = nm.lowerEntry(key);
|
||||
return (null != lower)
|
||||
? new CheckedMap.CheckedEntrySet.CheckedEntry(lower, valueType)
|
||||
? new CheckedMap.CheckedEntrySet.CheckedEntry<>(lower, valueType)
|
||||
: null;
|
||||
}
|
||||
|
||||
@ -4090,7 +4097,7 @@ public class Collections {
|
||||
public Entry<K, V> floorEntry(K key) {
|
||||
Entry<K,V> floor = nm.floorEntry(key);
|
||||
return (null != floor)
|
||||
? new CheckedMap.CheckedEntrySet.CheckedEntry(floor, valueType)
|
||||
? new CheckedMap.CheckedEntrySet.CheckedEntry<>(floor, valueType)
|
||||
: null;
|
||||
}
|
||||
|
||||
@ -4099,7 +4106,7 @@ public class Collections {
|
||||
public Entry<K, V> ceilingEntry(K key) {
|
||||
Entry<K,V> ceiling = nm.ceilingEntry(key);
|
||||
return (null != ceiling)
|
||||
? new CheckedMap.CheckedEntrySet.CheckedEntry(ceiling, valueType)
|
||||
? new CheckedMap.CheckedEntrySet.CheckedEntry<>(ceiling, valueType)
|
||||
: null;
|
||||
}
|
||||
|
||||
@ -4108,7 +4115,7 @@ public class Collections {
|
||||
public Entry<K, V> higherEntry(K key) {
|
||||
Entry<K,V> higher = nm.higherEntry(key);
|
||||
return (null != higher)
|
||||
? new CheckedMap.CheckedEntrySet.CheckedEntry(higher, valueType)
|
||||
? new CheckedMap.CheckedEntrySet.CheckedEntry<>(higher, valueType)
|
||||
: null;
|
||||
}
|
||||
|
||||
@ -4117,14 +4124,14 @@ public class Collections {
|
||||
public Entry<K, V> firstEntry() {
|
||||
Entry<K,V> first = nm.firstEntry();
|
||||
return (null != first)
|
||||
? new CheckedMap.CheckedEntrySet.CheckedEntry(first, valueType)
|
||||
? new CheckedMap.CheckedEntrySet.CheckedEntry<>(first, valueType)
|
||||
: null;
|
||||
}
|
||||
|
||||
public Entry<K, V> lastEntry() {
|
||||
Entry<K,V> last = nm.lastEntry();
|
||||
return (null != last)
|
||||
? new CheckedMap.CheckedEntrySet.CheckedEntry(last, valueType)
|
||||
? new CheckedMap.CheckedEntrySet.CheckedEntry<>(last, valueType)
|
||||
: null;
|
||||
}
|
||||
|
||||
@ -4132,14 +4139,14 @@ public class Collections {
|
||||
Entry<K,V> entry = nm.pollFirstEntry();
|
||||
return (null == entry)
|
||||
? null
|
||||
: new CheckedMap.CheckedEntrySet.CheckedEntry(entry, valueType);
|
||||
: new CheckedMap.CheckedEntrySet.CheckedEntry<>(entry, valueType);
|
||||
}
|
||||
|
||||
public Entry<K, V> pollLastEntry() {
|
||||
Entry<K,V> entry = nm.pollLastEntry();
|
||||
return (null == entry)
|
||||
? null
|
||||
: new CheckedMap.CheckedEntrySet.CheckedEntry(entry, valueType);
|
||||
: new CheckedMap.CheckedEntrySet.CheckedEntry<>(entry, valueType);
|
||||
}
|
||||
|
||||
public NavigableMap<K, V> descendingMap() {
|
||||
|
||||
@ -352,6 +352,7 @@ public interface Comparator<T> {
|
||||
* @see Comparable
|
||||
* @since 1.8
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T extends Comparable<? super T>> Comparator<T> naturalOrder() {
|
||||
return (Comparator<T>) Comparators.NaturalOrderComparator.INSTANCE;
|
||||
}
|
||||
@ -374,7 +375,7 @@ public interface Comparator<T> {
|
||||
* @since 1.8
|
||||
*/
|
||||
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> {
|
||||
* @since 1.8
|
||||
*/
|
||||
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 {
|
||||
@Override
|
||||
public Comparator<T> thenComparing(Comparator<? super T> 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
|
||||
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>
|
||||
return (null == result) ? defaultValue : result;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public synchronized void forEach(BiConsumer<? super K, ? super V> action) {
|
||||
Objects.requireNonNull(action); // explicit check required in case
|
||||
@ -947,6 +948,7 @@ public class Hashtable<K,V>
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public synchronized void replaceAll(BiFunction<? super K, ? super V, ? extends V> function) {
|
||||
Objects.requireNonNull(function); // explicit check required in case
|
||||
|
||||
@ -1339,6 +1339,7 @@ public class IdentityHashMap<K,V>
|
||||
tab[i + 1] = value;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void forEach(BiConsumer<? super K, ? super V> action) {
|
||||
Objects.requireNonNull(action);
|
||||
@ -1357,6 +1358,7 @@ public class IdentityHashMap<K,V>
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void replaceAll(BiFunction<? super K, ? super V, ? extends V> function) {
|
||||
Objects.requireNonNull(function);
|
||||
|
||||
@ -1164,12 +1164,13 @@ public class Vector<E>
|
||||
if (i >= size) {
|
||||
return;
|
||||
}
|
||||
final Object[] elementData = Vector.this.elementData;
|
||||
@SuppressWarnings("unchecked")
|
||||
final E[] elementData = (E[]) Vector.this.elementData;
|
||||
if (i >= elementData.length) {
|
||||
throw new ConcurrentModificationException();
|
||||
}
|
||||
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
|
||||
cursor = i;
|
||||
@ -1311,8 +1312,8 @@ public class Vector<E>
|
||||
modCount++;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public synchronized void sort(Comparator<? super E> c) {
|
||||
final int expectedModCount = modCount;
|
||||
Arrays.sort((E[]) elementData, 0, elementCount, c);
|
||||
|
||||
@ -1038,6 +1038,7 @@ public class WeakHashMap<K,V>
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void forEach(BiConsumer<? super K, ? super V> action) {
|
||||
Objects.requireNonNull(action);
|
||||
@ -1059,6 +1060,7 @@ public class WeakHashMap<K,V>
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void replaceAll(BiFunction<? super K, ? super V, ? extends V> function) {
|
||||
Objects.requireNonNull(function);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user