1 |
|
/* |
2 |
< |
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved. |
2 |
> |
* Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved. |
3 |
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
|
* |
5 |
|
* This code is free software; you can redistribute it and/or modify it |
23 |
|
|
24 |
|
/* |
25 |
|
* @test |
26 |
< |
* @bug 5017904 6356890 |
26 |
> |
* @bug 5017904 6356890 8004928 |
27 |
|
* @summary Test empty iterators, enumerations, and collections |
28 |
|
*/ |
29 |
|
|
30 |
< |
import java.util.*; |
31 |
< |
import static java.util.Collections.*; |
30 |
> |
import java.util.Collection; |
31 |
> |
import java.util.Collections; |
32 |
> |
import java.util.Enumeration; |
33 |
> |
import java.util.Hashtable; |
34 |
> |
import java.util.Iterator; |
35 |
> |
import java.util.List; |
36 |
> |
import java.util.Map; |
37 |
> |
import java.util.NoSuchElementException; |
38 |
> |
import java.util.concurrent.SynchronousQueue; |
39 |
> |
|
40 |
> |
import static java.util.Collections.emptyEnumeration; |
41 |
> |
import static java.util.Collections.emptyIterator; |
42 |
> |
import static java.util.Collections.emptyList; |
43 |
> |
import static java.util.Collections.emptyListIterator; |
44 |
> |
import static java.util.Collections.emptyMap; |
45 |
> |
import static java.util.Collections.emptySet; |
46 |
> |
import static java.util.Collections.nCopies; |
47 |
> |
import static java.util.Collections.unmodifiableMap; |
48 |
|
|
49 |
|
public class EmptyIterator { |
50 |
|
|
51 |
|
void test(String[] args) throws Throwable { |
52 |
< |
testEmptyCollection(Collections.<Object>emptyList()); |
53 |
< |
testEmptyCollection(Collections.<Object>emptySet()); |
54 |
< |
testEmptyCollection(new java.util.concurrent. |
55 |
< |
SynchronousQueue<Object>()); |
52 |
> |
testEmptyCollection(emptyList()); |
53 |
> |
testEmptyCollection(emptySet()); |
54 |
> |
testEmptyCollection(new SynchronousQueue<Object>()); |
55 |
> |
testEmptyMap(emptyMap()); |
56 |
|
|
57 |
< |
testEmptyMap(Collections.<Object, Object>emptyMap()); |
42 |
< |
|
43 |
< |
Hashtable<Object, Object> emptyTable = new Hashtable<Object, Object>(); |
57 |
> |
Hashtable<?,?> emptyTable = new Hashtable<>(); |
58 |
|
testEmptyEnumeration(emptyTable.keys()); |
59 |
|
testEmptyEnumeration(emptyTable.elements()); |
60 |
|
testEmptyIterator(emptyTable.keySet().iterator()); |
61 |
|
testEmptyIterator(emptyTable.values().iterator()); |
62 |
|
testEmptyIterator(emptyTable.entrySet().iterator()); |
63 |
|
|
64 |
< |
testEmptyEnumeration(javax.swing.tree.DefaultMutableTreeNode |
65 |
< |
.EMPTY_ENUMERATION); |
66 |
< |
testEmptyEnumeration(javax.swing.text.SimpleAttributeSet |
67 |
< |
.EMPTY.getAttributeNames()); |
68 |
< |
|
69 |
< |
@SuppressWarnings("unchecked") Iterator<?> x = |
70 |
< |
new sun.tools.java.MethodSet() |
57 |
< |
.lookupName(sun.tools.java.Identifier.lookup("")); |
58 |
< |
testEmptyIterator(x); |
64 |
> |
final Enumeration<EmptyIterator> finalEmptyTyped = emptyEnumeration(); |
65 |
> |
testEmptyEnumeration(finalEmptyTyped); |
66 |
> |
|
67 |
> |
final Enumeration<?> finalEmptyAbstract = emptyEnumeration(); |
68 |
> |
testEmptyEnumeration(finalEmptyAbstract); |
69 |
> |
|
70 |
> |
testEmptyIterator(emptyIterator()); |
71 |
|
} |
72 |
|
|
73 |
< |
<T> void testEmptyEnumeration(final Enumeration<T> e) { |
73 |
> |
void testEmptyEnumeration(final Enumeration<?> e) { |
74 |
|
check(e == emptyEnumeration()); |
75 |
< |
check(! e.hasMoreElements()); |
75 |
> |
check(!e.hasMoreElements()); |
76 |
|
THROWS(NoSuchElementException.class, |
77 |
|
new F(){void f(){ e.nextElement(); }}); |
78 |
|
} |
79 |
|
|
80 |
< |
<T> void testEmptyIterator(final Iterator<T> it) { |
80 |
> |
void testEmptyIterator(final Iterator<?> it) { |
81 |
|
check(it == emptyIterator()); |
82 |
|
check(! it.hasNext()); |
83 |
|
THROWS(NoSuchElementException.class, |
86 |
|
new F(){void f(){ it.remove(); }}); |
87 |
|
} |
88 |
|
|
89 |
< |
void testEmptyMap(Map<Object, Object> m) { |
89 |
> |
void testEmptyMap(Map<?,?> m) { |
90 |
|
check(m == emptyMap()); |
91 |
|
check(m.entrySet().iterator() == |
92 |
< |
Collections.<Map.Entry<Object,Object>>emptyIterator()); |
92 |
> |
Collections.<Map.Entry<?,?>>emptyIterator()); |
93 |
|
check(m.values().iterator() == emptyIterator()); |
94 |
|
check(m.keySet().iterator() == emptyIterator()); |
95 |
|
equal(m, unmodifiableMap(m)); |
99 |
|
testEmptyCollection(m.values()); |
100 |
|
} |
101 |
|
|
102 |
< |
<E> void testToArray(final Collection<E> c) { |
102 |
> |
void testToArray(final Collection<?> c) { |
103 |
|
Object[] a = c.toArray(); |
104 |
|
equal(a.length, 0); |
105 |
|
equal(a.getClass().getComponentType(), Object.class); |
120 |
|
} |
121 |
|
} |
122 |
|
|
123 |
< |
<E> void testEmptyCollection(final Collection<E> c) { |
123 |
> |
void testEmptyCollection(final Collection<?> c) { |
124 |
|
testEmptyIterator(c.iterator()); |
125 |
|
|
126 |
|
check(c.iterator() == emptyIterator()); |