Skip to content

Commit bfdac97

Browse files
committed
legacy Hashtable upgrade to use JavaScript map, as in SwingJS version.
1 parent c80cb72 commit bfdac97

File tree

6 files changed

+1384
-803
lines changed

6 files changed

+1384
-803
lines changed
16 KB
Binary file not shown.

sources/net.sf.j2s.java.core/src_4.2/java/util/Collections.java

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,55 @@
2727
* @since 1.2
2828
*/
2929
public class Collections {
30+
31+
static EmptyEnumeration<Object> EMPTY_ENUMERATION;
32+
static EmptyIterator<Object> EMPTY_ITERATOR;
3033

34+
35+
@SuppressWarnings("unchecked")
36+
public static <T> Enumeration<T> emptyEnumeration() {
37+
if (EMPTY_ENUMERATION == null)
38+
EMPTY_ENUMERATION = new EmptyEnumeration<>();
39+
return (Enumeration<T>) EMPTY_ENUMERATION;
40+
}
41+
42+
private static class EmptyEnumeration<E> implements Enumeration<E> {
43+
44+
@Override
45+
public boolean hasMoreElements() { return false; }
46+
@Override
47+
public E nextElement() { throw new NoSuchElementException(); }
48+
}
49+
50+
@SuppressWarnings("unchecked")
51+
public static <T> Iterator<T> emptyIterator() {
52+
if (EMPTY_ITERATOR == null) {
53+
EMPTY_ITERATOR = new EmptyIterator<>();
54+
}
55+
return (Iterator<T>) EMPTY_ITERATOR;
56+
}
57+
58+
59+
/**
60+
* From Java 8+
61+
* @author hanso
62+
*
63+
* @param <E>
64+
*/
65+
private static class EmptyIterator<E> implements Iterator<E> {
66+
@Override
67+
public boolean hasNext() { return false; }
68+
@Override
69+
public E next() { throw new NoSuchElementException(); }
70+
@Override
71+
public void remove() { throw new IllegalStateException(); }
72+
// @Override
73+
// public void forEachRemaining(Consumer<? super E> action) {
74+
// Objects.requireNonNull(action);
75+
// }
76+
}
77+
78+
3179
private static final class CopiesList<E> extends AbstractList<E> implements
3280
Serializable {
3381
private static final long serialVersionUID = 2739099268398711800L;
@@ -91,8 +139,6 @@ private Object readResolve() {
91139
@SuppressWarnings("unchecked")
92140
private static final class EmptySet extends AbstractSet implements
93141
Serializable {
94-
private static final long serialVersionUID = 1582296315990362920L;
95-
96142
@Override
97143
public boolean contains(Object object) {
98144
return false;

0 commit comments

Comments
 (0)