8067112: Update java/util/Collections/EmptyIterator.java to eliminate dependency on sun.tools.java
Reviewed-by: chegar, prappo
Contributed-by: Amy Lu <amy.lu@oracle.com>
--- a/jdk/test/java/util/Collections/EmptyIterator.java Thu Oct 30 07:31:41 2014 -0700
+++ b/jdk/test/java/util/Collections/EmptyIterator.java Sat Dec 13 20:22:21 2014 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -33,40 +33,35 @@
public class EmptyIterator {
void test(String[] args) throws Throwable {
- testEmptyCollection(Collections.<Object>emptyList());
- testEmptyCollection(Collections.<Object>emptySet());
+ testEmptyCollection(emptyList());
+ testEmptyCollection(emptySet());
- testEmptyMap(Collections.<Object, Object>emptyMap());
+ testEmptyMap(emptyMap());
- Hashtable<Object, Object> emptyTable = new Hashtable<Object, Object>();
+ Hashtable<?,?> emptyTable = new Hashtable<>();
testEmptyEnumeration(emptyTable.keys());
testEmptyEnumeration(emptyTable.elements());
testEmptyIterator(emptyTable.keySet().iterator());
testEmptyIterator(emptyTable.values().iterator());
testEmptyIterator(emptyTable.entrySet().iterator());
- final Enumeration<EmptyIterator> finalEmptyTyped =
- Collections.emptyEnumeration();
+ final Enumeration<EmptyIterator> finalEmptyTyped = emptyEnumeration();
testEmptyEnumeration(finalEmptyTyped);
- final Enumeration finalEmptyAbstract =
- Collections.emptyEnumeration();
+ final Enumeration<?> finalEmptyAbstract = emptyEnumeration();
testEmptyEnumeration(finalEmptyAbstract);
- @SuppressWarnings("unchecked") Iterator<?> x =
- new sun.tools.java.MethodSet()
- .lookupName(sun.tools.java.Identifier.lookup(""));
- testEmptyIterator(x);
+ testEmptyIterator(emptyIterator());
}
- <T> void testEmptyEnumeration(final Enumeration<T> e) {
+ void testEmptyEnumeration(final Enumeration<?> e) {
check(e == emptyEnumeration());
- check(! e.hasMoreElements());
+ check(!e.hasMoreElements());
THROWS(NoSuchElementException.class,
new F(){void f(){ e.nextElement(); }});
}
- <T> void testEmptyIterator(final Iterator<T> it) {
+ void testEmptyIterator(final Iterator<?> it) {
check(it == emptyIterator());
check(! it.hasNext());
THROWS(NoSuchElementException.class,
@@ -75,10 +70,10 @@
new F(){void f(){ it.remove(); }});
}
- void testEmptyMap(Map<Object, Object> m) {
+ void testEmptyMap(Map<?,?> m) {
check(m == emptyMap());
check(m.entrySet().iterator() ==
- Collections.<Map.Entry<Object,Object>>emptyIterator());
+ Collections.<Map.Entry<?,?>>emptyIterator());
check(m.values().iterator() == emptyIterator());
check(m.keySet().iterator() == emptyIterator());
equal(m, unmodifiableMap(m));
@@ -88,7 +83,7 @@
testEmptyCollection(m.values());
}
- <E> void testToArray(final Collection<E> c) {
+ void testToArray(final Collection<?> c) {
Object[] a = c.toArray();
equal(a.length, 0);
equal(a.getClass().getComponentType(), Object.class);
@@ -109,7 +104,7 @@
}
}
- <E> void testEmptyCollection(final Collection<E> c) {
+ void testEmptyCollection(final Collection<?> c) {
testEmptyIterator(c.iterator());
check(c.iterator() == emptyIterator());