Merge
This commit is contained in:
commit
e49c821349
@ -170,6 +170,7 @@ public abstract class AbstractCollection<E> implements Collection<E> {
|
|||||||
* @throws ArrayStoreException {@inheritDoc}
|
* @throws ArrayStoreException {@inheritDoc}
|
||||||
* @throws NullPointerException {@inheritDoc}
|
* @throws NullPointerException {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public <T> T[] toArray(T[] a) {
|
public <T> T[] toArray(T[] a) {
|
||||||
// Estimate size of array; be prepared to see more or fewer elements
|
// Estimate size of array; be prepared to see more or fewer elements
|
||||||
int size = size();
|
int size = size();
|
||||||
@ -216,6 +217,7 @@ public abstract class AbstractCollection<E> implements Collection<E> {
|
|||||||
* @return array containing the elements in the given array, plus any
|
* @return array containing the elements in the given array, plus any
|
||||||
* further elements returned by the iterator, trimmed to size
|
* further elements returned by the iterator, trimmed to size
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
private static <T> T[] finishToArray(T[] r, Iterator<?> it) {
|
private static <T> T[] finishToArray(T[] r, Iterator<?> it) {
|
||||||
int i = r.length;
|
int i = r.length;
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
|
@ -516,7 +516,7 @@ public abstract class AbstractList<E> extends AbstractCollection<E> implements L
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
ListIterator<E> e1 = listIterator();
|
ListIterator<E> e1 = listIterator();
|
||||||
ListIterator e2 = ((List) o).listIterator();
|
ListIterator<?> e2 = ((List<?>) o).listIterator();
|
||||||
while (e1.hasNext() && e2.hasNext()) {
|
while (e1.hasNext() && e2.hasNext()) {
|
||||||
E o1 = e1.next();
|
E o1 = e1.next();
|
||||||
Object o2 = e2.next();
|
Object o2 = e2.next();
|
||||||
|
@ -443,7 +443,7 @@ public abstract class AbstractMap<K,V> implements Map<K,V> {
|
|||||||
|
|
||||||
if (!(o instanceof Map))
|
if (!(o instanceof Map))
|
||||||
return false;
|
return false;
|
||||||
Map<K,V> m = (Map<K,V>) o;
|
Map<?,?> m = (Map<?,?>) o;
|
||||||
if (m.size() != size())
|
if (m.size() != size())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -534,7 +534,7 @@ public abstract class AbstractMap<K,V> implements Map<K,V> {
|
|||||||
* @return a shallow copy of this map
|
* @return a shallow copy of this map
|
||||||
*/
|
*/
|
||||||
protected Object clone() throws CloneNotSupportedException {
|
protected Object clone() throws CloneNotSupportedException {
|
||||||
AbstractMap<K,V> result = (AbstractMap<K,V>)super.clone();
|
AbstractMap<?,?> result = (AbstractMap<?,?>)super.clone();
|
||||||
result.keySet = null;
|
result.keySet = null;
|
||||||
result.values = null;
|
result.values = null;
|
||||||
return result;
|
return result;
|
||||||
@ -652,7 +652,7 @@ public abstract class AbstractMap<K,V> implements Map<K,V> {
|
|||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (!(o instanceof Map.Entry))
|
if (!(o instanceof Map.Entry))
|
||||||
return false;
|
return false;
|
||||||
Map.Entry e = (Map.Entry)o;
|
Map.Entry<?,?> e = (Map.Entry<?,?>)o;
|
||||||
return eq(key, e.getKey()) && eq(value, e.getValue());
|
return eq(key, e.getKey()) && eq(value, e.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -783,7 +783,7 @@ public abstract class AbstractMap<K,V> implements Map<K,V> {
|
|||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (!(o instanceof Map.Entry))
|
if (!(o instanceof Map.Entry))
|
||||||
return false;
|
return false;
|
||||||
Map.Entry e = (Map.Entry)o;
|
Map.Entry<?,?> e = (Map.Entry<?,?>)o;
|
||||||
return eq(key, e.getKey()) && eq(value, e.getValue());
|
return eq(key, e.getKey()) && eq(value, e.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@ public abstract class AbstractSet<E> extends AbstractCollection<E> implements Se
|
|||||||
|
|
||||||
if (!(o instanceof Set))
|
if (!(o instanceof Set))
|
||||||
return false;
|
return false;
|
||||||
Collection c = (Collection) o;
|
Collection<?> c = (Collection<?>) o;
|
||||||
if (c.size() != size())
|
if (c.size() != size())
|
||||||
return false;
|
return false;
|
||||||
try {
|
try {
|
||||||
|
@ -813,7 +813,8 @@ public class ArrayDeque<E> extends AbstractCollection<E>
|
|||||||
*/
|
*/
|
||||||
public ArrayDeque<E> clone() {
|
public ArrayDeque<E> clone() {
|
||||||
try {
|
try {
|
||||||
ArrayDeque<E> result = (ArrayDeque<E>) super.clone();
|
@SuppressWarnings("unchecked")
|
||||||
|
ArrayDeque<E> result = (ArrayDeque<E>) super.clone();
|
||||||
result.elements = Arrays.copyOf(elements, elements.length);
|
result.elements = Arrays.copyOf(elements, elements.length);
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
@ -849,6 +850,7 @@ public class ArrayDeque<E> extends AbstractCollection<E>
|
|||||||
/**
|
/**
|
||||||
* Deserialize this deque.
|
* Deserialize this deque.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
private void readObject(ObjectInputStream s)
|
private void readObject(ObjectInputStream s)
|
||||||
throws IOException, ClassNotFoundException {
|
throws IOException, ClassNotFoundException {
|
||||||
s.defaultReadObject();
|
s.defaultReadObject();
|
||||||
|
@ -300,8 +300,7 @@ public class ArrayList<E> extends AbstractList<E>
|
|||||||
*/
|
*/
|
||||||
public Object clone() {
|
public Object clone() {
|
||||||
try {
|
try {
|
||||||
@SuppressWarnings("unchecked")
|
ArrayList<?> v = (ArrayList<?>) super.clone();
|
||||||
ArrayList<E> v = (ArrayList<E>) super.clone();
|
|
||||||
v.elementData = Arrays.copyOf(elementData, size);
|
v.elementData = Arrays.copyOf(elementData, size);
|
||||||
v.modCount = 0;
|
v.modCount = 0;
|
||||||
return v;
|
return v;
|
||||||
|
@ -560,6 +560,7 @@ public class Arrays {
|
|||||||
* off is the offset to generate corresponding low, high in src
|
* off is the offset to generate corresponding low, high in src
|
||||||
* To be removed in a future release.
|
* To be removed in a future release.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||||
private static void mergeSort(Object[] src,
|
private static void mergeSort(Object[] src,
|
||||||
Object[] dest,
|
Object[] dest,
|
||||||
int low,
|
int low,
|
||||||
@ -746,6 +747,7 @@ public class Arrays {
|
|||||||
* off is the offset into src corresponding to low in dest
|
* off is the offset into src corresponding to low in dest
|
||||||
* To be removed in a future release.
|
* To be removed in a future release.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||||
private static void mergeSort(Object[] src,
|
private static void mergeSort(Object[] src,
|
||||||
Object[] dest,
|
Object[] dest,
|
||||||
int low, int high, int off,
|
int low, int high, int off,
|
||||||
@ -1477,8 +1479,10 @@ public class Arrays {
|
|||||||
|
|
||||||
while (low <= high) {
|
while (low <= high) {
|
||||||
int mid = (low + high) >>> 1;
|
int mid = (low + high) >>> 1;
|
||||||
Comparable midVal = (Comparable)a[mid];
|
@SuppressWarnings("rawtypes")
|
||||||
int cmp = midVal.compareTo(key);
|
Comparable midVal = (Comparable)a[mid];
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
int cmp = midVal.compareTo(key);
|
||||||
|
|
||||||
if (cmp < 0)
|
if (cmp < 0)
|
||||||
low = mid + 1;
|
low = mid + 1;
|
||||||
@ -2215,6 +2219,7 @@ public class Arrays {
|
|||||||
* @throws NullPointerException if <tt>original</tt> is null
|
* @throws NullPointerException if <tt>original</tt> is null
|
||||||
* @since 1.6
|
* @since 1.6
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public static <T> T[] copyOf(T[] original, int newLength) {
|
public static <T> T[] copyOf(T[] original, int newLength) {
|
||||||
return (T[]) copyOf(original, newLength, original.getClass());
|
return (T[]) copyOf(original, newLength, original.getClass());
|
||||||
}
|
}
|
||||||
@ -2242,6 +2247,7 @@ public class Arrays {
|
|||||||
* @since 1.6
|
* @since 1.6
|
||||||
*/
|
*/
|
||||||
public static <T,U> T[] copyOf(U[] original, int newLength, Class<? extends T[]> newType) {
|
public static <T,U> T[] copyOf(U[] original, int newLength, Class<? extends T[]> newType) {
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
T[] copy = ((Object)newType == (Object)Object[].class)
|
T[] copy = ((Object)newType == (Object)Object[].class)
|
||||||
? (T[]) new Object[newLength]
|
? (T[]) new Object[newLength]
|
||||||
: (T[]) Array.newInstance(newType.getComponentType(), newLength);
|
: (T[]) Array.newInstance(newType.getComponentType(), newLength);
|
||||||
@ -2470,8 +2476,9 @@ public class Arrays {
|
|||||||
* @throws NullPointerException if <tt>original</tt> is null
|
* @throws NullPointerException if <tt>original</tt> is null
|
||||||
* @since 1.6
|
* @since 1.6
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public static <T> T[] copyOfRange(T[] original, int from, int to) {
|
public static <T> T[] copyOfRange(T[] original, int from, int to) {
|
||||||
return copyOfRange(original, from, to, (Class<T[]>) original.getClass());
|
return copyOfRange(original, from, to, (Class<? extends T[]>) original.getClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2509,6 +2516,7 @@ public class Arrays {
|
|||||||
int newLength = to - from;
|
int newLength = to - from;
|
||||||
if (newLength < 0)
|
if (newLength < 0)
|
||||||
throw new IllegalArgumentException(from + " > " + to);
|
throw new IllegalArgumentException(from + " > " + to);
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
T[] copy = ((Object)newType == (Object)Object[].class)
|
T[] copy = ((Object)newType == (Object)Object[].class)
|
||||||
? (T[]) new Object[newLength]
|
? (T[]) new Object[newLength]
|
||||||
: (T[]) Array.newInstance(newType.getComponentType(), newLength);
|
: (T[]) Array.newInstance(newType.getComponentType(), newLength);
|
||||||
@ -2851,6 +2859,7 @@ public class Arrays {
|
|||||||
return a.clone();
|
return a.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public <T> T[] toArray(T[] a) {
|
public <T> T[] toArray(T[] a) {
|
||||||
int size = size();
|
int size = size();
|
||||||
if (a.length < size)
|
if (a.length < size)
|
||||||
@ -3634,7 +3643,7 @@ public class Arrays {
|
|||||||
if (element == null) {
|
if (element == null) {
|
||||||
buf.append("null");
|
buf.append("null");
|
||||||
} else {
|
} else {
|
||||||
Class eClass = element.getClass();
|
Class<?> eClass = element.getClass();
|
||||||
|
|
||||||
if (eClass.isArray()) {
|
if (eClass.isArray()) {
|
||||||
if (eClass == byte[].class)
|
if (eClass == byte[].class)
|
||||||
|
@ -840,7 +840,7 @@ public abstract class Calendar implements Serializable, Cloneable, Comparable<Ca
|
|||||||
* of a Locale.
|
* of a Locale.
|
||||||
*/
|
*/
|
||||||
private static final ConcurrentMap<Locale, int[]> cachedLocaleData
|
private static final ConcurrentMap<Locale, int[]> cachedLocaleData
|
||||||
= new ConcurrentHashMap<Locale, int[]>(3);
|
= new ConcurrentHashMap<>(3);
|
||||||
|
|
||||||
// Special values of stamp[]
|
// Special values of stamp[]
|
||||||
/**
|
/**
|
||||||
@ -1499,7 +1499,7 @@ public abstract class Calendar implements Serializable, Cloneable, Comparable<Ca
|
|||||||
DateFormatSymbols symbols = DateFormatSymbols.getInstance(locale);
|
DateFormatSymbols symbols = DateFormatSymbols.getInstance(locale);
|
||||||
String[] strings = getFieldStrings(field, style, symbols);
|
String[] strings = getFieldStrings(field, style, symbols);
|
||||||
if (strings != null) {
|
if (strings != null) {
|
||||||
Map<String,Integer> names = new HashMap<String,Integer>();
|
Map<String,Integer> names = new HashMap<>();
|
||||||
for (int i = 0; i < strings.length; i++) {
|
for (int i = 0; i < strings.length; i++) {
|
||||||
if (strings[i].length() == 0) {
|
if (strings[i].length() == 0) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -150,6 +150,7 @@ public class Collections {
|
|||||||
* detects that the natural ordering of the list elements is
|
* detects that the natural ordering of the list elements is
|
||||||
* found to violate the {@link Comparable} contract
|
* found to violate the {@link Comparable} contract
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public static <T extends Comparable<? super T>> void sort(List<T> list) {
|
public static <T extends Comparable<? super T>> void sort(List<T> list) {
|
||||||
Object[] a = list.toArray();
|
Object[] a = list.toArray();
|
||||||
Arrays.sort(a);
|
Arrays.sort(a);
|
||||||
@ -212,13 +213,14 @@ public class Collections {
|
|||||||
* @throws IllegalArgumentException (optional) if the comparator is
|
* @throws IllegalArgumentException (optional) if the comparator is
|
||||||
* found to violate the {@link Comparator} contract
|
* found to violate the {@link Comparator} contract
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||||
public static <T> void sort(List<T> list, Comparator<? super T> c) {
|
public static <T> void sort(List<T> list, Comparator<? super T> c) {
|
||||||
Object[] a = list.toArray();
|
Object[] a = list.toArray();
|
||||||
Arrays.sort(a, (Comparator)c);
|
Arrays.sort(a, (Comparator)c);
|
||||||
ListIterator i = list.listIterator();
|
ListIterator<T> i = list.listIterator();
|
||||||
for (int j=0; j<a.length; j++) {
|
for (int j=0; j<a.length; j++) {
|
||||||
i.next();
|
i.next();
|
||||||
i.set(a[j]);
|
i.set((T)a[j]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -357,9 +359,10 @@ public class Collections {
|
|||||||
* or the search key is not mutually comparable with the
|
* or the search key is not mutually comparable with the
|
||||||
* elements of the list using this comparator.
|
* elements of the list using this comparator.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public static <T> int binarySearch(List<? extends T> list, T key, Comparator<? super T> c) {
|
public static <T> int binarySearch(List<? extends T> list, T key, Comparator<? super T> c) {
|
||||||
if (c==null)
|
if (c==null)
|
||||||
return binarySearch((List) list, key);
|
return binarySearch((List<? extends Comparable<? super T>>) list, key);
|
||||||
|
|
||||||
if (list instanceof RandomAccess || list.size()<BINARYSEARCH_THRESHOLD)
|
if (list instanceof RandomAccess || list.size()<BINARYSEARCH_THRESHOLD)
|
||||||
return Collections.indexedBinarySearch(list, key, c);
|
return Collections.indexedBinarySearch(list, key, c);
|
||||||
@ -406,9 +409,6 @@ public class Collections {
|
|||||||
return -(low + 1); // key not found
|
return -(low + 1); // key not found
|
||||||
}
|
}
|
||||||
|
|
||||||
private interface SelfComparable extends Comparable<SelfComparable> {}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reverses the order of the elements in the specified list.<p>
|
* Reverses the order of the elements in the specified list.<p>
|
||||||
*
|
*
|
||||||
@ -418,12 +418,16 @@ public class Collections {
|
|||||||
* @throws UnsupportedOperationException if the specified list or
|
* @throws UnsupportedOperationException if the specified list or
|
||||||
* its list-iterator does not support the <tt>set</tt> operation.
|
* its list-iterator does not support the <tt>set</tt> operation.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||||
public static void reverse(List<?> list) {
|
public static void reverse(List<?> list) {
|
||||||
int size = list.size();
|
int size = list.size();
|
||||||
if (size < REVERSE_THRESHOLD || list instanceof RandomAccess) {
|
if (size < REVERSE_THRESHOLD || list instanceof RandomAccess) {
|
||||||
for (int i=0, mid=size>>1, j=size-1; i<mid; i++, j--)
|
for (int i=0, mid=size>>1, j=size-1; i<mid; i++, j--)
|
||||||
swap(list, i, j);
|
swap(list, i, j);
|
||||||
} else {
|
} else {
|
||||||
|
// instead of using a raw type here, it's possible to capture
|
||||||
|
// the wildcard but it will require a call to a supplementary
|
||||||
|
// private method
|
||||||
ListIterator fwd = list.listIterator();
|
ListIterator fwd = list.listIterator();
|
||||||
ListIterator rev = list.listIterator(size);
|
ListIterator rev = list.listIterator(size);
|
||||||
for (int i=0, mid=list.size()>>1; i<mid; i++) {
|
for (int i=0, mid=list.size()>>1; i<mid; i++) {
|
||||||
@ -493,6 +497,7 @@ public class Collections {
|
|||||||
* @throws UnsupportedOperationException if the specified list or its
|
* @throws UnsupportedOperationException if the specified list or its
|
||||||
* list-iterator does not support the <tt>set</tt> operation.
|
* list-iterator does not support the <tt>set</tt> operation.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||||
public static void shuffle(List<?> list, Random rnd) {
|
public static void shuffle(List<?> list, Random rnd) {
|
||||||
int size = list.size();
|
int size = list.size();
|
||||||
if (size < SHUFFLE_THRESHOLD || list instanceof RandomAccess) {
|
if (size < SHUFFLE_THRESHOLD || list instanceof RandomAccess) {
|
||||||
@ -506,6 +511,9 @@ public class Collections {
|
|||||||
swap(arr, i-1, rnd.nextInt(i));
|
swap(arr, i-1, rnd.nextInt(i));
|
||||||
|
|
||||||
// Dump array back into list
|
// Dump array back into list
|
||||||
|
// instead of using a raw type here, it's possible to capture
|
||||||
|
// the wildcard but it will require a call to a supplementary
|
||||||
|
// private method
|
||||||
ListIterator it = list.listIterator();
|
ListIterator it = list.listIterator();
|
||||||
for (int i=0; i<arr.length; i++) {
|
for (int i=0; i<arr.length; i++) {
|
||||||
it.next();
|
it.next();
|
||||||
@ -527,7 +535,11 @@ public class Collections {
|
|||||||
* || j < 0 || j >= list.size()).
|
* || j < 0 || j >= list.size()).
|
||||||
* @since 1.4
|
* @since 1.4
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||||
public static void swap(List<?> list, int i, int j) {
|
public static void swap(List<?> list, int i, int j) {
|
||||||
|
// instead of using a raw type here, it's possible to capture
|
||||||
|
// the wildcard but it will require a call to a supplementary
|
||||||
|
// private method
|
||||||
final List l = list;
|
final List l = list;
|
||||||
l.set(i, l.set(j, l.get(i)));
|
l.set(i, l.set(j, l.get(i)));
|
||||||
}
|
}
|
||||||
@ -657,9 +669,10 @@ public class Collections {
|
|||||||
* @throws NoSuchElementException if the collection is empty.
|
* @throws NoSuchElementException if the collection is empty.
|
||||||
* @see Comparable
|
* @see Comparable
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||||
public static <T> T min(Collection<? extends T> coll, Comparator<? super T> comp) {
|
public static <T> T min(Collection<? extends T> coll, Comparator<? super T> comp) {
|
||||||
if (comp==null)
|
if (comp==null)
|
||||||
return (T)min((Collection<SelfComparable>) (Collection) coll);
|
return (T)min((Collection) coll);
|
||||||
|
|
||||||
Iterator<? extends T> i = coll.iterator();
|
Iterator<? extends T> i = coll.iterator();
|
||||||
T candidate = i.next();
|
T candidate = i.next();
|
||||||
@ -727,9 +740,10 @@ public class Collections {
|
|||||||
* @throws NoSuchElementException if the collection is empty.
|
* @throws NoSuchElementException if the collection is empty.
|
||||||
* @see Comparable
|
* @see Comparable
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||||
public static <T> T max(Collection<? extends T> coll, Comparator<? super T> comp) {
|
public static <T> T max(Collection<? extends T> coll, Comparator<? super T> comp) {
|
||||||
if (comp==null)
|
if (comp==null)
|
||||||
return (T)max((Collection<SelfComparable>) (Collection) coll);
|
return (T)max((Collection) coll);
|
||||||
|
|
||||||
Iterator<? extends T> i = coll.iterator();
|
Iterator<? extends T> i = coll.iterator();
|
||||||
T candidate = i.next();
|
T candidate = i.next();
|
||||||
@ -1389,7 +1403,9 @@ public class Collections {
|
|||||||
extends UnmodifiableSet<Map.Entry<K,V>> {
|
extends UnmodifiableSet<Map.Entry<K,V>> {
|
||||||
private static final long serialVersionUID = 7854390611657943733L;
|
private static final long serialVersionUID = 7854390611657943733L;
|
||||||
|
|
||||||
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||||
UnmodifiableEntrySet(Set<? extends Map.Entry<? extends K, ? extends V>> s) {
|
UnmodifiableEntrySet(Set<? extends Map.Entry<? extends K, ? extends V>> s) {
|
||||||
|
// Need to cast to raw in order to work around a limitation in the type system
|
||||||
super((Set)s);
|
super((Set)s);
|
||||||
}
|
}
|
||||||
public Iterator<Map.Entry<K,V>> iterator() {
|
public Iterator<Map.Entry<K,V>> iterator() {
|
||||||
@ -1408,13 +1424,15 @@ public class Collections {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public Object[] toArray() {
|
public Object[] toArray() {
|
||||||
Object[] a = c.toArray();
|
Object[] a = c.toArray();
|
||||||
for (int i=0; i<a.length; i++)
|
for (int i=0; i<a.length; i++)
|
||||||
a[i] = new UnmodifiableEntry<>((Map.Entry<K,V>)a[i]);
|
a[i] = new UnmodifiableEntry<>((Map.Entry<? extends K, ? extends V>)a[i]);
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public <T> T[] toArray(T[] a) {
|
public <T> T[] toArray(T[] a) {
|
||||||
// We don't pass a to c.toArray, to avoid window of
|
// We don't pass a to c.toArray, to avoid window of
|
||||||
// vulnerability wherein an unscrupulous multithreaded client
|
// vulnerability wherein an unscrupulous multithreaded client
|
||||||
@ -1422,7 +1440,7 @@ public class Collections {
|
|||||||
Object[] arr = c.toArray(a.length==0 ? a : Arrays.copyOf(a, 0));
|
Object[] arr = c.toArray(a.length==0 ? a : Arrays.copyOf(a, 0));
|
||||||
|
|
||||||
for (int i=0; i<arr.length; i++)
|
for (int i=0; i<arr.length; i++)
|
||||||
arr[i] = new UnmodifiableEntry<>((Map.Entry<K,V>)arr[i]);
|
arr[i] = new UnmodifiableEntry<>((Map.Entry<? extends K, ? extends V>)arr[i]);
|
||||||
|
|
||||||
if (arr.length > a.length)
|
if (arr.length > a.length)
|
||||||
return (T[])arr;
|
return (T[])arr;
|
||||||
@ -1464,7 +1482,7 @@ public class Collections {
|
|||||||
|
|
||||||
if (!(o instanceof Set))
|
if (!(o instanceof Set))
|
||||||
return false;
|
return false;
|
||||||
Set s = (Set) o;
|
Set<?> s = (Set<?>) o;
|
||||||
if (s.size() != c.size())
|
if (s.size() != c.size())
|
||||||
return false;
|
return false;
|
||||||
return containsAll(s); // Invokes safe containsAll() above
|
return containsAll(s); // Invokes safe containsAll() above
|
||||||
@ -1493,7 +1511,7 @@ public class Collections {
|
|||||||
return true;
|
return true;
|
||||||
if (!(o instanceof Map.Entry))
|
if (!(o instanceof Map.Entry))
|
||||||
return false;
|
return false;
|
||||||
Map.Entry t = (Map.Entry)o;
|
Map.Entry<?,?> t = (Map.Entry<?,?>)o;
|
||||||
return eq(e.getKey(), t.getKey()) &&
|
return eq(e.getKey(), t.getKey()) &&
|
||||||
eq(e.getValue(), t.getValue());
|
eq(e.getValue(), t.getValue());
|
||||||
}
|
}
|
||||||
|
@ -114,7 +114,6 @@ class ComparableTimSort {
|
|||||||
|
|
||||||
// Allocate temp storage (which may be increased later if necessary)
|
// Allocate temp storage (which may be increased later if necessary)
|
||||||
int len = a.length;
|
int len = a.length;
|
||||||
@SuppressWarnings({"unchecked", "UnnecessaryLocalVariable"})
|
|
||||||
Object[] newArray = new Object[len < 2 * INITIAL_TMP_STORAGE_LENGTH ?
|
Object[] newArray = new Object[len < 2 * INITIAL_TMP_STORAGE_LENGTH ?
|
||||||
len >>> 1 : INITIAL_TMP_STORAGE_LENGTH];
|
len >>> 1 : INITIAL_TMP_STORAGE_LENGTH];
|
||||||
tmp = newArray;
|
tmp = newArray;
|
||||||
@ -209,14 +208,13 @@ class ComparableTimSort {
|
|||||||
* @param start the index of the first element in the range that is
|
* @param start the index of the first element in the range that is
|
||||||
* not already known to be sorted ({@code lo <= start <= hi})
|
* not already known to be sorted ({@code lo <= start <= hi})
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("fallthrough")
|
@SuppressWarnings({ "fallthrough", "rawtypes", "unchecked" })
|
||||||
private static void binarySort(Object[] a, int lo, int hi, int start) {
|
private static void binarySort(Object[] a, int lo, int hi, int start) {
|
||||||
assert lo <= start && start <= hi;
|
assert lo <= start && start <= hi;
|
||||||
if (start == lo)
|
if (start == lo)
|
||||||
start++;
|
start++;
|
||||||
for ( ; start < hi; start++) {
|
for ( ; start < hi; start++) {
|
||||||
@SuppressWarnings("unchecked")
|
Comparable pivot = (Comparable) a[start];
|
||||||
Comparable<Object> pivot = (Comparable) a[start];
|
|
||||||
|
|
||||||
// Set left (and right) to the index where a[start] (pivot) belongs
|
// Set left (and right) to the index where a[start] (pivot) belongs
|
||||||
int left = lo;
|
int left = lo;
|
||||||
@ -279,7 +277,7 @@ class ComparableTimSort {
|
|||||||
* @return the length of the run beginning at the specified position in
|
* @return the length of the run beginning at the specified position in
|
||||||
* the specified array
|
* the specified array
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||||
private static int countRunAndMakeAscending(Object[] a, int lo, int hi) {
|
private static int countRunAndMakeAscending(Object[] a, int lo, int hi) {
|
||||||
assert lo < hi;
|
assert lo < hi;
|
||||||
int runHi = lo + 1;
|
int runHi = lo + 1;
|
||||||
@ -614,7 +612,7 @@ class ComparableTimSort {
|
|||||||
* (must be aBase + aLen)
|
* (must be aBase + aLen)
|
||||||
* @param len2 length of second run to be merged (must be > 0)
|
* @param len2 length of second run to be merged (must be > 0)
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||||
private void mergeLo(int base1, int len1, int base2, int len2) {
|
private void mergeLo(int base1, int len1, int base2, int len2) {
|
||||||
assert len1 > 0 && len2 > 0 && base1 + len1 == base2;
|
assert len1 > 0 && len2 > 0 && base1 + len1 == base2;
|
||||||
|
|
||||||
@ -731,7 +729,7 @@ class ComparableTimSort {
|
|||||||
* (must be aBase + aLen)
|
* (must be aBase + aLen)
|
||||||
* @param len2 length of second run to be merged (must be > 0)
|
* @param len2 length of second run to be merged (must be > 0)
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||||
private void mergeHi(int base1, int len1, int base2, int len2) {
|
private void mergeHi(int base1, int len1, int base2, int len2) {
|
||||||
assert len1 > 0 && len2 > 0 && base1 + len1 == base2;
|
assert len1 > 0 && len2 > 0 && base1 + len1 == base2;
|
||||||
|
|
||||||
@ -865,7 +863,6 @@ class ComparableTimSort {
|
|||||||
else
|
else
|
||||||
newSize = Math.min(newSize, a.length >>> 1);
|
newSize = Math.min(newSize, a.length >>> 1);
|
||||||
|
|
||||||
@SuppressWarnings({"unchecked", "UnnecessaryLocalVariable"})
|
|
||||||
Object[] newArray = new Object[newSize];
|
Object[] newArray = new Object[newSize];
|
||||||
tmp = newArray;
|
tmp = newArray;
|
||||||
}
|
}
|
||||||
|
@ -404,7 +404,7 @@ public final class Currency implements Serializable {
|
|||||||
public static Set<Currency> getAvailableCurrencies() {
|
public static Set<Currency> getAvailableCurrencies() {
|
||||||
synchronized(Currency.class) {
|
synchronized(Currency.class) {
|
||||||
if (available == null) {
|
if (available == null) {
|
||||||
available = new HashSet<Currency>(256);
|
available = new HashSet<>(256);
|
||||||
|
|
||||||
// Add simple currencies first
|
// Add simple currencies first
|
||||||
for (char c1 = 'A'; c1 <= 'Z'; c1 ++) {
|
for (char c1 = 'A'; c1 <= 'Z'; c1 ++) {
|
||||||
|
@ -120,11 +120,12 @@ public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V>
|
|||||||
return (value == null ? NULL : value);
|
return (value == null ? NULL : value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
private V unmaskNull(Object value) {
|
private V unmaskNull(Object value) {
|
||||||
return (V) (value == NULL ? null : value);
|
return (V)(value == NULL ? null : value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Enum[] ZERO_LENGTH_ENUM_ARRAY = new Enum[0];
|
private static final Enum<?>[] ZERO_LENGTH_ENUM_ARRAY = new Enum<?>[0];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an empty enum map with the specified key type.
|
* Creates an empty enum map with the specified key type.
|
||||||
@ -218,12 +219,12 @@ public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V>
|
|||||||
* key
|
* key
|
||||||
*/
|
*/
|
||||||
public boolean containsKey(Object key) {
|
public boolean containsKey(Object key) {
|
||||||
return isValidKey(key) && vals[((Enum)key).ordinal()] != null;
|
return isValidKey(key) && vals[((Enum<?>)key).ordinal()] != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean containsMapping(Object key, Object value) {
|
private boolean containsMapping(Object key, Object value) {
|
||||||
return isValidKey(key) &&
|
return isValidKey(key) &&
|
||||||
maskNull(value).equals(vals[((Enum)key).ordinal()]);
|
maskNull(value).equals(vals[((Enum<?>)key).ordinal()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -243,7 +244,7 @@ public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V>
|
|||||||
*/
|
*/
|
||||||
public V get(Object key) {
|
public V get(Object key) {
|
||||||
return (isValidKey(key) ?
|
return (isValidKey(key) ?
|
||||||
unmaskNull(vals[((Enum)key).ordinal()]) : null);
|
unmaskNull(vals[((Enum<?>)key).ordinal()]) : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Modification Operations
|
// Modification Operations
|
||||||
@ -285,7 +286,7 @@ public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V>
|
|||||||
public V remove(Object key) {
|
public V remove(Object key) {
|
||||||
if (!isValidKey(key))
|
if (!isValidKey(key))
|
||||||
return null;
|
return null;
|
||||||
int index = ((Enum)key).ordinal();
|
int index = ((Enum<?>)key).ordinal();
|
||||||
Object oldValue = vals[index];
|
Object oldValue = vals[index];
|
||||||
vals[index] = null;
|
vals[index] = null;
|
||||||
if (oldValue != null)
|
if (oldValue != null)
|
||||||
@ -296,7 +297,7 @@ public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V>
|
|||||||
private boolean removeMapping(Object key, Object value) {
|
private boolean removeMapping(Object key, Object value) {
|
||||||
if (!isValidKey(key))
|
if (!isValidKey(key))
|
||||||
return false;
|
return false;
|
||||||
int index = ((Enum)key).ordinal();
|
int index = ((Enum<?>)key).ordinal();
|
||||||
if (maskNull(value).equals(vals[index])) {
|
if (maskNull(value).equals(vals[index])) {
|
||||||
vals[index] = null;
|
vals[index] = null;
|
||||||
size--;
|
size--;
|
||||||
@ -314,7 +315,7 @@ public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V>
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Cheaper than instanceof Enum followed by getDeclaringClass
|
// Cheaper than instanceof Enum followed by getDeclaringClass
|
||||||
Class keyClass = key.getClass();
|
Class<?> keyClass = key.getClass();
|
||||||
return keyClass == keyType || keyClass.getSuperclass() == keyType;
|
return keyClass == keyType || keyClass.getSuperclass() == keyType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -331,8 +332,7 @@ public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V>
|
|||||||
*/
|
*/
|
||||||
public void putAll(Map<? extends K, ? extends V> m) {
|
public void putAll(Map<? extends K, ? extends V> m) {
|
||||||
if (m instanceof EnumMap) {
|
if (m instanceof EnumMap) {
|
||||||
EnumMap<? extends K, ? extends V> em =
|
EnumMap<?, ?> em = (EnumMap<?, ?>)m;
|
||||||
(EnumMap<? extends K, ? extends V>)m;
|
|
||||||
if (em.keyType != keyType) {
|
if (em.keyType != keyType) {
|
||||||
if (em.isEmpty())
|
if (em.isEmpty())
|
||||||
return;
|
return;
|
||||||
@ -476,13 +476,13 @@ public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V>
|
|||||||
public boolean contains(Object o) {
|
public boolean contains(Object o) {
|
||||||
if (!(o instanceof Map.Entry))
|
if (!(o instanceof Map.Entry))
|
||||||
return false;
|
return false;
|
||||||
Map.Entry entry = (Map.Entry)o;
|
Map.Entry<?,?> entry = (Map.Entry<?,?>)o;
|
||||||
return containsMapping(entry.getKey(), entry.getValue());
|
return containsMapping(entry.getKey(), entry.getValue());
|
||||||
}
|
}
|
||||||
public boolean remove(Object o) {
|
public boolean remove(Object o) {
|
||||||
if (!(o instanceof Map.Entry))
|
if (!(o instanceof Map.Entry))
|
||||||
return false;
|
return false;
|
||||||
Map.Entry entry = (Map.Entry)o;
|
Map.Entry<?,?> entry = (Map.Entry<?,?>)o;
|
||||||
return removeMapping(entry.getKey(), entry.getValue());
|
return removeMapping(entry.getKey(), entry.getValue());
|
||||||
}
|
}
|
||||||
public int size() {
|
public int size() {
|
||||||
@ -610,7 +610,7 @@ public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V>
|
|||||||
if (!(o instanceof Map.Entry))
|
if (!(o instanceof Map.Entry))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
Map.Entry e = (Map.Entry)o;
|
Map.Entry<?,?> e = (Map.Entry<?,?>)o;
|
||||||
V ourValue = unmaskNull(vals[index]);
|
V ourValue = unmaskNull(vals[index]);
|
||||||
Object hisValue = e.getValue();
|
Object hisValue = e.getValue();
|
||||||
return (e.getKey() == keyUniverse[index] &&
|
return (e.getKey() == keyUniverse[index] &&
|
||||||
@ -655,11 +655,11 @@ public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V>
|
|||||||
if (this == o)
|
if (this == o)
|
||||||
return true;
|
return true;
|
||||||
if (o instanceof EnumMap)
|
if (o instanceof EnumMap)
|
||||||
return equals((EnumMap)o);
|
return equals((EnumMap<?,?>)o);
|
||||||
if (!(o instanceof Map))
|
if (!(o instanceof Map))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
Map<K,V> m = (Map<K,V>)o;
|
Map<?,?> m = (Map<?,?>)o;
|
||||||
if (size != m.size())
|
if (size != m.size())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -680,7 +680,7 @@ public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V>
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean equals(EnumMap em) {
|
private boolean equals(EnumMap<?,?> em) {
|
||||||
if (em.keyType != keyType)
|
if (em.keyType != keyType)
|
||||||
return size == 0 && em.size == 0;
|
return size == 0 && em.size == 0;
|
||||||
|
|
||||||
@ -721,6 +721,7 @@ public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V>
|
|||||||
*
|
*
|
||||||
* @return a shallow copy of this enum map
|
* @return a shallow copy of this enum map
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public EnumMap<K, V> clone() {
|
public EnumMap<K, V> clone() {
|
||||||
EnumMap<K, V> result = null;
|
EnumMap<K, V> result = null;
|
||||||
try {
|
try {
|
||||||
@ -736,7 +737,7 @@ public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V>
|
|||||||
* Throws an exception if e is not of the correct type for this enum set.
|
* Throws an exception if e is not of the correct type for this enum set.
|
||||||
*/
|
*/
|
||||||
private void typeCheck(K key) {
|
private void typeCheck(K key) {
|
||||||
Class keyClass = key.getClass();
|
Class<?> keyClass = key.getClass();
|
||||||
if (keyClass != keyType && keyClass.getSuperclass() != keyType)
|
if (keyClass != keyType && keyClass.getSuperclass() != keyType)
|
||||||
throw new ClassCastException(keyClass + " != " + keyType);
|
throw new ClassCastException(keyClass + " != " + keyType);
|
||||||
}
|
}
|
||||||
@ -785,6 +786,7 @@ public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V>
|
|||||||
* Reconstitute the <tt>EnumMap</tt> instance from a stream (i.e.,
|
* Reconstitute the <tt>EnumMap</tt> instance from a stream (i.e.,
|
||||||
* deserialize it).
|
* deserialize it).
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
private void readObject(java.io.ObjectInputStream s)
|
private void readObject(java.io.ObjectInputStream s)
|
||||||
throws java.io.IOException, ClassNotFoundException
|
throws java.io.IOException, ClassNotFoundException
|
||||||
{
|
{
|
||||||
|
@ -88,11 +88,11 @@ public abstract class EnumSet<E extends Enum<E>> extends AbstractSet<E>
|
|||||||
/**
|
/**
|
||||||
* All of the values comprising T. (Cached for performance.)
|
* All of the values comprising T. (Cached for performance.)
|
||||||
*/
|
*/
|
||||||
final Enum[] universe;
|
final Enum<?>[] universe;
|
||||||
|
|
||||||
private static Enum[] ZERO_LENGTH_ENUM_ARRAY = new Enum[0];
|
private static Enum<?>[] ZERO_LENGTH_ENUM_ARRAY = new Enum<?>[0];
|
||||||
|
|
||||||
EnumSet(Class<E>elementType, Enum[] universe) {
|
EnumSet(Class<E>elementType, Enum<?>[] universe) {
|
||||||
this.elementType = elementType;
|
this.elementType = elementType;
|
||||||
this.universe = universe;
|
this.universe = universe;
|
||||||
}
|
}
|
||||||
@ -105,7 +105,7 @@ public abstract class EnumSet<E extends Enum<E>> extends AbstractSet<E>
|
|||||||
* @throws NullPointerException if <tt>elementType</tt> is null
|
* @throws NullPointerException if <tt>elementType</tt> is null
|
||||||
*/
|
*/
|
||||||
public static <E extends Enum<E>> EnumSet<E> noneOf(Class<E> elementType) {
|
public static <E extends Enum<E>> EnumSet<E> noneOf(Class<E> elementType) {
|
||||||
Enum[] universe = getUniverse(elementType);
|
Enum<?>[] universe = getUniverse(elementType);
|
||||||
if (universe == null)
|
if (universe == null)
|
||||||
throw new ClassCastException(elementType + " not an enum");
|
throw new ClassCastException(elementType + " not an enum");
|
||||||
|
|
||||||
@ -358,6 +358,7 @@ public abstract class EnumSet<E extends Enum<E>> extends AbstractSet<E>
|
|||||||
*
|
*
|
||||||
* @return a copy of this set
|
* @return a copy of this set
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public EnumSet<E> clone() {
|
public EnumSet<E> clone() {
|
||||||
try {
|
try {
|
||||||
return (EnumSet<E>) super.clone();
|
return (EnumSet<E>) super.clone();
|
||||||
@ -375,7 +376,7 @@ public abstract class EnumSet<E extends Enum<E>> extends AbstractSet<E>
|
|||||||
* Throws an exception if e is not of the correct type for this enum set.
|
* Throws an exception if e is not of the correct type for this enum set.
|
||||||
*/
|
*/
|
||||||
final void typeCheck(E e) {
|
final void typeCheck(E e) {
|
||||||
Class eClass = e.getClass();
|
Class<?> eClass = e.getClass();
|
||||||
if (eClass != elementType && eClass.getSuperclass() != elementType)
|
if (eClass != elementType && eClass.getSuperclass() != elementType)
|
||||||
throw new ClassCastException(eClass + " != " + elementType);
|
throw new ClassCastException(eClass + " != " + elementType);
|
||||||
}
|
}
|
||||||
@ -413,16 +414,19 @@ public abstract class EnumSet<E extends Enum<E>> extends AbstractSet<E>
|
|||||||
*
|
*
|
||||||
* @serial
|
* @serial
|
||||||
*/
|
*/
|
||||||
private final Enum[] elements;
|
private final Enum<?>[] elements;
|
||||||
|
|
||||||
SerializationProxy(EnumSet<E> set) {
|
SerializationProxy(EnumSet<E> set) {
|
||||||
elementType = set.elementType;
|
elementType = set.elementType;
|
||||||
elements = set.toArray(ZERO_LENGTH_ENUM_ARRAY);
|
elements = set.toArray(ZERO_LENGTH_ENUM_ARRAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// instead of cast to E, we should perhaps use elementType.cast()
|
||||||
|
// to avoid injection of forged stream, but it will slow the implementation
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
private Object readResolve() {
|
private Object readResolve() {
|
||||||
EnumSet<E> result = EnumSet.noneOf(elementType);
|
EnumSet<E> result = EnumSet.noneOf(elementType);
|
||||||
for (Enum e : elements)
|
for (Enum<?> e : elements)
|
||||||
result.add((E)e);
|
result.add((E)e);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -146,7 +146,7 @@ public class HashMap<K,V>
|
|||||||
/**
|
/**
|
||||||
* The table, resized as necessary. Length MUST Always be a power of two.
|
* The table, resized as necessary. Length MUST Always be a power of two.
|
||||||
*/
|
*/
|
||||||
transient Entry[] table;
|
transient Entry<?,?>[] table;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The number of key-value mappings contained in this map.
|
* The number of key-value mappings contained in this map.
|
||||||
@ -311,16 +311,17 @@ public class HashMap<K,V>
|
|||||||
*
|
*
|
||||||
* @see #put(Object, Object)
|
* @see #put(Object, Object)
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public V get(Object key) {
|
public V get(Object key) {
|
||||||
if (key == null)
|
if (key == null)
|
||||||
return getForNullKey();
|
return (V)getForNullKey();
|
||||||
int hash = hash(key.hashCode());
|
int hash = hash(key.hashCode());
|
||||||
for (Entry<K,V> e = table[indexFor(hash, table.length)];
|
for (Entry<?,?> e = table[indexFor(hash, table.length)];
|
||||||
e != null;
|
e != null;
|
||||||
e = e.next) {
|
e = e.next) {
|
||||||
Object k;
|
Object k;
|
||||||
if (e.hash == hash && ((k = e.key) == key || key.equals(k)))
|
if (e.hash == hash && ((k = e.key) == key || key.equals(k)))
|
||||||
return e.value;
|
return (V)e.value;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -332,8 +333,8 @@ public class HashMap<K,V>
|
|||||||
* operations (get and put), but incorporated with conditionals in
|
* operations (get and put), but incorporated with conditionals in
|
||||||
* others.
|
* others.
|
||||||
*/
|
*/
|
||||||
private V getForNullKey() {
|
private Object getForNullKey() {
|
||||||
for (Entry<K,V> e = table[0]; e != null; e = e.next) {
|
for (Entry<?,?> e = table[0]; e != null; e = e.next) {
|
||||||
if (e.key == null)
|
if (e.key == null)
|
||||||
return e.value;
|
return e.value;
|
||||||
}
|
}
|
||||||
@ -357,15 +358,16 @@ public class HashMap<K,V>
|
|||||||
* HashMap. Returns null if the HashMap contains no mapping
|
* HashMap. Returns null if the HashMap contains no mapping
|
||||||
* for the key.
|
* for the key.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
final Entry<K,V> getEntry(Object key) {
|
final Entry<K,V> getEntry(Object key) {
|
||||||
int hash = (key == null) ? 0 : hash(key.hashCode());
|
int hash = (key == null) ? 0 : hash(key.hashCode());
|
||||||
for (Entry<K,V> e = table[indexFor(hash, table.length)];
|
for (Entry<?,?> e = table[indexFor(hash, table.length)];
|
||||||
e != null;
|
e != null;
|
||||||
e = e.next) {
|
e = e.next) {
|
||||||
Object k;
|
Object k;
|
||||||
if (e.hash == hash &&
|
if (e.hash == hash &&
|
||||||
((k = e.key) == key || (key != null && key.equals(k))))
|
((k = e.key) == key || (key != null && key.equals(k))))
|
||||||
return e;
|
return (Entry<K,V>)e;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -388,7 +390,9 @@ public class HashMap<K,V>
|
|||||||
return putForNullKey(value);
|
return putForNullKey(value);
|
||||||
int hash = hash(key.hashCode());
|
int hash = hash(key.hashCode());
|
||||||
int i = indexFor(hash, table.length);
|
int i = indexFor(hash, table.length);
|
||||||
for (Entry<K,V> e = table[i]; e != null; e = e.next) {
|
@SuppressWarnings("unchecked")
|
||||||
|
Entry<K,V> e = (Entry<K,V>)table[i];
|
||||||
|
for(; e != null; e = e.next) {
|
||||||
Object k;
|
Object k;
|
||||||
if (e.hash == hash && ((k = e.key) == key || key.equals(k))) {
|
if (e.hash == hash && ((k = e.key) == key || key.equals(k))) {
|
||||||
V oldValue = e.value;
|
V oldValue = e.value;
|
||||||
@ -407,7 +411,9 @@ public class HashMap<K,V>
|
|||||||
* Offloaded version of put for null keys
|
* Offloaded version of put for null keys
|
||||||
*/
|
*/
|
||||||
private V putForNullKey(V value) {
|
private V putForNullKey(V value) {
|
||||||
for (Entry<K,V> e = table[0]; e != null; e = e.next) {
|
@SuppressWarnings("unchecked")
|
||||||
|
Entry<K,V> e = (Entry<K,V>)table[0];
|
||||||
|
for(; e != null; e = e.next) {
|
||||||
if (e.key == null) {
|
if (e.key == null) {
|
||||||
V oldValue = e.value;
|
V oldValue = e.value;
|
||||||
e.value = value;
|
e.value = value;
|
||||||
@ -435,7 +441,8 @@ public class HashMap<K,V>
|
|||||||
* clone or deserialize. It will only happen for construction if the
|
* clone or deserialize. It will only happen for construction if the
|
||||||
* input Map is a sorted map whose ordering is inconsistent w/ equals.
|
* input Map is a sorted map whose ordering is inconsistent w/ equals.
|
||||||
*/
|
*/
|
||||||
for (Entry<K,V> e = table[i]; e != null; e = e.next) {
|
for (@SuppressWarnings("unchecked")
|
||||||
|
Entry<?,V> e = (Entry<?,V>)table[i]; e != null; e = e.next) {
|
||||||
Object k;
|
Object k;
|
||||||
if (e.hash == hash &&
|
if (e.hash == hash &&
|
||||||
((k = e.key) == key || (key != null && key.equals(k)))) {
|
((k = e.key) == key || (key != null && key.equals(k)))) {
|
||||||
@ -467,14 +474,14 @@ public class HashMap<K,V>
|
|||||||
* is irrelevant).
|
* is irrelevant).
|
||||||
*/
|
*/
|
||||||
void resize(int newCapacity) {
|
void resize(int newCapacity) {
|
||||||
Entry[] oldTable = table;
|
Entry<?,?>[] oldTable = table;
|
||||||
int oldCapacity = oldTable.length;
|
int oldCapacity = oldTable.length;
|
||||||
if (oldCapacity == MAXIMUM_CAPACITY) {
|
if (oldCapacity == MAXIMUM_CAPACITY) {
|
||||||
threshold = Integer.MAX_VALUE;
|
threshold = Integer.MAX_VALUE;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Entry[] newTable = new Entry[newCapacity];
|
Entry<?,?>[] newTable = new Entry<?,?>[newCapacity];
|
||||||
transfer(newTable);
|
transfer(newTable);
|
||||||
table = newTable;
|
table = newTable;
|
||||||
threshold = (int)(newCapacity * loadFactor);
|
threshold = (int)(newCapacity * loadFactor);
|
||||||
@ -483,17 +490,18 @@ public class HashMap<K,V>
|
|||||||
/**
|
/**
|
||||||
* Transfers all entries from current table to newTable.
|
* Transfers all entries from current table to newTable.
|
||||||
*/
|
*/
|
||||||
void transfer(Entry[] newTable) {
|
@SuppressWarnings("unchecked")
|
||||||
Entry[] src = table;
|
void transfer(Entry<?,?>[] newTable) {
|
||||||
|
Entry<?,?>[] src = table;
|
||||||
int newCapacity = newTable.length;
|
int newCapacity = newTable.length;
|
||||||
for (int j = 0; j < src.length; j++) {
|
for (int j = 0; j < src.length; j++) {
|
||||||
Entry<K,V> e = src[j];
|
Entry<K,V> e = (Entry<K,V>)src[j];
|
||||||
if (e != null) {
|
if (e != null) {
|
||||||
src[j] = null;
|
src[j] = null;
|
||||||
do {
|
do {
|
||||||
Entry<K,V> next = e.next;
|
Entry<K,V> next = e.next;
|
||||||
int i = indexFor(e.hash, newCapacity);
|
int i = indexFor(e.hash, newCapacity);
|
||||||
e.next = newTable[i];
|
e.next = (Entry<K,V>)newTable[i];
|
||||||
newTable[i] = e;
|
newTable[i] = e;
|
||||||
e = next;
|
e = next;
|
||||||
} while (e != null);
|
} while (e != null);
|
||||||
@ -560,7 +568,8 @@ public class HashMap<K,V>
|
|||||||
final Entry<K,V> removeEntryForKey(Object key) {
|
final Entry<K,V> removeEntryForKey(Object key) {
|
||||||
int hash = (key == null) ? 0 : hash(key.hashCode());
|
int hash = (key == null) ? 0 : hash(key.hashCode());
|
||||||
int i = indexFor(hash, table.length);
|
int i = indexFor(hash, table.length);
|
||||||
Entry<K,V> prev = table[i];
|
@SuppressWarnings("unchecked")
|
||||||
|
Entry<K,V> prev = (Entry<K,V>)table[i];
|
||||||
Entry<K,V> e = prev;
|
Entry<K,V> e = prev;
|
||||||
|
|
||||||
while (e != null) {
|
while (e != null) {
|
||||||
@ -591,11 +600,12 @@ public class HashMap<K,V>
|
|||||||
if (!(o instanceof Map.Entry))
|
if (!(o instanceof Map.Entry))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
Map.Entry<K,V> entry = (Map.Entry<K,V>) o;
|
Map.Entry<?,?> entry = (Map.Entry<?,?>) o;
|
||||||
Object key = entry.getKey();
|
Object key = entry.getKey();
|
||||||
int hash = (key == null) ? 0 : hash(key.hashCode());
|
int hash = (key == null) ? 0 : hash(key.hashCode());
|
||||||
int i = indexFor(hash, table.length);
|
int i = indexFor(hash, table.length);
|
||||||
Entry<K,V> prev = table[i];
|
@SuppressWarnings("unchecked")
|
||||||
|
Entry<K,V> prev = (Entry<K,V>)table[i];
|
||||||
Entry<K,V> e = prev;
|
Entry<K,V> e = prev;
|
||||||
|
|
||||||
while (e != null) {
|
while (e != null) {
|
||||||
@ -623,7 +633,7 @@ public class HashMap<K,V>
|
|||||||
*/
|
*/
|
||||||
public void clear() {
|
public void clear() {
|
||||||
modCount++;
|
modCount++;
|
||||||
Entry[] tab = table;
|
Entry<?,?>[] tab = table;
|
||||||
for (int i = 0; i < tab.length; i++)
|
for (int i = 0; i < tab.length; i++)
|
||||||
tab[i] = null;
|
tab[i] = null;
|
||||||
size = 0;
|
size = 0;
|
||||||
@ -641,9 +651,9 @@ public class HashMap<K,V>
|
|||||||
if (value == null)
|
if (value == null)
|
||||||
return containsNullValue();
|
return containsNullValue();
|
||||||
|
|
||||||
Entry[] tab = table;
|
Entry<?,?>[] tab = table;
|
||||||
for (int i = 0; i < tab.length ; i++)
|
for (int i = 0; i < tab.length ; i++)
|
||||||
for (Entry e = tab[i] ; e != null ; e = e.next)
|
for (Entry<?,?> e = tab[i] ; e != null ; e = e.next)
|
||||||
if (value.equals(e.value))
|
if (value.equals(e.value))
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
@ -653,9 +663,9 @@ public class HashMap<K,V>
|
|||||||
* Special-case code for containsValue with null argument
|
* Special-case code for containsValue with null argument
|
||||||
*/
|
*/
|
||||||
private boolean containsNullValue() {
|
private boolean containsNullValue() {
|
||||||
Entry[] tab = table;
|
Entry<?,?>[] tab = table;
|
||||||
for (int i = 0; i < tab.length ; i++)
|
for (int i = 0; i < tab.length ; i++)
|
||||||
for (Entry e = tab[i] ; e != null ; e = e.next)
|
for (Entry<?,?> e = tab[i] ; e != null ; e = e.next)
|
||||||
if (e.value == null)
|
if (e.value == null)
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
@ -667,6 +677,7 @@ public class HashMap<K,V>
|
|||||||
*
|
*
|
||||||
* @return a shallow copy of this map
|
* @return a shallow copy of this map
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public Object clone() {
|
public Object clone() {
|
||||||
HashMap<K,V> result = null;
|
HashMap<K,V> result = null;
|
||||||
try {
|
try {
|
||||||
@ -674,7 +685,7 @@ public class HashMap<K,V>
|
|||||||
} catch (CloneNotSupportedException e) {
|
} catch (CloneNotSupportedException e) {
|
||||||
// assert false;
|
// assert false;
|
||||||
}
|
}
|
||||||
result.table = new Entry[table.length];
|
result.table = new Entry<?,?>[table.length];
|
||||||
result.entrySet = null;
|
result.entrySet = null;
|
||||||
result.modCount = 0;
|
result.modCount = 0;
|
||||||
result.size = 0;
|
result.size = 0;
|
||||||
@ -717,7 +728,7 @@ public class HashMap<K,V>
|
|||||||
public final boolean equals(Object o) {
|
public final boolean equals(Object o) {
|
||||||
if (!(o instanceof Map.Entry))
|
if (!(o instanceof Map.Entry))
|
||||||
return false;
|
return false;
|
||||||
Map.Entry e = (Map.Entry)o;
|
Map.Entry<?,?> e = (Map.Entry<?,?>)o;
|
||||||
Object k1 = getKey();
|
Object k1 = getKey();
|
||||||
Object k2 = e.getKey();
|
Object k2 = e.getKey();
|
||||||
if (k1 == k2 || (k1 != null && k1.equals(k2))) {
|
if (k1 == k2 || (k1 != null && k1.equals(k2))) {
|
||||||
@ -762,7 +773,8 @@ public class HashMap<K,V>
|
|||||||
* Subclass overrides this to alter the behavior of put method.
|
* Subclass overrides this to alter the behavior of put method.
|
||||||
*/
|
*/
|
||||||
void addEntry(int hash, K key, V value, int bucketIndex) {
|
void addEntry(int hash, K key, V value, int bucketIndex) {
|
||||||
Entry<K,V> e = table[bucketIndex];
|
@SuppressWarnings("unchecked")
|
||||||
|
Entry<K,V> e = (Entry<K,V>)table[bucketIndex];
|
||||||
table[bucketIndex] = new Entry<>(hash, key, value, e);
|
table[bucketIndex] = new Entry<>(hash, key, value, e);
|
||||||
if (size++ >= threshold)
|
if (size++ >= threshold)
|
||||||
resize(2 * table.length);
|
resize(2 * table.length);
|
||||||
@ -777,21 +789,22 @@ public class HashMap<K,V>
|
|||||||
* clone, and readObject.
|
* clone, and readObject.
|
||||||
*/
|
*/
|
||||||
void createEntry(int hash, K key, V value, int bucketIndex) {
|
void createEntry(int hash, K key, V value, int bucketIndex) {
|
||||||
Entry<K,V> e = table[bucketIndex];
|
@SuppressWarnings("unchecked")
|
||||||
|
Entry<K,V> e = (Entry<K,V>)table[bucketIndex];
|
||||||
table[bucketIndex] = new Entry<>(hash, key, value, e);
|
table[bucketIndex] = new Entry<>(hash, key, value, e);
|
||||||
size++;
|
size++;
|
||||||
}
|
}
|
||||||
|
|
||||||
private abstract class HashIterator<E> implements Iterator<E> {
|
private abstract class HashIterator<E> implements Iterator<E> {
|
||||||
Entry<K,V> next; // next entry to return
|
Entry<?,?> next; // next entry to return
|
||||||
int expectedModCount; // For fast-fail
|
int expectedModCount; // For fast-fail
|
||||||
int index; // current slot
|
int index; // current slot
|
||||||
Entry<K,V> current; // current entry
|
Entry<?,?> current; // current entry
|
||||||
|
|
||||||
HashIterator() {
|
HashIterator() {
|
||||||
expectedModCount = modCount;
|
expectedModCount = modCount;
|
||||||
if (size > 0) { // advance to first entry
|
if (size > 0) { // advance to first entry
|
||||||
Entry[] t = table;
|
Entry<?,?>[] t = table;
|
||||||
while (index < t.length && (next = t[index++]) == null)
|
while (index < t.length && (next = t[index++]) == null)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
@ -801,20 +814,21 @@ public class HashMap<K,V>
|
|||||||
return next != null;
|
return next != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
final Entry<K,V> nextEntry() {
|
final Entry<K,V> nextEntry() {
|
||||||
if (modCount != expectedModCount)
|
if (modCount != expectedModCount)
|
||||||
throw new ConcurrentModificationException();
|
throw new ConcurrentModificationException();
|
||||||
Entry<K,V> e = next;
|
Entry<?,?> e = next;
|
||||||
if (e == null)
|
if (e == null)
|
||||||
throw new NoSuchElementException();
|
throw new NoSuchElementException();
|
||||||
|
|
||||||
if ((next = e.next) == null) {
|
if ((next = e.next) == null) {
|
||||||
Entry[] t = table;
|
Entry<?,?>[] t = table;
|
||||||
while (index < t.length && (next = t[index++]) == null)
|
while (index < t.length && (next = t[index++]) == null)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
current = e;
|
current = e;
|
||||||
return e;
|
return (Entry<K,V>)e;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove() {
|
public void remove() {
|
||||||
@ -965,7 +979,7 @@ public class HashMap<K,V>
|
|||||||
public boolean contains(Object o) {
|
public boolean contains(Object o) {
|
||||||
if (!(o instanceof Map.Entry))
|
if (!(o instanceof Map.Entry))
|
||||||
return false;
|
return false;
|
||||||
Map.Entry<K,V> e = (Map.Entry<K,V>) o;
|
Map.Entry<?,?> e = (Map.Entry<?,?>) o;
|
||||||
Entry<K,V> candidate = getEntry(e.getKey());
|
Entry<K,V> candidate = getEntry(e.getKey());
|
||||||
return candidate != null && candidate.equals(e);
|
return candidate != null && candidate.equals(e);
|
||||||
}
|
}
|
||||||
@ -1039,8 +1053,10 @@ public class HashMap<K,V>
|
|||||||
|
|
||||||
// Read the keys and values, and put the mappings in the HashMap
|
// Read the keys and values, and put the mappings in the HashMap
|
||||||
for (int i=0; i<size; i++) {
|
for (int i=0; i<size; i++) {
|
||||||
K key = (K) s.readObject();
|
@SuppressWarnings("unchecked")
|
||||||
V value = (V) s.readObject();
|
K key = (K) s.readObject();
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
V value = (V) s.readObject();
|
||||||
putForCreate(key, value);
|
putForCreate(key, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -247,6 +247,7 @@ public class HashSet<E>
|
|||||||
*
|
*
|
||||||
* @return a shallow copy of this set
|
* @return a shallow copy of this set
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public Object clone() {
|
public Object clone() {
|
||||||
try {
|
try {
|
||||||
HashSet<E> newSet = (HashSet<E>) super.clone();
|
HashSet<E> newSet = (HashSet<E>) super.clone();
|
||||||
@ -296,7 +297,7 @@ public class HashSet<E>
|
|||||||
// Read in HashMap capacity and load factor and create backing HashMap
|
// Read in HashMap capacity and load factor and create backing HashMap
|
||||||
int capacity = s.readInt();
|
int capacity = s.readInt();
|
||||||
float loadFactor = s.readFloat();
|
float loadFactor = s.readFloat();
|
||||||
map = (((HashSet)this) instanceof LinkedHashSet ?
|
map = (((HashSet<?>)this) instanceof LinkedHashSet ?
|
||||||
new LinkedHashMap<E,Object>(capacity, loadFactor) :
|
new LinkedHashMap<E,Object>(capacity, loadFactor) :
|
||||||
new HashMap<E,Object>(capacity, loadFactor));
|
new HashMap<E,Object>(capacity, loadFactor));
|
||||||
|
|
||||||
@ -305,7 +306,8 @@ public class HashSet<E>
|
|||||||
|
|
||||||
// Read in all elements in the proper order.
|
// Read in all elements in the proper order.
|
||||||
for (int i=0; i<size; i++) {
|
for (int i=0; i<size; i++) {
|
||||||
E e = (E) s.readObject();
|
@SuppressWarnings("unchecked")
|
||||||
|
E e = (E) s.readObject();
|
||||||
map.put(e, PRESENT);
|
map.put(e, PRESENT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -129,7 +129,7 @@ public class Hashtable<K,V>
|
|||||||
/**
|
/**
|
||||||
* The hash table data.
|
* The hash table data.
|
||||||
*/
|
*/
|
||||||
private transient Entry[] table;
|
private transient Entry<?,?>[] table;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The total number of entries in the hash table.
|
* The total number of entries in the hash table.
|
||||||
@ -182,7 +182,7 @@ public class Hashtable<K,V>
|
|||||||
if (initialCapacity==0)
|
if (initialCapacity==0)
|
||||||
initialCapacity = 1;
|
initialCapacity = 1;
|
||||||
this.loadFactor = loadFactor;
|
this.loadFactor = loadFactor;
|
||||||
table = new Entry[initialCapacity];
|
table = new Entry<?,?>[initialCapacity];
|
||||||
threshold = (int)(initialCapacity * loadFactor);
|
threshold = (int)(initialCapacity * loadFactor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -288,9 +288,9 @@ public class Hashtable<K,V>
|
|||||||
throw new NullPointerException();
|
throw new NullPointerException();
|
||||||
}
|
}
|
||||||
|
|
||||||
Entry tab[] = table;
|
Entry<?,?> tab[] = table;
|
||||||
for (int i = tab.length ; i-- > 0 ;) {
|
for (int i = tab.length ; i-- > 0 ;) {
|
||||||
for (Entry<K,V> e = tab[i] ; e != null ; e = e.next) {
|
for (Entry<?,?> e = tab[i] ; e != null ; e = e.next) {
|
||||||
if (e.value.equals(value)) {
|
if (e.value.equals(value)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -326,10 +326,10 @@ public class Hashtable<K,V>
|
|||||||
* @see #contains(Object)
|
* @see #contains(Object)
|
||||||
*/
|
*/
|
||||||
public synchronized boolean containsKey(Object key) {
|
public synchronized boolean containsKey(Object key) {
|
||||||
Entry tab[] = table;
|
Entry<?,?> tab[] = table;
|
||||||
int hash = key.hashCode();
|
int hash = key.hashCode();
|
||||||
int index = (hash & 0x7FFFFFFF) % tab.length;
|
int index = (hash & 0x7FFFFFFF) % tab.length;
|
||||||
for (Entry<K,V> e = tab[index] ; e != null ; e = e.next) {
|
for (Entry<?,?> e = tab[index] ; e != null ; e = e.next) {
|
||||||
if ((e.hash == hash) && e.key.equals(key)) {
|
if ((e.hash == hash) && e.key.equals(key)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -352,13 +352,14 @@ public class Hashtable<K,V>
|
|||||||
* @throws NullPointerException if the specified key is null
|
* @throws NullPointerException if the specified key is null
|
||||||
* @see #put(Object, Object)
|
* @see #put(Object, Object)
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public synchronized V get(Object key) {
|
public synchronized V get(Object key) {
|
||||||
Entry tab[] = table;
|
Entry<?,?> tab[] = table;
|
||||||
int hash = key.hashCode();
|
int hash = key.hashCode();
|
||||||
int index = (hash & 0x7FFFFFFF) % tab.length;
|
int index = (hash & 0x7FFFFFFF) % tab.length;
|
||||||
for (Entry<K,V> e = tab[index] ; e != null ; e = e.next) {
|
for (Entry<?,?> e = tab[index] ; e != null ; e = e.next) {
|
||||||
if ((e.hash == hash) && e.key.equals(key)) {
|
if ((e.hash == hash) && e.key.equals(key)) {
|
||||||
return e.value;
|
return (V)e.value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@ -379,9 +380,10 @@ public class Hashtable<K,V>
|
|||||||
* number of keys in the hashtable exceeds this hashtable's capacity
|
* number of keys in the hashtable exceeds this hashtable's capacity
|
||||||
* and load factor.
|
* and load factor.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
protected void rehash() {
|
protected void rehash() {
|
||||||
int oldCapacity = table.length;
|
int oldCapacity = table.length;
|
||||||
Entry[] oldMap = table;
|
Entry<?,?>[] oldMap = table;
|
||||||
|
|
||||||
// overflow-conscious code
|
// overflow-conscious code
|
||||||
int newCapacity = (oldCapacity << 1) + 1;
|
int newCapacity = (oldCapacity << 1) + 1;
|
||||||
@ -391,19 +393,19 @@ public class Hashtable<K,V>
|
|||||||
return;
|
return;
|
||||||
newCapacity = MAX_ARRAY_SIZE;
|
newCapacity = MAX_ARRAY_SIZE;
|
||||||
}
|
}
|
||||||
Entry[] newMap = new Entry[newCapacity];
|
Entry<?,?>[] newMap = new Entry<?,?>[newCapacity];
|
||||||
|
|
||||||
modCount++;
|
modCount++;
|
||||||
threshold = (int)(newCapacity * loadFactor);
|
threshold = (int)(newCapacity * loadFactor);
|
||||||
table = newMap;
|
table = newMap;
|
||||||
|
|
||||||
for (int i = oldCapacity ; i-- > 0 ;) {
|
for (int i = oldCapacity ; i-- > 0 ;) {
|
||||||
for (Entry<K,V> old = oldMap[i] ; old != null ; ) {
|
for (Entry<K,V> old = (Entry<K,V>)oldMap[i] ; old != null ; ) {
|
||||||
Entry<K,V> e = old;
|
Entry<K,V> e = old;
|
||||||
old = old.next;
|
old = old.next;
|
||||||
|
|
||||||
int index = (e.hash & 0x7FFFFFFF) % newCapacity;
|
int index = (e.hash & 0x7FFFFFFF) % newCapacity;
|
||||||
e.next = newMap[index];
|
e.next = (Entry<K,V>)newMap[index];
|
||||||
newMap[index] = e;
|
newMap[index] = e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -433,13 +435,15 @@ public class Hashtable<K,V>
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Makes sure the key is not already in the hashtable.
|
// Makes sure the key is not already in the hashtable.
|
||||||
Entry tab[] = table;
|
Entry<?,?> tab[] = table;
|
||||||
int hash = key.hashCode();
|
int hash = key.hashCode();
|
||||||
int index = (hash & 0x7FFFFFFF) % tab.length;
|
int index = (hash & 0x7FFFFFFF) % tab.length;
|
||||||
for (Entry<K,V> e = tab[index] ; e != null ; e = e.next) {
|
@SuppressWarnings("unchecked")
|
||||||
if ((e.hash == hash) && e.key.equals(key)) {
|
Entry<K,V> entry = (Entry<K,V>)tab[index];
|
||||||
V old = e.value;
|
for(; entry != null ; entry = entry.next) {
|
||||||
e.value = value;
|
if ((entry.hash == hash) && entry.key.equals(key)) {
|
||||||
|
V old = entry.value;
|
||||||
|
entry.value = value;
|
||||||
return old;
|
return old;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -454,7 +458,8 @@ public class Hashtable<K,V>
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Creates the new entry.
|
// Creates the new entry.
|
||||||
Entry<K,V> e = tab[index];
|
@SuppressWarnings("unchecked")
|
||||||
|
Entry<K,V> e = (Entry<K,V>)tab[index];
|
||||||
tab[index] = new Entry<>(hash, key, value, e);
|
tab[index] = new Entry<>(hash, key, value, e);
|
||||||
count++;
|
count++;
|
||||||
return null;
|
return null;
|
||||||
@ -470,10 +475,12 @@ public class Hashtable<K,V>
|
|||||||
* @throws NullPointerException if the key is <code>null</code>
|
* @throws NullPointerException if the key is <code>null</code>
|
||||||
*/
|
*/
|
||||||
public synchronized V remove(Object key) {
|
public synchronized V remove(Object key) {
|
||||||
Entry tab[] = table;
|
Entry<?,?> tab[] = table;
|
||||||
int hash = key.hashCode();
|
int hash = key.hashCode();
|
||||||
int index = (hash & 0x7FFFFFFF) % tab.length;
|
int index = (hash & 0x7FFFFFFF) % tab.length;
|
||||||
for (Entry<K,V> e = tab[index], prev = null ; e != null ; prev = e, e = e.next) {
|
@SuppressWarnings("unchecked")
|
||||||
|
Entry<K,V> e = (Entry<K,V>)tab[index];
|
||||||
|
for(Entry<K,V> prev = null ; e != null ; prev = e, e = e.next) {
|
||||||
if ((e.hash == hash) && e.key.equals(key)) {
|
if ((e.hash == hash) && e.key.equals(key)) {
|
||||||
modCount++;
|
modCount++;
|
||||||
if (prev != null) {
|
if (prev != null) {
|
||||||
@ -508,7 +515,7 @@ public class Hashtable<K,V>
|
|||||||
* Clears this hashtable so that it contains no keys.
|
* Clears this hashtable so that it contains no keys.
|
||||||
*/
|
*/
|
||||||
public synchronized void clear() {
|
public synchronized void clear() {
|
||||||
Entry tab[] = table;
|
Entry<?,?> tab[] = table;
|
||||||
modCount++;
|
modCount++;
|
||||||
for (int index = tab.length; --index >= 0; )
|
for (int index = tab.length; --index >= 0; )
|
||||||
tab[index] = null;
|
tab[index] = null;
|
||||||
@ -524,11 +531,11 @@ public class Hashtable<K,V>
|
|||||||
*/
|
*/
|
||||||
public synchronized Object clone() {
|
public synchronized Object clone() {
|
||||||
try {
|
try {
|
||||||
Hashtable<K,V> t = (Hashtable<K,V>) super.clone();
|
Hashtable<?,?> t = (Hashtable<?,?>)super.clone();
|
||||||
t.table = new Entry[table.length];
|
t.table = new Entry<?,?>[table.length];
|
||||||
for (int i = table.length ; i-- > 0 ; ) {
|
for (int i = table.length ; i-- > 0 ; ) {
|
||||||
t.table[i] = (table[i] != null)
|
t.table[i] = (table[i] != null)
|
||||||
? (Entry<K,V>) table[i].clone() : null;
|
? (Entry<?,?>) table[i].clone() : null;
|
||||||
}
|
}
|
||||||
t.keySet = null;
|
t.keySet = null;
|
||||||
t.entrySet = null;
|
t.entrySet = null;
|
||||||
@ -675,13 +682,13 @@ public class Hashtable<K,V>
|
|||||||
public boolean contains(Object o) {
|
public boolean contains(Object o) {
|
||||||
if (!(o instanceof Map.Entry))
|
if (!(o instanceof Map.Entry))
|
||||||
return false;
|
return false;
|
||||||
Map.Entry entry = (Map.Entry)o;
|
Map.Entry<?,?> entry = (Map.Entry<?,?>)o;
|
||||||
Object key = entry.getKey();
|
Object key = entry.getKey();
|
||||||
Entry[] tab = table;
|
Entry<?,?>[] tab = table;
|
||||||
int hash = key.hashCode();
|
int hash = key.hashCode();
|
||||||
int index = (hash & 0x7FFFFFFF) % tab.length;
|
int index = (hash & 0x7FFFFFFF) % tab.length;
|
||||||
|
|
||||||
for (Entry e = tab[index]; e != null; e = e.next)
|
for (Entry<?,?> e = tab[index]; e != null; e = e.next)
|
||||||
if (e.hash==hash && e.equals(entry))
|
if (e.hash==hash && e.equals(entry))
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
@ -690,14 +697,15 @@ public class Hashtable<K,V>
|
|||||||
public boolean remove(Object o) {
|
public boolean remove(Object o) {
|
||||||
if (!(o instanceof Map.Entry))
|
if (!(o instanceof Map.Entry))
|
||||||
return false;
|
return false;
|
||||||
Map.Entry<K,V> entry = (Map.Entry<K,V>) o;
|
Map.Entry<?,?> entry = (Map.Entry<?,?>) o;
|
||||||
K key = entry.getKey();
|
Object key = entry.getKey();
|
||||||
Entry[] tab = table;
|
Entry<?,?>[] tab = table;
|
||||||
int hash = key.hashCode();
|
int hash = key.hashCode();
|
||||||
int index = (hash & 0x7FFFFFFF) % tab.length;
|
int index = (hash & 0x7FFFFFFF) % tab.length;
|
||||||
|
|
||||||
for (Entry<K,V> e = tab[index], prev = null; e != null;
|
@SuppressWarnings("unchecked")
|
||||||
prev = e, e = e.next) {
|
Entry<K,V> e = (Entry<K,V>)tab[index];
|
||||||
|
for(Entry<K,V> prev = null; e != null; prev = e, e = e.next) {
|
||||||
if (e.hash==hash && e.equals(entry)) {
|
if (e.hash==hash && e.equals(entry)) {
|
||||||
modCount++;
|
modCount++;
|
||||||
if (prev != null)
|
if (prev != null)
|
||||||
@ -776,7 +784,7 @@ public class Hashtable<K,V>
|
|||||||
|
|
||||||
if (!(o instanceof Map))
|
if (!(o instanceof Map))
|
||||||
return false;
|
return false;
|
||||||
Map<K,V> t = (Map<K,V>) o;
|
Map<?,?> t = (Map<?,?>) o;
|
||||||
if (t.size() != size())
|
if (t.size() != size())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -826,9 +834,9 @@ public class Hashtable<K,V>
|
|||||||
return h; // Returns zero
|
return h; // Returns zero
|
||||||
|
|
||||||
loadFactor = -loadFactor; // Mark hashCode computation in progress
|
loadFactor = -loadFactor; // Mark hashCode computation in progress
|
||||||
Entry[] tab = table;
|
Entry<?,?>[] tab = table;
|
||||||
for (int i = 0; i < tab.length; i++)
|
for (int i = 0; i < tab.length; i++)
|
||||||
for (Entry e = tab[i]; e != null; e = e.next)
|
for (Entry<?,?> e = tab[i]; e != null; e = e.next)
|
||||||
h += e.key.hashCode() ^ e.value.hashCode();
|
h += e.key.hashCode() ^ e.value.hashCode();
|
||||||
loadFactor = -loadFactor; // Mark hashCode computation complete
|
loadFactor = -loadFactor; // Mark hashCode computation complete
|
||||||
|
|
||||||
@ -859,7 +867,7 @@ public class Hashtable<K,V>
|
|||||||
|
|
||||||
// Stack copies of the entries in the table
|
// Stack copies of the entries in the table
|
||||||
for (int index = 0; index < table.length; index++) {
|
for (int index = 0; index < table.length; index++) {
|
||||||
Entry entry = table[index];
|
Entry<?,?> entry = table[index];
|
||||||
|
|
||||||
while (entry != null) {
|
while (entry != null) {
|
||||||
entryStack =
|
entryStack =
|
||||||
@ -899,14 +907,15 @@ public class Hashtable<K,V>
|
|||||||
length--;
|
length--;
|
||||||
if (origlength > 0 && length > origlength)
|
if (origlength > 0 && length > origlength)
|
||||||
length = origlength;
|
length = origlength;
|
||||||
|
Entry<?,?>[] table = new Entry<?,?>[length];
|
||||||
Entry[] table = new Entry[length];
|
|
||||||
count = 0;
|
count = 0;
|
||||||
|
|
||||||
// Read the number of elements and then all the key/value objects
|
// Read the number of elements and then all the key/value objects
|
||||||
for (; elements > 0; elements--) {
|
for (; elements > 0; elements--) {
|
||||||
K key = (K)s.readObject();
|
@SuppressWarnings("unchecked")
|
||||||
V value = (V)s.readObject();
|
K key = (K)s.readObject();
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
V value = (V)s.readObject();
|
||||||
// synch could be eliminated for performance
|
// synch could be eliminated for performance
|
||||||
reconstitutionPut(table, key, value);
|
reconstitutionPut(table, key, value);
|
||||||
}
|
}
|
||||||
@ -924,7 +933,7 @@ public class Hashtable<K,V>
|
|||||||
* because we are creating a new instance. Also, no return value
|
* because we are creating a new instance. Also, no return value
|
||||||
* is needed.
|
* is needed.
|
||||||
*/
|
*/
|
||||||
private void reconstitutionPut(Entry[] tab, K key, V value)
|
private void reconstitutionPut(Entry<?,?>[] tab, K key, V value)
|
||||||
throws StreamCorruptedException
|
throws StreamCorruptedException
|
||||||
{
|
{
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
@ -934,13 +943,14 @@ public class Hashtable<K,V>
|
|||||||
// This should not happen in deserialized version.
|
// This should not happen in deserialized version.
|
||||||
int hash = key.hashCode();
|
int hash = key.hashCode();
|
||||||
int index = (hash & 0x7FFFFFFF) % tab.length;
|
int index = (hash & 0x7FFFFFFF) % tab.length;
|
||||||
for (Entry<K,V> e = tab[index] ; e != null ; e = e.next) {
|
for (Entry<?,?> e = tab[index] ; e != null ; e = e.next) {
|
||||||
if ((e.hash == hash) && e.key.equals(key)) {
|
if ((e.hash == hash) && e.key.equals(key)) {
|
||||||
throw new java.io.StreamCorruptedException();
|
throw new java.io.StreamCorruptedException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Creates the new entry.
|
// Creates the new entry.
|
||||||
Entry<K,V> e = tab[index];
|
@SuppressWarnings("unchecked")
|
||||||
|
Entry<K,V> e = (Entry<K,V>)tab[index];
|
||||||
tab[index] = new Entry<>(hash, key, value, e);
|
tab[index] = new Entry<>(hash, key, value, e);
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
@ -961,6 +971,7 @@ public class Hashtable<K,V>
|
|||||||
this.next = next;
|
this.next = next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
protected Object clone() {
|
protected Object clone() {
|
||||||
return new Entry<>(hash, key, value,
|
return new Entry<>(hash, key, value,
|
||||||
(next==null ? null : (Entry<K,V>) next.clone()));
|
(next==null ? null : (Entry<K,V>) next.clone()));
|
||||||
@ -988,7 +999,7 @@ public class Hashtable<K,V>
|
|||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (!(o instanceof Map.Entry))
|
if (!(o instanceof Map.Entry))
|
||||||
return false;
|
return false;
|
||||||
Map.Entry e = (Map.Entry)o;
|
Map.Entry<?,?> e = (Map.Entry<?,?>)o;
|
||||||
|
|
||||||
return (key==null ? e.getKey()==null : key.equals(e.getKey())) &&
|
return (key==null ? e.getKey()==null : key.equals(e.getKey())) &&
|
||||||
(value==null ? e.getValue()==null : value.equals(e.getValue()));
|
(value==null ? e.getValue()==null : value.equals(e.getValue()));
|
||||||
@ -1016,10 +1027,10 @@ public class Hashtable<K,V>
|
|||||||
* by passing an Enumeration.
|
* by passing an Enumeration.
|
||||||
*/
|
*/
|
||||||
private class Enumerator<T> implements Enumeration<T>, Iterator<T> {
|
private class Enumerator<T> implements Enumeration<T>, Iterator<T> {
|
||||||
Entry[] table = Hashtable.this.table;
|
Entry<?,?>[] table = Hashtable.this.table;
|
||||||
int index = table.length;
|
int index = table.length;
|
||||||
Entry<K,V> entry = null;
|
Entry<?,?> entry = null;
|
||||||
Entry<K,V> lastReturned = null;
|
Entry<?,?> lastReturned = null;
|
||||||
int type;
|
int type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1041,9 +1052,9 @@ public class Hashtable<K,V>
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasMoreElements() {
|
public boolean hasMoreElements() {
|
||||||
Entry<K,V> e = entry;
|
Entry<?,?> e = entry;
|
||||||
int i = index;
|
int i = index;
|
||||||
Entry[] t = table;
|
Entry<?,?>[] t = table;
|
||||||
/* Use locals for faster loop iteration */
|
/* Use locals for faster loop iteration */
|
||||||
while (e == null && i > 0) {
|
while (e == null && i > 0) {
|
||||||
e = t[--i];
|
e = t[--i];
|
||||||
@ -1053,10 +1064,11 @@ public class Hashtable<K,V>
|
|||||||
return e != null;
|
return e != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public T nextElement() {
|
public T nextElement() {
|
||||||
Entry<K,V> et = entry;
|
Entry<?,?> et = entry;
|
||||||
int i = index;
|
int i = index;
|
||||||
Entry[] t = table;
|
Entry<?,?>[] t = table;
|
||||||
/* Use locals for faster loop iteration */
|
/* Use locals for faster loop iteration */
|
||||||
while (et == null && i > 0) {
|
while (et == null && i > 0) {
|
||||||
et = t[--i];
|
et = t[--i];
|
||||||
@ -1064,7 +1076,7 @@ public class Hashtable<K,V>
|
|||||||
entry = et;
|
entry = et;
|
||||||
index = i;
|
index = i;
|
||||||
if (et != null) {
|
if (et != null) {
|
||||||
Entry<K,V> e = lastReturned = entry;
|
Entry<?,?> e = lastReturned = entry;
|
||||||
entry = e.next;
|
entry = e.next;
|
||||||
return type == KEYS ? (T)e.key : (type == VALUES ? (T)e.value : (T)e);
|
return type == KEYS ? (T)e.key : (type == VALUES ? (T)e.value : (T)e);
|
||||||
}
|
}
|
||||||
@ -1091,11 +1103,12 @@ public class Hashtable<K,V>
|
|||||||
throw new ConcurrentModificationException();
|
throw new ConcurrentModificationException();
|
||||||
|
|
||||||
synchronized(Hashtable.this) {
|
synchronized(Hashtable.this) {
|
||||||
Entry[] tab = Hashtable.this.table;
|
Entry<?,?>[] tab = Hashtable.this.table;
|
||||||
int index = (lastReturned.hash & 0x7FFFFFFF) % tab.length;
|
int index = (lastReturned.hash & 0x7FFFFFFF) % tab.length;
|
||||||
|
|
||||||
for (Entry<K,V> e = tab[index], prev = null; e != null;
|
@SuppressWarnings("unchecked")
|
||||||
prev = e, e = e.next) {
|
Entry<K,V> e = (Entry<K,V>)tab[index];
|
||||||
|
for(Entry<K,V> prev = null; e != null; prev = e, e = e.next) {
|
||||||
if (e == lastReturned) {
|
if (e == lastReturned) {
|
||||||
modCount++;
|
modCount++;
|
||||||
expectedModCount++;
|
expectedModCount++;
|
||||||
|
@ -327,6 +327,7 @@ public class IdentityHashMap<K,V>
|
|||||||
*
|
*
|
||||||
* @see #put(Object, Object)
|
* @see #put(Object, Object)
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public V get(Object key) {
|
public V get(Object key) {
|
||||||
Object k = maskNull(key);
|
Object k = maskNull(key);
|
||||||
Object[] tab = table;
|
Object[] tab = table;
|
||||||
@ -431,7 +432,8 @@ public class IdentityHashMap<K,V>
|
|||||||
Object item;
|
Object item;
|
||||||
while ( (item = tab[i]) != null) {
|
while ( (item = tab[i]) != null) {
|
||||||
if (item == k) {
|
if (item == k) {
|
||||||
V oldValue = (V) tab[i + 1];
|
@SuppressWarnings("unchecked")
|
||||||
|
V oldValue = (V) tab[i + 1];
|
||||||
tab[i + 1] = value;
|
tab[i + 1] = value;
|
||||||
return oldValue;
|
return oldValue;
|
||||||
}
|
}
|
||||||
@ -524,7 +526,8 @@ public class IdentityHashMap<K,V>
|
|||||||
if (item == k) {
|
if (item == k) {
|
||||||
modCount++;
|
modCount++;
|
||||||
size--;
|
size--;
|
||||||
V oldValue = (V) tab[i + 1];
|
@SuppressWarnings("unchecked")
|
||||||
|
V oldValue = (V) tab[i + 1];
|
||||||
tab[i + 1] = null;
|
tab[i + 1] = null;
|
||||||
tab[i] = null;
|
tab[i] = null;
|
||||||
closeDeletion(i);
|
closeDeletion(i);
|
||||||
@ -638,7 +641,7 @@ public class IdentityHashMap<K,V>
|
|||||||
if (o == this) {
|
if (o == this) {
|
||||||
return true;
|
return true;
|
||||||
} else if (o instanceof IdentityHashMap) {
|
} else if (o instanceof IdentityHashMap) {
|
||||||
IdentityHashMap m = (IdentityHashMap) o;
|
IdentityHashMap<?,?> m = (IdentityHashMap<?,?>) o;
|
||||||
if (m.size() != size)
|
if (m.size() != size)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -650,7 +653,7 @@ public class IdentityHashMap<K,V>
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else if (o instanceof Map) {
|
} else if (o instanceof Map) {
|
||||||
Map m = (Map)o;
|
Map<?,?> m = (Map<?,?>)o;
|
||||||
return entrySet().equals(m.entrySet());
|
return entrySet().equals(m.entrySet());
|
||||||
} else {
|
} else {
|
||||||
return false; // o is not a Map
|
return false; // o is not a Map
|
||||||
@ -698,7 +701,7 @@ public class IdentityHashMap<K,V>
|
|||||||
*/
|
*/
|
||||||
public Object clone() {
|
public Object clone() {
|
||||||
try {
|
try {
|
||||||
IdentityHashMap<K,V> m = (IdentityHashMap<K,V>) super.clone();
|
IdentityHashMap<?,?> m = (IdentityHashMap<?,?>) super.clone();
|
||||||
m.entrySet = null;
|
m.entrySet = null;
|
||||||
m.table = table.clone();
|
m.table = table.clone();
|
||||||
return m;
|
return m;
|
||||||
@ -768,7 +771,7 @@ public class IdentityHashMap<K,V>
|
|||||||
int len = tab.length;
|
int len = tab.length;
|
||||||
|
|
||||||
int d = deletedSlot;
|
int d = deletedSlot;
|
||||||
K key = (K) tab[d];
|
Object key = tab[d];
|
||||||
tab[d] = null; // vacate the slot
|
tab[d] = null; // vacate the slot
|
||||||
tab[d + 1] = null;
|
tab[d + 1] = null;
|
||||||
|
|
||||||
@ -818,12 +821,14 @@ public class IdentityHashMap<K,V>
|
|||||||
}
|
}
|
||||||
|
|
||||||
private class KeyIterator extends IdentityHashMapIterator<K> {
|
private class KeyIterator extends IdentityHashMapIterator<K> {
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public K next() {
|
public K next() {
|
||||||
return (K) unmaskNull(traversalTable[nextIndex()]);
|
return (K) unmaskNull(traversalTable[nextIndex()]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ValueIterator extends IdentityHashMapIterator<V> {
|
private class ValueIterator extends IdentityHashMapIterator<V> {
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public V next() {
|
public V next() {
|
||||||
return (V) traversalTable[nextIndex() + 1];
|
return (V) traversalTable[nextIndex() + 1];
|
||||||
}
|
}
|
||||||
@ -854,16 +859,19 @@ public class IdentityHashMap<K,V>
|
|||||||
this.index = index;
|
this.index = index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public K getKey() {
|
public K getKey() {
|
||||||
checkIndexForEntryUse();
|
checkIndexForEntryUse();
|
||||||
return (K) unmaskNull(traversalTable[index]);
|
return (K) unmaskNull(traversalTable[index]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public V getValue() {
|
public V getValue() {
|
||||||
checkIndexForEntryUse();
|
checkIndexForEntryUse();
|
||||||
return (V) traversalTable[index+1];
|
return (V) traversalTable[index+1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public V setValue(V value) {
|
public V setValue(V value) {
|
||||||
checkIndexForEntryUse();
|
checkIndexForEntryUse();
|
||||||
V oldValue = (V) traversalTable[index+1];
|
V oldValue = (V) traversalTable[index+1];
|
||||||
@ -880,7 +888,7 @@ public class IdentityHashMap<K,V>
|
|||||||
|
|
||||||
if (!(o instanceof Map.Entry))
|
if (!(o instanceof Map.Entry))
|
||||||
return false;
|
return false;
|
||||||
Map.Entry e = (Map.Entry)o;
|
Map.Entry<?,?> e = (Map.Entry<?,?>)o;
|
||||||
return (e.getKey() == unmaskNull(traversalTable[index]) &&
|
return (e.getKey() == unmaskNull(traversalTable[index]) &&
|
||||||
e.getValue() == traversalTable[index+1]);
|
e.getValue() == traversalTable[index+1]);
|
||||||
}
|
}
|
||||||
@ -1109,13 +1117,13 @@ public class IdentityHashMap<K,V>
|
|||||||
public boolean contains(Object o) {
|
public boolean contains(Object o) {
|
||||||
if (!(o instanceof Map.Entry))
|
if (!(o instanceof Map.Entry))
|
||||||
return false;
|
return false;
|
||||||
Map.Entry entry = (Map.Entry)o;
|
Map.Entry<?,?> entry = (Map.Entry<?,?>)o;
|
||||||
return containsMapping(entry.getKey(), entry.getValue());
|
return containsMapping(entry.getKey(), entry.getValue());
|
||||||
}
|
}
|
||||||
public boolean remove(Object o) {
|
public boolean remove(Object o) {
|
||||||
if (!(o instanceof Map.Entry))
|
if (!(o instanceof Map.Entry))
|
||||||
return false;
|
return false;
|
||||||
Map.Entry entry = (Map.Entry)o;
|
Map.Entry<?,?> entry = (Map.Entry<?,?>)o;
|
||||||
return removeMapping(entry.getKey(), entry.getValue());
|
return removeMapping(entry.getKey(), entry.getValue());
|
||||||
}
|
}
|
||||||
public int size() {
|
public int size() {
|
||||||
@ -1213,8 +1221,10 @@ public class IdentityHashMap<K,V>
|
|||||||
|
|
||||||
// Read the keys and values, and put the mappings in the table
|
// Read the keys and values, and put the mappings in the table
|
||||||
for (int i=0; i<size; i++) {
|
for (int i=0; i<size; i++) {
|
||||||
K key = (K) s.readObject();
|
@SuppressWarnings("unchecked")
|
||||||
V value = (V) s.readObject();
|
K key = (K) s.readObject();
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
V value = (V) s.readObject();
|
||||||
putForCreate(key, value);
|
putForCreate(key, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1226,7 +1236,7 @@ public class IdentityHashMap<K,V>
|
|||||||
private void putForCreate(K key, V value)
|
private void putForCreate(K key, V value)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
K k = (K)maskNull(key);
|
Object k = maskNull(key);
|
||||||
Object[] tab = table;
|
Object[] tab = table;
|
||||||
int len = tab.length;
|
int len = tab.length;
|
||||||
int i = hash(k, len);
|
int i = hash(k, len);
|
||||||
|
@ -40,7 +40,7 @@ public class IllegalFormatConversionException extends IllegalFormatException {
|
|||||||
private static final long serialVersionUID = 17000126L;
|
private static final long serialVersionUID = 17000126L;
|
||||||
|
|
||||||
private char c;
|
private char c;
|
||||||
private Class arg;
|
private Class<?> arg;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs an instance of this class with the mismatched conversion and
|
* Constructs an instance of this class with the mismatched conversion and
|
||||||
|
@ -46,7 +46,7 @@ class JumboEnumSet<E extends Enum<E>> extends EnumSet<E> {
|
|||||||
// Redundant - maintained for performance
|
// Redundant - maintained for performance
|
||||||
private int size = 0;
|
private int size = 0;
|
||||||
|
|
||||||
JumboEnumSet(Class<E>elementType, Enum[] universe) {
|
JumboEnumSet(Class<E>elementType, Enum<?>[] universe) {
|
||||||
super(elementType, universe);
|
super(elementType, universe);
|
||||||
elements = new long[(universe.length + 63) >>> 6];
|
elements = new long[(universe.length + 63) >>> 6];
|
||||||
}
|
}
|
||||||
@ -127,6 +127,7 @@ class JumboEnumSet<E extends Enum<E>> extends EnumSet<E> {
|
|||||||
return unseen != 0;
|
return unseen != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public E next() {
|
public E next() {
|
||||||
if (!hasNext())
|
if (!hasNext())
|
||||||
throw new NoSuchElementException();
|
throw new NoSuchElementException();
|
||||||
@ -176,11 +177,11 @@ class JumboEnumSet<E extends Enum<E>> extends EnumSet<E> {
|
|||||||
public boolean contains(Object e) {
|
public boolean contains(Object e) {
|
||||||
if (e == null)
|
if (e == null)
|
||||||
return false;
|
return false;
|
||||||
Class eClass = e.getClass();
|
Class<?> eClass = e.getClass();
|
||||||
if (eClass != elementType && eClass.getSuperclass() != elementType)
|
if (eClass != elementType && eClass.getSuperclass() != elementType)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
int eOrdinal = ((Enum)e).ordinal();
|
int eOrdinal = ((Enum<?>)e).ordinal();
|
||||||
return (elements[eOrdinal >>> 6] & (1L << eOrdinal)) != 0;
|
return (elements[eOrdinal >>> 6] & (1L << eOrdinal)) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -217,10 +218,10 @@ class JumboEnumSet<E extends Enum<E>> extends EnumSet<E> {
|
|||||||
public boolean remove(Object e) {
|
public boolean remove(Object e) {
|
||||||
if (e == null)
|
if (e == null)
|
||||||
return false;
|
return false;
|
||||||
Class eClass = e.getClass();
|
Class<?> eClass = e.getClass();
|
||||||
if (eClass != elementType && eClass.getSuperclass() != elementType)
|
if (eClass != elementType && eClass.getSuperclass() != elementType)
|
||||||
return false;
|
return false;
|
||||||
int eOrdinal = ((Enum)e).ordinal();
|
int eOrdinal = ((Enum<?>)e).ordinal();
|
||||||
int eWordNum = eOrdinal >>> 6;
|
int eWordNum = eOrdinal >>> 6;
|
||||||
|
|
||||||
long oldElements = elements[eWordNum];
|
long oldElements = elements[eWordNum];
|
||||||
@ -246,7 +247,7 @@ class JumboEnumSet<E extends Enum<E>> extends EnumSet<E> {
|
|||||||
if (!(c instanceof JumboEnumSet))
|
if (!(c instanceof JumboEnumSet))
|
||||||
return super.containsAll(c);
|
return super.containsAll(c);
|
||||||
|
|
||||||
JumboEnumSet es = (JumboEnumSet)c;
|
JumboEnumSet<?> es = (JumboEnumSet<?>)c;
|
||||||
if (es.elementType != elementType)
|
if (es.elementType != elementType)
|
||||||
return es.isEmpty();
|
return es.isEmpty();
|
||||||
|
|
||||||
@ -268,7 +269,7 @@ class JumboEnumSet<E extends Enum<E>> extends EnumSet<E> {
|
|||||||
if (!(c instanceof JumboEnumSet))
|
if (!(c instanceof JumboEnumSet))
|
||||||
return super.addAll(c);
|
return super.addAll(c);
|
||||||
|
|
||||||
JumboEnumSet es = (JumboEnumSet)c;
|
JumboEnumSet<?> es = (JumboEnumSet<?>)c;
|
||||||
if (es.elementType != elementType) {
|
if (es.elementType != elementType) {
|
||||||
if (es.isEmpty())
|
if (es.isEmpty())
|
||||||
return false;
|
return false;
|
||||||
@ -294,7 +295,7 @@ class JumboEnumSet<E extends Enum<E>> extends EnumSet<E> {
|
|||||||
if (!(c instanceof JumboEnumSet))
|
if (!(c instanceof JumboEnumSet))
|
||||||
return super.removeAll(c);
|
return super.removeAll(c);
|
||||||
|
|
||||||
JumboEnumSet es = (JumboEnumSet)c;
|
JumboEnumSet<?> es = (JumboEnumSet<?>)c;
|
||||||
if (es.elementType != elementType)
|
if (es.elementType != elementType)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -348,7 +349,7 @@ class JumboEnumSet<E extends Enum<E>> extends EnumSet<E> {
|
|||||||
if (!(o instanceof JumboEnumSet))
|
if (!(o instanceof JumboEnumSet))
|
||||||
return super.equals(o);
|
return super.equals(o);
|
||||||
|
|
||||||
JumboEnumSet es = (JumboEnumSet)o;
|
JumboEnumSet<?> es = (JumboEnumSet<?>)o;
|
||||||
if (es.elementType != elementType)
|
if (es.elementType != elementType)
|
||||||
return size == 0 && es.size == 0;
|
return size == 0 && es.size == 0;
|
||||||
|
|
||||||
|
@ -246,11 +246,12 @@ public class LinkedHashMap<K,V>
|
|||||||
* by superclass resize. It is overridden for performance, as it is
|
* by superclass resize. It is overridden for performance, as it is
|
||||||
* faster to iterate using our linked list.
|
* faster to iterate using our linked list.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
void transfer(HashMap.Entry[] newTable) {
|
void transfer(HashMap.Entry[] newTable) {
|
||||||
int newCapacity = newTable.length;
|
int newCapacity = newTable.length;
|
||||||
for (Entry<K,V> e = header.after; e != header; e = e.after) {
|
for (Entry<K,V> e = header.after; e != header; e = e.after) {
|
||||||
int index = indexFor(e.hash, newCapacity);
|
int index = indexFor(e.hash, newCapacity);
|
||||||
e.next = newTable[index];
|
e.next = (HashMap.Entry<K,V>)newTable[index];
|
||||||
newTable[index] = e;
|
newTable[index] = e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -267,11 +268,11 @@ public class LinkedHashMap<K,V>
|
|||||||
public boolean containsValue(Object value) {
|
public boolean containsValue(Object value) {
|
||||||
// Overridden to take advantage of faster iterator
|
// Overridden to take advantage of faster iterator
|
||||||
if (value==null) {
|
if (value==null) {
|
||||||
for (Entry e = header.after; e != header; e = e.after)
|
for (Entry<?,?> e = header.after; e != header; e = e.after)
|
||||||
if (e.value==null)
|
if (e.value==null)
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
for (Entry e = header.after; e != header; e = e.after)
|
for (Entry<?,?> e = header.after; e != header; e = e.after)
|
||||||
if (value.equals(e.value))
|
if (value.equals(e.value))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -437,7 +438,8 @@ public class LinkedHashMap<K,V>
|
|||||||
* table or remove the eldest entry.
|
* table or remove the eldest entry.
|
||||||
*/
|
*/
|
||||||
void createEntry(int hash, K key, V value, int bucketIndex) {
|
void createEntry(int hash, K key, V value, int bucketIndex) {
|
||||||
HashMap.Entry<K,V> old = table[bucketIndex];
|
@SuppressWarnings("unchecked")
|
||||||
|
HashMap.Entry<K,V> old = (HashMap.Entry<K,V>)table[bucketIndex];
|
||||||
Entry<K,V> e = new Entry<>(hash, key, value, old);
|
Entry<K,V> e = new Entry<>(hash, key, value, old);
|
||||||
table[bucketIndex] = e;
|
table[bucketIndex] = e;
|
||||||
e.addBefore(header);
|
e.addBefore(header);
|
||||||
|
@ -61,12 +61,12 @@ package java.util;
|
|||||||
*/
|
*/
|
||||||
public class Observable {
|
public class Observable {
|
||||||
private boolean changed = false;
|
private boolean changed = false;
|
||||||
private Vector obs;
|
private Vector<Observer> obs;
|
||||||
|
|
||||||
/** Construct an Observable with zero Observers. */
|
/** Construct an Observable with zero Observers. */
|
||||||
|
|
||||||
public Observable() {
|
public Observable() {
|
||||||
obs = new Vector();
|
obs = new Vector<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -449,6 +449,7 @@ public class PriorityQueue<E> extends AbstractQueue<E>
|
|||||||
* this queue
|
* this queue
|
||||||
* @throws NullPointerException if the specified array is null
|
* @throws NullPointerException if the specified array is null
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public <T> T[] toArray(T[] a) {
|
public <T> T[] toArray(T[] a) {
|
||||||
if (a.length < size)
|
if (a.length < size)
|
||||||
// Make a new array of a's runtime type, but my contents:
|
// Make a new array of a's runtime type, but my contents:
|
||||||
@ -514,6 +515,7 @@ public class PriorityQueue<E> extends AbstractQueue<E>
|
|||||||
(forgetMeNot != null && !forgetMeNot.isEmpty());
|
(forgetMeNot != null && !forgetMeNot.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public E next() {
|
public E next() {
|
||||||
if (expectedModCount != modCount)
|
if (expectedModCount != modCount)
|
||||||
throw new ConcurrentModificationException();
|
throw new ConcurrentModificationException();
|
||||||
@ -571,8 +573,10 @@ public class PriorityQueue<E> extends AbstractQueue<E>
|
|||||||
return null;
|
return null;
|
||||||
int s = --size;
|
int s = --size;
|
||||||
modCount++;
|
modCount++;
|
||||||
E result = (E) queue[0];
|
@SuppressWarnings("unchecked")
|
||||||
E x = (E) queue[s];
|
E result = (E) queue[0];
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
E x = (E) queue[s];
|
||||||
queue[s] = null;
|
queue[s] = null;
|
||||||
if (s != 0)
|
if (s != 0)
|
||||||
siftDown(0, x);
|
siftDown(0, x);
|
||||||
@ -598,7 +602,8 @@ public class PriorityQueue<E> extends AbstractQueue<E>
|
|||||||
if (s == i) // removed last element
|
if (s == i) // removed last element
|
||||||
queue[i] = null;
|
queue[i] = null;
|
||||||
else {
|
else {
|
||||||
E moved = (E) queue[s];
|
@SuppressWarnings("unchecked")
|
||||||
|
E moved = (E) queue[s];
|
||||||
queue[s] = null;
|
queue[s] = null;
|
||||||
siftDown(i, moved);
|
siftDown(i, moved);
|
||||||
if (queue[i] == moved) {
|
if (queue[i] == moved) {
|
||||||
@ -629,6 +634,7 @@ public class PriorityQueue<E> extends AbstractQueue<E>
|
|||||||
siftUpComparable(k, x);
|
siftUpComparable(k, x);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
private void siftUpComparable(int k, E x) {
|
private void siftUpComparable(int k, E x) {
|
||||||
Comparable<? super E> key = (Comparable<? super E>) x;
|
Comparable<? super E> key = (Comparable<? super E>) x;
|
||||||
while (k > 0) {
|
while (k > 0) {
|
||||||
@ -645,8 +651,9 @@ public class PriorityQueue<E> extends AbstractQueue<E>
|
|||||||
private void siftUpUsingComparator(int k, E x) {
|
private void siftUpUsingComparator(int k, E x) {
|
||||||
while (k > 0) {
|
while (k > 0) {
|
||||||
int parent = (k - 1) >>> 1;
|
int parent = (k - 1) >>> 1;
|
||||||
Object e = queue[parent];
|
@SuppressWarnings("unchecked")
|
||||||
if (comparator.compare(x, (E) e) >= 0)
|
E e = (E) queue[parent];
|
||||||
|
if (comparator.compare(x, e) >= 0)
|
||||||
break;
|
break;
|
||||||
queue[k] = e;
|
queue[k] = e;
|
||||||
k = parent;
|
k = parent;
|
||||||
@ -669,6 +676,7 @@ public class PriorityQueue<E> extends AbstractQueue<E>
|
|||||||
siftDownComparable(k, x);
|
siftDownComparable(k, x);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
private void siftDownComparable(int k, E x) {
|
private void siftDownComparable(int k, E x) {
|
||||||
Comparable<? super E> key = (Comparable<? super E>)x;
|
Comparable<? super E> key = (Comparable<? super E>)x;
|
||||||
int half = size >>> 1; // loop while a non-leaf
|
int half = size >>> 1; // loop while a non-leaf
|
||||||
@ -687,6 +695,7 @@ public class PriorityQueue<E> extends AbstractQueue<E>
|
|||||||
queue[k] = key;
|
queue[k] = key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
private void siftDownUsingComparator(int k, E x) {
|
private void siftDownUsingComparator(int k, E x) {
|
||||||
int half = size >>> 1;
|
int half = size >>> 1;
|
||||||
while (k < half) {
|
while (k < half) {
|
||||||
@ -708,6 +717,7 @@ public class PriorityQueue<E> extends AbstractQueue<E>
|
|||||||
* Establishes the heap invariant (described above) in the entire tree,
|
* Establishes the heap invariant (described above) in the entire tree,
|
||||||
* assuming nothing about the order of the elements prior to the call.
|
* assuming nothing about the order of the elements prior to the call.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
private void heapify() {
|
private void heapify() {
|
||||||
for (int i = (size >>> 1) - 1; i >= 0; i--)
|
for (int i = (size >>> 1) - 1; i >= 0; i--)
|
||||||
siftDown(i, (E) queue[i]);
|
siftDown(i, (E) queue[i]);
|
||||||
|
@ -824,7 +824,7 @@ class Properties extends Hashtable<Object,Object> {
|
|||||||
bw.write("#" + new Date().toString());
|
bw.write("#" + new Date().toString());
|
||||||
bw.newLine();
|
bw.newLine();
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
for (Enumeration e = keys(); e.hasMoreElements();) {
|
for (Enumeration<?> e = keys(); e.hasMoreElements();) {
|
||||||
String key = (String)e.nextElement();
|
String key = (String)e.nextElement();
|
||||||
String val = (String)get(key);
|
String val = (String)get(key);
|
||||||
key = saveConvert(key, true, escUnicode);
|
key = saveConvert(key, true, escUnicode);
|
||||||
@ -987,7 +987,7 @@ class Properties extends Hashtable<Object,Object> {
|
|||||||
* @see #stringPropertyNames
|
* @see #stringPropertyNames
|
||||||
*/
|
*/
|
||||||
public Enumeration<?> propertyNames() {
|
public Enumeration<?> propertyNames() {
|
||||||
Hashtable h = new Hashtable();
|
Hashtable<String,Object> h = new Hashtable<>();
|
||||||
enumerate(h);
|
enumerate(h);
|
||||||
return h.keys();
|
return h.keys();
|
||||||
}
|
}
|
||||||
@ -1026,10 +1026,10 @@ class Properties extends Hashtable<Object,Object> {
|
|||||||
*/
|
*/
|
||||||
public void list(PrintStream out) {
|
public void list(PrintStream out) {
|
||||||
out.println("-- listing properties --");
|
out.println("-- listing properties --");
|
||||||
Hashtable h = new Hashtable();
|
Hashtable<String,Object> h = new Hashtable<>();
|
||||||
enumerate(h);
|
enumerate(h);
|
||||||
for (Enumeration e = h.keys() ; e.hasMoreElements() ;) {
|
for (Enumeration<String> e = h.keys() ; e.hasMoreElements() ;) {
|
||||||
String key = (String)e.nextElement();
|
String key = e.nextElement();
|
||||||
String val = (String)h.get(key);
|
String val = (String)h.get(key);
|
||||||
if (val.length() > 40) {
|
if (val.length() > 40) {
|
||||||
val = val.substring(0, 37) + "...";
|
val = val.substring(0, 37) + "...";
|
||||||
@ -1054,10 +1054,10 @@ class Properties extends Hashtable<Object,Object> {
|
|||||||
*/
|
*/
|
||||||
public void list(PrintWriter out) {
|
public void list(PrintWriter out) {
|
||||||
out.println("-- listing properties --");
|
out.println("-- listing properties --");
|
||||||
Hashtable h = new Hashtable();
|
Hashtable<String,Object> h = new Hashtable<>();
|
||||||
enumerate(h);
|
enumerate(h);
|
||||||
for (Enumeration e = h.keys() ; e.hasMoreElements() ;) {
|
for (Enumeration<String> e = h.keys() ; e.hasMoreElements() ;) {
|
||||||
String key = (String)e.nextElement();
|
String key = e.nextElement();
|
||||||
String val = (String)h.get(key);
|
String val = (String)h.get(key);
|
||||||
if (val.length() > 40) {
|
if (val.length() > 40) {
|
||||||
val = val.substring(0, 37) + "...";
|
val = val.substring(0, 37) + "...";
|
||||||
@ -1072,11 +1072,11 @@ class Properties extends Hashtable<Object,Object> {
|
|||||||
* @throws ClassCastException if any of the property keys
|
* @throws ClassCastException if any of the property keys
|
||||||
* is not of String type.
|
* is not of String type.
|
||||||
*/
|
*/
|
||||||
private synchronized void enumerate(Hashtable h) {
|
private synchronized void enumerate(Hashtable<String,Object> h) {
|
||||||
if (defaults != null) {
|
if (defaults != null) {
|
||||||
defaults.enumerate(h);
|
defaults.enumerate(h);
|
||||||
}
|
}
|
||||||
for (Enumeration e = keys() ; e.hasMoreElements() ;) {
|
for (Enumeration<?> e = keys() ; e.hasMoreElements() ;) {
|
||||||
String key = (String)e.nextElement();
|
String key = (String)e.nextElement();
|
||||||
h.put(key, get(key));
|
h.put(key, get(key));
|
||||||
}
|
}
|
||||||
@ -1091,7 +1091,7 @@ class Properties extends Hashtable<Object,Object> {
|
|||||||
if (defaults != null) {
|
if (defaults != null) {
|
||||||
defaults.enumerateStringProperties(h);
|
defaults.enumerateStringProperties(h);
|
||||||
}
|
}
|
||||||
for (Enumeration e = keys() ; e.hasMoreElements() ;) {
|
for (Enumeration<?> e = keys() ; e.hasMoreElements() ;) {
|
||||||
Object k = e.nextElement();
|
Object k = e.nextElement();
|
||||||
Object v = get(k);
|
Object v = get(k);
|
||||||
if (k instanceof String && v instanceof String) {
|
if (k instanceof String && v instanceof String) {
|
||||||
|
@ -442,7 +442,7 @@ implements Serializable
|
|||||||
* Key is property name; value is PropertyPermission.
|
* Key is property name; value is PropertyPermission.
|
||||||
* Not serialized; see serialization section at end of class.
|
* Not serialized; see serialization section at end of class.
|
||||||
*/
|
*/
|
||||||
private transient Map<String, Permission> perms;
|
private transient Map<String, PropertyPermission> perms;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Boolean saying if "*" is in the collection.
|
* Boolean saying if "*" is in the collection.
|
||||||
@ -488,7 +488,7 @@ implements Serializable
|
|||||||
String propName = pp.getName();
|
String propName = pp.getName();
|
||||||
|
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
PropertyPermission existing = (PropertyPermission) perms.get(propName);
|
PropertyPermission existing = perms.get(propName);
|
||||||
|
|
||||||
if (existing != null) {
|
if (existing != null) {
|
||||||
int oldMask = existing.getMask();
|
int oldMask = existing.getMask();
|
||||||
@ -499,7 +499,7 @@ implements Serializable
|
|||||||
perms.put(propName, new PropertyPermission(propName, actions));
|
perms.put(propName, new PropertyPermission(propName, actions));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
perms.put(propName, permission);
|
perms.put(propName, pp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -533,7 +533,7 @@ implements Serializable
|
|||||||
// short circuit if the "*" Permission was added
|
// short circuit if the "*" Permission was added
|
||||||
if (all_allowed) {
|
if (all_allowed) {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
x = (PropertyPermission) perms.get("*");
|
x = perms.get("*");
|
||||||
}
|
}
|
||||||
if (x != null) {
|
if (x != null) {
|
||||||
effective |= x.getMask();
|
effective |= x.getMask();
|
||||||
@ -550,7 +550,7 @@ implements Serializable
|
|||||||
//System.out.println("check "+name);
|
//System.out.println("check "+name);
|
||||||
|
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
x = (PropertyPermission) perms.get(name);
|
x = perms.get(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (x != null) {
|
if (x != null) {
|
||||||
@ -570,7 +570,7 @@ implements Serializable
|
|||||||
name = name.substring(0, last+1) + "*";
|
name = name.substring(0, last+1) + "*";
|
||||||
//System.out.println("check "+name);
|
//System.out.println("check "+name);
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
x = (PropertyPermission) perms.get(name);
|
x = perms.get(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (x != null) {
|
if (x != null) {
|
||||||
@ -592,11 +592,15 @@ implements Serializable
|
|||||||
*
|
*
|
||||||
* @return an enumeration of all the PropertyPermission objects.
|
* @return an enumeration of all the PropertyPermission objects.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public Enumeration<Permission> elements() {
|
public Enumeration<Permission> elements() {
|
||||||
// Convert Iterator of Map values into an Enumeration
|
// Convert Iterator of Map values into an Enumeration
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
return Collections.enumeration(perms.values());
|
/**
|
||||||
|
* Casting to rawtype since Enumeration<PropertyPermission>
|
||||||
|
* cannot be directly cast to Enumeration<Permission>
|
||||||
|
*/
|
||||||
|
return (Enumeration)Collections.enumeration(perms.values());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -633,7 +637,8 @@ implements Serializable
|
|||||||
// Don't call out.defaultWriteObject()
|
// Don't call out.defaultWriteObject()
|
||||||
|
|
||||||
// Copy perms into a Hashtable
|
// Copy perms into a Hashtable
|
||||||
Hashtable<String, Permission> permissions = new Hashtable<>(perms.size()*2);
|
Hashtable<String, Permission> permissions =
|
||||||
|
new Hashtable<>(perms.size()*2);
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
permissions.putAll(perms);
|
permissions.putAll(perms);
|
||||||
}
|
}
|
||||||
@ -661,8 +666,8 @@ implements Serializable
|
|||||||
|
|
||||||
// Get permissions
|
// Get permissions
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Hashtable<String, Permission> permissions =
|
Hashtable<String, PropertyPermission> permissions =
|
||||||
(Hashtable<String, Permission>)gfields.get("permissions", null);
|
(Hashtable<String, PropertyPermission>)gfields.get("permissions", null);
|
||||||
perms = new HashMap<>(permissions.size()*2);
|
perms = new HashMap<>(permissions.size()*2);
|
||||||
perms.putAll(permissions);
|
perms.putAll(permissions);
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ class RegularEnumSet<E extends Enum<E>> extends EnumSet<E> {
|
|||||||
*/
|
*/
|
||||||
private long elements = 0L;
|
private long elements = 0L;
|
||||||
|
|
||||||
RegularEnumSet(Class<E>elementType, Enum[] universe) {
|
RegularEnumSet(Class<E>elementType, Enum<?>[] universe) {
|
||||||
super(elementType, universe);
|
super(elementType, universe);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,6 +96,7 @@ class RegularEnumSet<E extends Enum<E>> extends EnumSet<E> {
|
|||||||
return unseen != 0;
|
return unseen != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public E next() {
|
public E next() {
|
||||||
if (unseen == 0)
|
if (unseen == 0)
|
||||||
throw new NoSuchElementException();
|
throw new NoSuchElementException();
|
||||||
@ -139,11 +140,11 @@ class RegularEnumSet<E extends Enum<E>> extends EnumSet<E> {
|
|||||||
public boolean contains(Object e) {
|
public boolean contains(Object e) {
|
||||||
if (e == null)
|
if (e == null)
|
||||||
return false;
|
return false;
|
||||||
Class eClass = e.getClass();
|
Class<?> eClass = e.getClass();
|
||||||
if (eClass != elementType && eClass.getSuperclass() != elementType)
|
if (eClass != elementType && eClass.getSuperclass() != elementType)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return (elements & (1L << ((Enum)e).ordinal())) != 0;
|
return (elements & (1L << ((Enum<?>)e).ordinal())) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Modification Operations
|
// Modification Operations
|
||||||
@ -160,7 +161,7 @@ class RegularEnumSet<E extends Enum<E>> extends EnumSet<E> {
|
|||||||
typeCheck(e);
|
typeCheck(e);
|
||||||
|
|
||||||
long oldElements = elements;
|
long oldElements = elements;
|
||||||
elements |= (1L << ((Enum)e).ordinal());
|
elements |= (1L << ((Enum<?>)e).ordinal());
|
||||||
return elements != oldElements;
|
return elements != oldElements;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,12 +174,12 @@ class RegularEnumSet<E extends Enum<E>> extends EnumSet<E> {
|
|||||||
public boolean remove(Object e) {
|
public boolean remove(Object e) {
|
||||||
if (e == null)
|
if (e == null)
|
||||||
return false;
|
return false;
|
||||||
Class eClass = e.getClass();
|
Class<?> eClass = e.getClass();
|
||||||
if (eClass != elementType && eClass.getSuperclass() != elementType)
|
if (eClass != elementType && eClass.getSuperclass() != elementType)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
long oldElements = elements;
|
long oldElements = elements;
|
||||||
elements &= ~(1L << ((Enum)e).ordinal());
|
elements &= ~(1L << ((Enum<?>)e).ordinal());
|
||||||
return elements != oldElements;
|
return elements != oldElements;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,7 +198,7 @@ class RegularEnumSet<E extends Enum<E>> extends EnumSet<E> {
|
|||||||
if (!(c instanceof RegularEnumSet))
|
if (!(c instanceof RegularEnumSet))
|
||||||
return super.containsAll(c);
|
return super.containsAll(c);
|
||||||
|
|
||||||
RegularEnumSet es = (RegularEnumSet)c;
|
RegularEnumSet<?> es = (RegularEnumSet<?>)c;
|
||||||
if (es.elementType != elementType)
|
if (es.elementType != elementType)
|
||||||
return es.isEmpty();
|
return es.isEmpty();
|
||||||
|
|
||||||
@ -216,7 +217,7 @@ class RegularEnumSet<E extends Enum<E>> extends EnumSet<E> {
|
|||||||
if (!(c instanceof RegularEnumSet))
|
if (!(c instanceof RegularEnumSet))
|
||||||
return super.addAll(c);
|
return super.addAll(c);
|
||||||
|
|
||||||
RegularEnumSet es = (RegularEnumSet)c;
|
RegularEnumSet<?> es = (RegularEnumSet<?>)c;
|
||||||
if (es.elementType != elementType) {
|
if (es.elementType != elementType) {
|
||||||
if (es.isEmpty())
|
if (es.isEmpty())
|
||||||
return false;
|
return false;
|
||||||
@ -242,7 +243,7 @@ class RegularEnumSet<E extends Enum<E>> extends EnumSet<E> {
|
|||||||
if (!(c instanceof RegularEnumSet))
|
if (!(c instanceof RegularEnumSet))
|
||||||
return super.removeAll(c);
|
return super.removeAll(c);
|
||||||
|
|
||||||
RegularEnumSet es = (RegularEnumSet)c;
|
RegularEnumSet<?> es = (RegularEnumSet<?>)c;
|
||||||
if (es.elementType != elementType)
|
if (es.elementType != elementType)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -295,7 +296,7 @@ class RegularEnumSet<E extends Enum<E>> extends EnumSet<E> {
|
|||||||
if (!(o instanceof RegularEnumSet))
|
if (!(o instanceof RegularEnumSet))
|
||||||
return super.equals(o);
|
return super.equals(o);
|
||||||
|
|
||||||
RegularEnumSet es = (RegularEnumSet)o;
|
RegularEnumSet<?> es = (RegularEnumSet<?>)o;
|
||||||
if (es.elementType != elementType)
|
if (es.elementType != elementType)
|
||||||
return elements == 0 && es.elements == 0;
|
return elements == 0 && es.elements == 0;
|
||||||
return es.elements == elements;
|
return es.elements == elements;
|
||||||
|
@ -294,7 +294,8 @@ public abstract class ResourceBundle {
|
|||||||
/**
|
/**
|
||||||
* Queue for reference objects referring to class loaders or bundles.
|
* Queue for reference objects referring to class loaders or bundles.
|
||||||
*/
|
*/
|
||||||
private static final ReferenceQueue<Object> referenceQueue = new ReferenceQueue<>();
|
private static final ReferenceQueue<Object> referenceQueue =
|
||||||
|
new ReferenceQueue<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The parent bundle of this bundle.
|
* The parent bundle of this bundle.
|
||||||
@ -417,7 +418,7 @@ public abstract class ResourceBundle {
|
|||||||
* caller's caller.
|
* caller's caller.
|
||||||
*/
|
*/
|
||||||
private static ClassLoader getLoader() {
|
private static ClassLoader getLoader() {
|
||||||
Class[] stack = getClassContext();
|
Class<?>[] stack = getClassContext();
|
||||||
/* Magic number 2 identifies our caller's caller */
|
/* Magic number 2 identifies our caller's caller */
|
||||||
Class<?> c = stack[2];
|
Class<?> c = stack[2];
|
||||||
ClassLoader cl = (c == null) ? null : c.getClassLoader();
|
ClassLoader cl = (c == null) ? null : c.getClassLoader();
|
||||||
@ -434,7 +435,7 @@ public abstract class ResourceBundle {
|
|||||||
return cl;
|
return cl;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static native Class[] getClassContext();
|
private static native Class<?>[] getClassContext();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A wrapper of ClassLoader.getSystemClassLoader().
|
* A wrapper of ClassLoader.getSystemClassLoader().
|
||||||
|
@ -218,20 +218,20 @@ public final class ServiceLoader<S>
|
|||||||
reload();
|
reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void fail(Class service, String msg, Throwable cause)
|
private static void fail(Class<?> service, String msg, Throwable cause)
|
||||||
throws ServiceConfigurationError
|
throws ServiceConfigurationError
|
||||||
{
|
{
|
||||||
throw new ServiceConfigurationError(service.getName() + ": " + msg,
|
throw new ServiceConfigurationError(service.getName() + ": " + msg,
|
||||||
cause);
|
cause);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void fail(Class service, String msg)
|
private static void fail(Class<?> service, String msg)
|
||||||
throws ServiceConfigurationError
|
throws ServiceConfigurationError
|
||||||
{
|
{
|
||||||
throw new ServiceConfigurationError(service.getName() + ": " + msg);
|
throw new ServiceConfigurationError(service.getName() + ": " + msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void fail(Class service, URL u, int line, String msg)
|
private static void fail(Class<?> service, URL u, int line, String msg)
|
||||||
throws ServiceConfigurationError
|
throws ServiceConfigurationError
|
||||||
{
|
{
|
||||||
fail(service, u + ":" + line + ": " + msg);
|
fail(service, u + ":" + line + ": " + msg);
|
||||||
@ -240,7 +240,7 @@ public final class ServiceLoader<S>
|
|||||||
// Parse a single line from the given configuration file, adding the name
|
// Parse a single line from the given configuration file, adding the name
|
||||||
// on the line to the names list.
|
// on the line to the names list.
|
||||||
//
|
//
|
||||||
private int parseLine(Class service, URL u, BufferedReader r, int lc,
|
private int parseLine(Class<?> service, URL u, BufferedReader r, int lc,
|
||||||
List<String> names)
|
List<String> names)
|
||||||
throws IOException, ServiceConfigurationError
|
throws IOException, ServiceConfigurationError
|
||||||
{
|
{
|
||||||
@ -286,7 +286,7 @@ public final class ServiceLoader<S>
|
|||||||
// If an I/O error occurs while reading from the given URL, or
|
// If an I/O error occurs while reading from the given URL, or
|
||||||
// if a configuration-file format error is detected
|
// if a configuration-file format error is detected
|
||||||
//
|
//
|
||||||
private Iterator<String> parse(Class service, URL u)
|
private Iterator<String> parse(Class<?> service, URL u)
|
||||||
throws ServiceConfigurationError
|
throws ServiceConfigurationError
|
||||||
{
|
{
|
||||||
InputStream in = null;
|
InputStream in = null;
|
||||||
|
@ -428,7 +428,7 @@ abstract public class TimeZone implements Serializable, Cloneable {
|
|||||||
// The structure is:
|
// The structure is:
|
||||||
// Map(key=id, value=SoftReference(Map(key=locale, value=displaynames)))
|
// Map(key=id, value=SoftReference(Map(key=locale, value=displaynames)))
|
||||||
private static final Map<String, SoftReference<Map<Locale, String[]>>> CACHE =
|
private static final Map<String, SoftReference<Map<Locale, String[]>>> CACHE =
|
||||||
new ConcurrentHashMap<String, SoftReference<Map<Locale, String[]>>>();
|
new ConcurrentHashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String[] getDisplayNames(String id, Locale locale) {
|
private static final String[] getDisplayNames(String id, Locale locale) {
|
||||||
@ -452,9 +452,9 @@ abstract public class TimeZone implements Serializable, Cloneable {
|
|||||||
|
|
||||||
String[] names = TimeZoneNameUtility.retrieveDisplayNames(id, locale);
|
String[] names = TimeZoneNameUtility.retrieveDisplayNames(id, locale);
|
||||||
if (names != null) {
|
if (names != null) {
|
||||||
Map<Locale, String[]> perLocale = new ConcurrentHashMap<Locale, String[]>();
|
Map<Locale, String[]> perLocale = new ConcurrentHashMap<>();
|
||||||
perLocale.put(locale, names);
|
perLocale.put(locale, names);
|
||||||
ref = new SoftReference<Map<Locale, String[]>>(perLocale);
|
ref = new SoftReference<>(perLocale);
|
||||||
displayNames.put(id, ref);
|
displayNames.put(id, ref);
|
||||||
}
|
}
|
||||||
return names;
|
return names;
|
||||||
|
@ -307,7 +307,7 @@ public class TreeMap<K,V>
|
|||||||
public void putAll(Map<? extends K, ? extends V> map) {
|
public void putAll(Map<? extends K, ? extends V> map) {
|
||||||
int mapSize = map.size();
|
int mapSize = map.size();
|
||||||
if (size==0 && mapSize!=0 && map instanceof SortedMap) {
|
if (size==0 && mapSize!=0 && map instanceof SortedMap) {
|
||||||
Comparator c = ((SortedMap)map).comparator();
|
Comparator<?> c = ((SortedMap<?,?>)map).comparator();
|
||||||
if (c == comparator || (c != null && c.equals(comparator))) {
|
if (c == comparator || (c != null && c.equals(comparator))) {
|
||||||
++modCount;
|
++modCount;
|
||||||
try {
|
try {
|
||||||
@ -340,7 +340,8 @@ public class TreeMap<K,V>
|
|||||||
return getEntryUsingComparator(key);
|
return getEntryUsingComparator(key);
|
||||||
if (key == null)
|
if (key == null)
|
||||||
throw new NullPointerException();
|
throw new NullPointerException();
|
||||||
Comparable<? super K> k = (Comparable<? super K>) key;
|
@SuppressWarnings("unchecked")
|
||||||
|
Comparable<? super K> k = (Comparable<? super K>) key;
|
||||||
Entry<K,V> p = root;
|
Entry<K,V> p = root;
|
||||||
while (p != null) {
|
while (p != null) {
|
||||||
int cmp = k.compareTo(p.key);
|
int cmp = k.compareTo(p.key);
|
||||||
@ -361,7 +362,8 @@ public class TreeMap<K,V>
|
|||||||
* worthwhile here.)
|
* worthwhile here.)
|
||||||
*/
|
*/
|
||||||
final Entry<K,V> getEntryUsingComparator(Object key) {
|
final Entry<K,V> getEntryUsingComparator(Object key) {
|
||||||
K k = (K) key;
|
@SuppressWarnings("unchecked")
|
||||||
|
K k = (K) key;
|
||||||
Comparator<? super K> cpr = comparator;
|
Comparator<? super K> cpr = comparator;
|
||||||
if (cpr != null) {
|
if (cpr != null) {
|
||||||
Entry<K,V> p = root;
|
Entry<K,V> p = root;
|
||||||
@ -554,7 +556,8 @@ public class TreeMap<K,V>
|
|||||||
else {
|
else {
|
||||||
if (key == null)
|
if (key == null)
|
||||||
throw new NullPointerException();
|
throw new NullPointerException();
|
||||||
Comparable<? super K> k = (Comparable<? super K>) key;
|
@SuppressWarnings("unchecked")
|
||||||
|
Comparable<? super K> k = (Comparable<? super K>) key;
|
||||||
do {
|
do {
|
||||||
parent = t;
|
parent = t;
|
||||||
cmp = k.compareTo(t.key);
|
cmp = k.compareTo(t.key);
|
||||||
@ -618,9 +621,9 @@ public class TreeMap<K,V>
|
|||||||
* @return a shallow copy of this map
|
* @return a shallow copy of this map
|
||||||
*/
|
*/
|
||||||
public Object clone() {
|
public Object clone() {
|
||||||
TreeMap<K,V> clone = null;
|
TreeMap<?,?> clone;
|
||||||
try {
|
try {
|
||||||
clone = (TreeMap<K,V>) super.clone();
|
clone = (TreeMap<?,?>) super.clone();
|
||||||
} catch (CloneNotSupportedException e) {
|
} catch (CloneNotSupportedException e) {
|
||||||
throw new InternalError(e);
|
throw new InternalError(e);
|
||||||
}
|
}
|
||||||
@ -803,7 +806,7 @@ public class TreeMap<K,V>
|
|||||||
*/
|
*/
|
||||||
public NavigableSet<K> navigableKeySet() {
|
public NavigableSet<K> navigableKeySet() {
|
||||||
KeySet<K> nks = navigableKeySet;
|
KeySet<K> nks = navigableKeySet;
|
||||||
return (nks != null) ? nks : (navigableKeySet = new KeySet(this));
|
return (nks != null) ? nks : (navigableKeySet = new KeySet<>(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -859,9 +862,9 @@ public class TreeMap<K,V>
|
|||||||
public NavigableMap<K, V> descendingMap() {
|
public NavigableMap<K, V> descendingMap() {
|
||||||
NavigableMap<K, V> km = descendingMap;
|
NavigableMap<K, V> km = descendingMap;
|
||||||
return (km != null) ? km :
|
return (km != null) ? km :
|
||||||
(descendingMap = new DescendingSubMap(this,
|
(descendingMap = new DescendingSubMap<>(this,
|
||||||
true, null, true,
|
true, null, true,
|
||||||
true, null, true));
|
true, null, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -874,9 +877,9 @@ public class TreeMap<K,V>
|
|||||||
*/
|
*/
|
||||||
public NavigableMap<K,V> subMap(K fromKey, boolean fromInclusive,
|
public NavigableMap<K,V> subMap(K fromKey, boolean fromInclusive,
|
||||||
K toKey, boolean toInclusive) {
|
K toKey, boolean toInclusive) {
|
||||||
return new AscendingSubMap(this,
|
return new AscendingSubMap<>(this,
|
||||||
false, fromKey, fromInclusive,
|
false, fromKey, fromInclusive,
|
||||||
false, toKey, toInclusive);
|
false, toKey, toInclusive);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -888,9 +891,9 @@ public class TreeMap<K,V>
|
|||||||
* @since 1.6
|
* @since 1.6
|
||||||
*/
|
*/
|
||||||
public NavigableMap<K,V> headMap(K toKey, boolean inclusive) {
|
public NavigableMap<K,V> headMap(K toKey, boolean inclusive) {
|
||||||
return new AscendingSubMap(this,
|
return new AscendingSubMap<>(this,
|
||||||
true, null, true,
|
true, null, true,
|
||||||
false, toKey, inclusive);
|
false, toKey, inclusive);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -902,9 +905,9 @@ public class TreeMap<K,V>
|
|||||||
* @since 1.6
|
* @since 1.6
|
||||||
*/
|
*/
|
||||||
public NavigableMap<K,V> tailMap(K fromKey, boolean inclusive) {
|
public NavigableMap<K,V> tailMap(K fromKey, boolean inclusive) {
|
||||||
return new AscendingSubMap(this,
|
return new AscendingSubMap<>(this,
|
||||||
false, fromKey, inclusive,
|
false, fromKey, inclusive,
|
||||||
true, null, true);
|
true, null, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -978,8 +981,8 @@ public class TreeMap<K,V>
|
|||||||
public boolean contains(Object o) {
|
public boolean contains(Object o) {
|
||||||
if (!(o instanceof Map.Entry))
|
if (!(o instanceof Map.Entry))
|
||||||
return false;
|
return false;
|
||||||
Map.Entry<K,V> entry = (Map.Entry<K,V>) o;
|
Map.Entry<?,?> entry = (Map.Entry<?,?>) o;
|
||||||
V value = entry.getValue();
|
Object value = entry.getValue();
|
||||||
Entry<K,V> p = getEntry(entry.getKey());
|
Entry<K,V> p = getEntry(entry.getKey());
|
||||||
return p != null && valEquals(p.getValue(), value);
|
return p != null && valEquals(p.getValue(), value);
|
||||||
}
|
}
|
||||||
@ -987,8 +990,8 @@ public class TreeMap<K,V>
|
|||||||
public boolean remove(Object o) {
|
public boolean remove(Object o) {
|
||||||
if (!(o instanceof Map.Entry))
|
if (!(o instanceof Map.Entry))
|
||||||
return false;
|
return false;
|
||||||
Map.Entry<K,V> entry = (Map.Entry<K,V>) o;
|
Map.Entry<?,?> entry = (Map.Entry<?,?>) o;
|
||||||
V value = entry.getValue();
|
Object value = entry.getValue();
|
||||||
Entry<K,V> p = getEntry(entry.getKey());
|
Entry<K,V> p = getEntry(entry.getKey());
|
||||||
if (p != null && valEquals(p.getValue(), value)) {
|
if (p != null && valEquals(p.getValue(), value)) {
|
||||||
deleteEntry(p);
|
deleteEntry(p);
|
||||||
@ -1023,21 +1026,21 @@ public class TreeMap<K,V>
|
|||||||
}
|
}
|
||||||
|
|
||||||
static final class KeySet<E> extends AbstractSet<E> implements NavigableSet<E> {
|
static final class KeySet<E> extends AbstractSet<E> implements NavigableSet<E> {
|
||||||
private final NavigableMap<E, Object> m;
|
private final NavigableMap<E, ?> m;
|
||||||
KeySet(NavigableMap<E,Object> map) { m = map; }
|
KeySet(NavigableMap<E,?> map) { m = map; }
|
||||||
|
|
||||||
public Iterator<E> iterator() {
|
public Iterator<E> iterator() {
|
||||||
if (m instanceof TreeMap)
|
if (m instanceof TreeMap)
|
||||||
return ((TreeMap<E,Object>)m).keyIterator();
|
return ((TreeMap<E,?>)m).keyIterator();
|
||||||
else
|
else
|
||||||
return (Iterator<E>)(((TreeMap.NavigableSubMap)m).keyIterator());
|
return ((TreeMap.NavigableSubMap<E,?>)m).keyIterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Iterator<E> descendingIterator() {
|
public Iterator<E> descendingIterator() {
|
||||||
if (m instanceof TreeMap)
|
if (m instanceof TreeMap)
|
||||||
return ((TreeMap<E,Object>)m).descendingKeyIterator();
|
return ((TreeMap<E,?>)m).descendingKeyIterator();
|
||||||
else
|
else
|
||||||
return (Iterator<E>)(((TreeMap.NavigableSubMap)m).descendingKeyIterator());
|
return ((TreeMap.NavigableSubMap<E,?>)m).descendingKeyIterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int size() { return m.size(); }
|
public int size() { return m.size(); }
|
||||||
@ -1052,11 +1055,11 @@ public class TreeMap<K,V>
|
|||||||
public E last() { return m.lastKey(); }
|
public E last() { return m.lastKey(); }
|
||||||
public Comparator<? super E> comparator() { return m.comparator(); }
|
public Comparator<? super E> comparator() { return m.comparator(); }
|
||||||
public E pollFirst() {
|
public E pollFirst() {
|
||||||
Map.Entry<E,Object> e = m.pollFirstEntry();
|
Map.Entry<E,?> e = m.pollFirstEntry();
|
||||||
return (e == null) ? null : e.getKey();
|
return (e == null) ? null : e.getKey();
|
||||||
}
|
}
|
||||||
public E pollLast() {
|
public E pollLast() {
|
||||||
Map.Entry<E,Object> e = m.pollLastEntry();
|
Map.Entry<E,?> e = m.pollLastEntry();
|
||||||
return (e == null) ? null : e.getKey();
|
return (e == null) ? null : e.getKey();
|
||||||
}
|
}
|
||||||
public boolean remove(Object o) {
|
public boolean remove(Object o) {
|
||||||
@ -1085,7 +1088,7 @@ public class TreeMap<K,V>
|
|||||||
return tailSet(fromElement, true);
|
return tailSet(fromElement, true);
|
||||||
}
|
}
|
||||||
public NavigableSet<E> descendingSet() {
|
public NavigableSet<E> descendingSet() {
|
||||||
return new KeySet(m.descendingMap());
|
return new KeySet<>(m.descendingMap());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1184,6 +1187,7 @@ public class TreeMap<K,V>
|
|||||||
/**
|
/**
|
||||||
* Compares two keys using the correct comparison method for this TreeMap.
|
* Compares two keys using the correct comparison method for this TreeMap.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
final int compare(Object k1, Object k2) {
|
final int compare(Object k1, Object k2) {
|
||||||
return comparator==null ? ((Comparable<? super K>)k1).compareTo((K)k2)
|
return comparator==null ? ((Comparable<? super K>)k1).compareTo((K)k2)
|
||||||
: comparator.compare((K)k1, (K)k2);
|
: comparator.compare((K)k1, (K)k2);
|
||||||
@ -1488,7 +1492,7 @@ public class TreeMap<K,V>
|
|||||||
public final NavigableSet<K> navigableKeySet() {
|
public final NavigableSet<K> navigableKeySet() {
|
||||||
KeySet<K> nksv = navigableKeySetView;
|
KeySet<K> nksv = navigableKeySetView;
|
||||||
return (nksv != null) ? nksv :
|
return (nksv != null) ? nksv :
|
||||||
(navigableKeySetView = new TreeMap.KeySet(this));
|
(navigableKeySetView = new TreeMap.KeySet<>(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
public final Set<K> keySet() {
|
public final Set<K> keySet() {
|
||||||
@ -1522,7 +1526,7 @@ public class TreeMap<K,V>
|
|||||||
if (size == -1 || sizeModCount != m.modCount) {
|
if (size == -1 || sizeModCount != m.modCount) {
|
||||||
sizeModCount = m.modCount;
|
sizeModCount = m.modCount;
|
||||||
size = 0;
|
size = 0;
|
||||||
Iterator i = iterator();
|
Iterator<?> i = iterator();
|
||||||
while (i.hasNext()) {
|
while (i.hasNext()) {
|
||||||
size++;
|
size++;
|
||||||
i.next();
|
i.next();
|
||||||
@ -1539,11 +1543,11 @@ public class TreeMap<K,V>
|
|||||||
public boolean contains(Object o) {
|
public boolean contains(Object o) {
|
||||||
if (!(o instanceof Map.Entry))
|
if (!(o instanceof Map.Entry))
|
||||||
return false;
|
return false;
|
||||||
Map.Entry<K,V> entry = (Map.Entry<K,V>) o;
|
Map.Entry<?,?> entry = (Map.Entry<?,?>) o;
|
||||||
K key = entry.getKey();
|
Object key = entry.getKey();
|
||||||
if (!inRange(key))
|
if (!inRange(key))
|
||||||
return false;
|
return false;
|
||||||
TreeMap.Entry node = m.getEntry(key);
|
TreeMap.Entry<?,?> node = m.getEntry(key);
|
||||||
return node != null &&
|
return node != null &&
|
||||||
valEquals(node.getValue(), entry.getValue());
|
valEquals(node.getValue(), entry.getValue());
|
||||||
}
|
}
|
||||||
@ -1551,8 +1555,8 @@ public class TreeMap<K,V>
|
|||||||
public boolean remove(Object o) {
|
public boolean remove(Object o) {
|
||||||
if (!(o instanceof Map.Entry))
|
if (!(o instanceof Map.Entry))
|
||||||
return false;
|
return false;
|
||||||
Map.Entry<K,V> entry = (Map.Entry<K,V>) o;
|
Map.Entry<?,?> entry = (Map.Entry<?,?>) o;
|
||||||
K key = entry.getKey();
|
Object key = entry.getKey();
|
||||||
if (!inRange(key))
|
if (!inRange(key))
|
||||||
return false;
|
return false;
|
||||||
TreeMap.Entry<K,V> node = m.getEntry(key);
|
TreeMap.Entry<K,V> node = m.getEntry(key);
|
||||||
@ -1709,34 +1713,34 @@ public class TreeMap<K,V>
|
|||||||
throw new IllegalArgumentException("fromKey out of range");
|
throw new IllegalArgumentException("fromKey out of range");
|
||||||
if (!inRange(toKey, toInclusive))
|
if (!inRange(toKey, toInclusive))
|
||||||
throw new IllegalArgumentException("toKey out of range");
|
throw new IllegalArgumentException("toKey out of range");
|
||||||
return new AscendingSubMap(m,
|
return new AscendingSubMap<>(m,
|
||||||
false, fromKey, fromInclusive,
|
false, fromKey, fromInclusive,
|
||||||
false, toKey, toInclusive);
|
false, toKey, toInclusive);
|
||||||
}
|
}
|
||||||
|
|
||||||
public NavigableMap<K,V> headMap(K toKey, boolean inclusive) {
|
public NavigableMap<K,V> headMap(K toKey, boolean inclusive) {
|
||||||
if (!inRange(toKey, inclusive))
|
if (!inRange(toKey, inclusive))
|
||||||
throw new IllegalArgumentException("toKey out of range");
|
throw new IllegalArgumentException("toKey out of range");
|
||||||
return new AscendingSubMap(m,
|
return new AscendingSubMap<>(m,
|
||||||
fromStart, lo, loInclusive,
|
fromStart, lo, loInclusive,
|
||||||
false, toKey, inclusive);
|
false, toKey, inclusive);
|
||||||
}
|
}
|
||||||
|
|
||||||
public NavigableMap<K,V> tailMap(K fromKey, boolean inclusive) {
|
public NavigableMap<K,V> tailMap(K fromKey, boolean inclusive) {
|
||||||
if (!inRange(fromKey, inclusive))
|
if (!inRange(fromKey, inclusive))
|
||||||
throw new IllegalArgumentException("fromKey out of range");
|
throw new IllegalArgumentException("fromKey out of range");
|
||||||
return new AscendingSubMap(m,
|
return new AscendingSubMap<>(m,
|
||||||
false, fromKey, inclusive,
|
false, fromKey, inclusive,
|
||||||
toEnd, hi, hiInclusive);
|
toEnd, hi, hiInclusive);
|
||||||
}
|
}
|
||||||
|
|
||||||
public NavigableMap<K,V> descendingMap() {
|
public NavigableMap<K,V> descendingMap() {
|
||||||
NavigableMap<K,V> mv = descendingMapView;
|
NavigableMap<K,V> mv = descendingMapView;
|
||||||
return (mv != null) ? mv :
|
return (mv != null) ? mv :
|
||||||
(descendingMapView =
|
(descendingMapView =
|
||||||
new DescendingSubMap(m,
|
new DescendingSubMap<>(m,
|
||||||
fromStart, lo, loInclusive,
|
fromStart, lo, loInclusive,
|
||||||
toEnd, hi, hiInclusive));
|
toEnd, hi, hiInclusive));
|
||||||
}
|
}
|
||||||
|
|
||||||
Iterator<K> keyIterator() {
|
Iterator<K> keyIterator() {
|
||||||
@ -1790,34 +1794,34 @@ public class TreeMap<K,V>
|
|||||||
throw new IllegalArgumentException("fromKey out of range");
|
throw new IllegalArgumentException("fromKey out of range");
|
||||||
if (!inRange(toKey, toInclusive))
|
if (!inRange(toKey, toInclusive))
|
||||||
throw new IllegalArgumentException("toKey out of range");
|
throw new IllegalArgumentException("toKey out of range");
|
||||||
return new DescendingSubMap(m,
|
return new DescendingSubMap<>(m,
|
||||||
false, toKey, toInclusive,
|
false, toKey, toInclusive,
|
||||||
false, fromKey, fromInclusive);
|
false, fromKey, fromInclusive);
|
||||||
}
|
}
|
||||||
|
|
||||||
public NavigableMap<K,V> headMap(K toKey, boolean inclusive) {
|
public NavigableMap<K,V> headMap(K toKey, boolean inclusive) {
|
||||||
if (!inRange(toKey, inclusive))
|
if (!inRange(toKey, inclusive))
|
||||||
throw new IllegalArgumentException("toKey out of range");
|
throw new IllegalArgumentException("toKey out of range");
|
||||||
return new DescendingSubMap(m,
|
return new DescendingSubMap<>(m,
|
||||||
false, toKey, inclusive,
|
false, toKey, inclusive,
|
||||||
toEnd, hi, hiInclusive);
|
toEnd, hi, hiInclusive);
|
||||||
}
|
}
|
||||||
|
|
||||||
public NavigableMap<K,V> tailMap(K fromKey, boolean inclusive) {
|
public NavigableMap<K,V> tailMap(K fromKey, boolean inclusive) {
|
||||||
if (!inRange(fromKey, inclusive))
|
if (!inRange(fromKey, inclusive))
|
||||||
throw new IllegalArgumentException("fromKey out of range");
|
throw new IllegalArgumentException("fromKey out of range");
|
||||||
return new DescendingSubMap(m,
|
return new DescendingSubMap<>(m,
|
||||||
fromStart, lo, loInclusive,
|
fromStart, lo, loInclusive,
|
||||||
false, fromKey, inclusive);
|
false, fromKey, inclusive);
|
||||||
}
|
}
|
||||||
|
|
||||||
public NavigableMap<K,V> descendingMap() {
|
public NavigableMap<K,V> descendingMap() {
|
||||||
NavigableMap<K,V> mv = descendingMapView;
|
NavigableMap<K,V> mv = descendingMapView;
|
||||||
return (mv != null) ? mv :
|
return (mv != null) ? mv :
|
||||||
(descendingMapView =
|
(descendingMapView =
|
||||||
new AscendingSubMap(m,
|
new AscendingSubMap<>(m,
|
||||||
fromStart, lo, loInclusive,
|
fromStart, lo, loInclusive,
|
||||||
toEnd, hi, hiInclusive));
|
toEnd, hi, hiInclusive));
|
||||||
}
|
}
|
||||||
|
|
||||||
Iterator<K> keyIterator() {
|
Iterator<K> keyIterator() {
|
||||||
@ -1862,9 +1866,9 @@ public class TreeMap<K,V>
|
|||||||
private boolean fromStart = false, toEnd = false;
|
private boolean fromStart = false, toEnd = false;
|
||||||
private K fromKey, toKey;
|
private K fromKey, toKey;
|
||||||
private Object readResolve() {
|
private Object readResolve() {
|
||||||
return new AscendingSubMap(TreeMap.this,
|
return new AscendingSubMap<>(TreeMap.this,
|
||||||
fromStart, fromKey, true,
|
fromStart, fromKey, true,
|
||||||
toEnd, toKey, false);
|
toEnd, toKey, false);
|
||||||
}
|
}
|
||||||
public Set<Map.Entry<K,V>> entrySet() { throw new InternalError(); }
|
public Set<Map.Entry<K,V>> entrySet() { throw new InternalError(); }
|
||||||
public K lastKey() { throw new InternalError(); }
|
public K lastKey() { throw new InternalError(); }
|
||||||
@ -2331,12 +2335,12 @@ public class TreeMap<K,V>
|
|||||||
* @param defaultVal if non-null, this default value is used for
|
* @param defaultVal if non-null, this default value is used for
|
||||||
* each value in the map. If null, each value is read from
|
* each value in the map. If null, each value is read from
|
||||||
* iterator or stream, as described above.
|
* iterator or stream, as described above.
|
||||||
* @throws IOException propagated from stream reads. This cannot
|
* @throws java.io.IOException propagated from stream reads. This cannot
|
||||||
* occur if str is null.
|
* occur if str is null.
|
||||||
* @throws ClassNotFoundException propagated from readObject.
|
* @throws ClassNotFoundException propagated from readObject.
|
||||||
* This cannot occur if str is null.
|
* This cannot occur if str is null.
|
||||||
*/
|
*/
|
||||||
private void buildFromSorted(int size, Iterator it,
|
private void buildFromSorted(int size, Iterator<?> it,
|
||||||
java.io.ObjectInputStream str,
|
java.io.ObjectInputStream str,
|
||||||
V defaultVal)
|
V defaultVal)
|
||||||
throws java.io.IOException, ClassNotFoundException {
|
throws java.io.IOException, ClassNotFoundException {
|
||||||
@ -2359,9 +2363,10 @@ public class TreeMap<K,V>
|
|||||||
* @param redLevel the level at which nodes should be red.
|
* @param redLevel the level at which nodes should be red.
|
||||||
* Must be equal to computeRedLevel for tree of this size.
|
* Must be equal to computeRedLevel for tree of this size.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
private final Entry<K,V> buildFromSorted(int level, int lo, int hi,
|
private final Entry<K,V> buildFromSorted(int level, int lo, int hi,
|
||||||
int redLevel,
|
int redLevel,
|
||||||
Iterator it,
|
Iterator<?> it,
|
||||||
java.io.ObjectInputStream str,
|
java.io.ObjectInputStream str,
|
||||||
V defaultVal)
|
V defaultVal)
|
||||||
throws java.io.IOException, ClassNotFoundException {
|
throws java.io.IOException, ClassNotFoundException {
|
||||||
@ -2391,9 +2396,9 @@ public class TreeMap<K,V>
|
|||||||
V value;
|
V value;
|
||||||
if (it != null) {
|
if (it != null) {
|
||||||
if (defaultVal==null) {
|
if (defaultVal==null) {
|
||||||
Map.Entry<K,V> entry = (Map.Entry<K,V>)it.next();
|
Map.Entry<?,?> entry = (Map.Entry<?,?>)it.next();
|
||||||
key = entry.getKey();
|
key = (K)entry.getKey();
|
||||||
value = entry.getValue();
|
value = (V)entry.getValue();
|
||||||
} else {
|
} else {
|
||||||
key = (K)it.next();
|
key = (K)it.next();
|
||||||
value = defaultVal;
|
value = defaultVal;
|
||||||
|
@ -302,7 +302,7 @@ public class TreeSet<E> extends AbstractSet<E>
|
|||||||
m instanceof TreeMap) {
|
m instanceof TreeMap) {
|
||||||
SortedSet<? extends E> set = (SortedSet<? extends E>) c;
|
SortedSet<? extends E> set = (SortedSet<? extends E>) c;
|
||||||
TreeMap<E,Object> map = (TreeMap<E, Object>) m;
|
TreeMap<E,Object> map = (TreeMap<E, Object>) m;
|
||||||
Comparator<? super E> cc = (Comparator<? super E>) set.comparator();
|
Comparator<?> cc = set.comparator();
|
||||||
Comparator<? super E> mc = map.comparator();
|
Comparator<? super E> mc = map.comparator();
|
||||||
if (cc==mc || (cc != null && cc.equals(mc))) {
|
if (cc==mc || (cc != null && cc.equals(mc))) {
|
||||||
map.addAllForTreeSet(set, PRESENT);
|
map.addAllForTreeSet(set, PRESENT);
|
||||||
@ -469,8 +469,9 @@ public class TreeSet<E> extends AbstractSet<E>
|
|||||||
*
|
*
|
||||||
* @return a shallow copy of this set
|
* @return a shallow copy of this set
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public Object clone() {
|
public Object clone() {
|
||||||
TreeSet<E> clone = null;
|
TreeSet<E> clone;
|
||||||
try {
|
try {
|
||||||
clone = (TreeSet<E>) super.clone();
|
clone = (TreeSet<E>) super.clone();
|
||||||
} catch (CloneNotSupportedException e) {
|
} catch (CloneNotSupportedException e) {
|
||||||
@ -519,14 +520,11 @@ public class TreeSet<E> extends AbstractSet<E>
|
|||||||
s.defaultReadObject();
|
s.defaultReadObject();
|
||||||
|
|
||||||
// Read in Comparator
|
// Read in Comparator
|
||||||
Comparator<? super E> c = (Comparator<? super E>) s.readObject();
|
@SuppressWarnings("unchecked")
|
||||||
|
Comparator<? super E> c = (Comparator<? super E>) s.readObject();
|
||||||
|
|
||||||
// Create backing TreeMap
|
// Create backing TreeMap
|
||||||
TreeMap<E,Object> tm;
|
TreeMap<E,Object> tm = new TreeMap<>(c);
|
||||||
if (c==null)
|
|
||||||
tm = new TreeMap<>();
|
|
||||||
else
|
|
||||||
tm = new TreeMap<>(c);
|
|
||||||
m = tm;
|
m = tm;
|
||||||
|
|
||||||
// Read in size
|
// Read in size
|
||||||
|
@ -186,7 +186,7 @@ public class WeakHashMap<K,V>
|
|||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private Entry<K,V>[] newTable(int n) {
|
private Entry<K,V>[] newTable(int n) {
|
||||||
return (Entry<K,V>[]) new Entry[n];
|
return (Entry<K,V>[]) new Entry<?,?>[n];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2003, 2006, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -24,8 +24,6 @@
|
|||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @bug 4957695
|
* @bug 4957695
|
||||||
* @library ../../httptest/
|
|
||||||
* @build HttpCallback HttpServer ClosedChannelList HttpTransaction AbstractCallback
|
|
||||||
* @summary URLJarFile.retrieve does not delete tmpFile on IOException
|
* @summary URLJarFile.retrieve does not delete tmpFile on IOException
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -34,8 +32,56 @@ import java.net.*;
|
|||||||
|
|
||||||
public class B4957695 {
|
public class B4957695 {
|
||||||
|
|
||||||
static int count = 0;
|
static Server server;
|
||||||
static boolean error = false;
|
|
||||||
|
static class Server extends Thread {
|
||||||
|
final ServerSocket srv;
|
||||||
|
static final byte[] requestEnd = new byte[] {'\r', '\n', '\r', '\n'};
|
||||||
|
|
||||||
|
Server(ServerSocket s) {
|
||||||
|
srv = s;
|
||||||
|
}
|
||||||
|
|
||||||
|
void readOneRequest(InputStream is) throws IOException {
|
||||||
|
int requestEndCount = 0, r;
|
||||||
|
while ((r = is.read()) != -1) {
|
||||||
|
if (r == requestEnd[requestEndCount]) {
|
||||||
|
requestEndCount++;
|
||||||
|
if (requestEndCount == 4) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
requestEndCount = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run() {
|
||||||
|
try (Socket s = srv.accept()) {
|
||||||
|
// read HTTP request from client
|
||||||
|
readOneRequest(s.getInputStream());
|
||||||
|
try (OutputStreamWriter ow =
|
||||||
|
new OutputStreamWriter((s.getOutputStream()))) {
|
||||||
|
FileInputStream fin = new FileInputStream("foo1.jar");
|
||||||
|
int length = fin.available();
|
||||||
|
byte[] b = new byte[length-10];
|
||||||
|
fin.read(b, 0, length-10);
|
||||||
|
ow.write("HTTP/1.0 200 OK\r\n");
|
||||||
|
|
||||||
|
// Note: The client expects length bytes.
|
||||||
|
ow.write("Content-Length: " + length + "\r\n");
|
||||||
|
ow.write("Content-Type: text/html\r\n");
|
||||||
|
ow.write("\r\n");
|
||||||
|
|
||||||
|
// Note: The (buggy) server only sends length-10 bytes.
|
||||||
|
ow.write(new String(b));
|
||||||
|
ow.flush();
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void read (InputStream is) throws IOException {
|
static void read (InputStream is) throws IOException {
|
||||||
int c,len=0;
|
int c,len=0;
|
||||||
@ -45,32 +91,13 @@ public class B4957695 {
|
|||||||
System.out.println ("read " + len + " bytes");
|
System.out.println ("read " + len + " bytes");
|
||||||
}
|
}
|
||||||
|
|
||||||
static class CallBack extends AbstractCallback {
|
|
||||||
|
|
||||||
public void request (HttpTransaction req, int count) {
|
|
||||||
try {
|
|
||||||
System.out.println ("Request received");
|
|
||||||
req.setResponseEntityBody (new FileInputStream ("foo1.jar"));
|
|
||||||
System.out.println ("content length " + req.getResponseHeader (
|
|
||||||
"Content-length"
|
|
||||||
));
|
|
||||||
req.sendPartialResponse (200, "Ok");
|
|
||||||
req.abortiveClose();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
static HttpServer server;
|
|
||||||
|
|
||||||
public static void main (String[] args) throws Exception {
|
public static void main (String[] args) throws Exception {
|
||||||
String tmpdir = System.getProperty("java.io.tmpdir");
|
String tmpdir = System.getProperty("java.io.tmpdir");
|
||||||
String[] list1 = listTmpFiles(tmpdir);
|
String[] list1 = listTmpFiles(tmpdir);
|
||||||
//server = new HttpServer (new CallBack(), 10, 1, 0);
|
ServerSocket serverSocket = new ServerSocket(0);
|
||||||
server = new HttpServer (new CallBack(), 1, 5, 0);
|
server = new Server(serverSocket);
|
||||||
int port = server.getLocalPort();
|
server.start();
|
||||||
|
int port = serverSocket.getLocalPort();
|
||||||
System.out.println ("Server: listening on port: " + port);
|
System.out.println ("Server: listening on port: " + port);
|
||||||
URL url = new URL ("jar:http://localhost:"+port+"!/COPYRIGHT");
|
URL url = new URL ("jar:http://localhost:"+port+"!/COPYRIGHT");
|
||||||
try {
|
try {
|
||||||
@ -81,14 +108,12 @@ public class B4957695 {
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.out.println ("Received IOException as expected");
|
System.out.println ("Received IOException as expected");
|
||||||
}
|
}
|
||||||
server.terminate();
|
|
||||||
String[] list2 = listTmpFiles(tmpdir);
|
String[] list2 = listTmpFiles(tmpdir);
|
||||||
if (!sameList (list1, list2)) {
|
if (!sameList (list1, list2)) {
|
||||||
throw new RuntimeException ("some jar_cache files left behind");
|
throw new RuntimeException ("some jar_cache files left behind");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static String[] listTmpFiles (String d) {
|
static String[] listTmpFiles (String d) {
|
||||||
File dir = new File (d);
|
File dir = new File (d);
|
||||||
return dir.list (new FilenameFilter () {
|
return dir.list (new FilenameFilter () {
|
||||||
|
Loading…
Reference in New Issue
Block a user