Author: pyang
Date: Wed Sep 6 01:23:57 2006
New Revision: 440652
URL: http://svn.apache.org/viewvc?view=rev&rev=440652
Log:
Patch applied for HARMONY-1387 ([classlib][luni]new method java.util.EnumSet.clone, serialization feature, and subclass HugeEnumSet)
Added:
incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/HugeEnumSet.java
incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/resources/serialization/tests/api/java/util/EnumSetTest.golden.ser (with props)
Modified:
incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/EnumSet.java
incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/EnumSetTest.java
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/EnumSet.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/EnumSet.java?view=diff&rev=440652&r1=440651&r2=440652
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/EnumSet.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/EnumSet.java Wed Sep 6 01:23:57 2006
@@ -16,8 +16,6 @@
import java.io.Serializable;
-import org.apache.harmony.luni.util.NotYetImplementedException;
-
public abstract class EnumSet<E extends Enum<E>> extends AbstractSet<E>
implements Cloneable, Serializable {
@@ -44,7 +42,7 @@
if (elementType.getEnumConstants().length <= 64) {
return new MiniEnumSet<E>(elementType);
}
- throw new NotYetImplementedException();
+ return new HugeEnumSet<E>(elementType);
}
/**
@@ -279,11 +277,11 @@
throw new IllegalArgumentException();
}
EnumSet<E> set = EnumSet.noneOf(start.getDeclaringClass());
- set.addRange(start, end);
+ set.setRange(start, end);
return set;
}
- abstract void addRange(E start, E end);
+ abstract void setRange(E start, E end);
/**
* Creates a new enum set with the same elements as those contained in this
@@ -294,11 +292,42 @@
*/
@Override
public EnumSet<E> clone() {
- throw new NotYetImplementedException();
+ try {
+ Object set = super.clone();
+ return (EnumSet<E>) set;
+ } catch (CloneNotSupportedException e) {
+ return null;
+ }
}
@SuppressWarnings("unchecked")
boolean isValidType(Class cls) {
return cls == elementClass || cls.getSuperclass() == elementClass;
+ }
+
+ private static class SerializationProxy<E extends Enum<E>> implements
+ Serializable {
+
+ private static final long serialVersionUID = 362491234563181265L;
+
+ private Class<E> elementType;
+
+ private E[] elements;
+
+ private Object readResolve() {
+ EnumSet<E> set = EnumSet.noneOf(elementType);
+ for (E e : elements) {
+ set.add(e);
+ }
+ return set;
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private Object writeReplace() {
+ SerializationProxy proxy = new SerializationProxy();
+ proxy.elements = (Enum[]) toArray();
+ proxy.elementType = elementClass;
+ return proxy;
}
}
Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/HugeEnumSet.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/HugeEnumSet.java?view=auto&rev=440652
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/HugeEnumSet.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/HugeEnumSet.java Wed Sep 6 01:23:57 2006
@@ -0,0 +1,346 @@
+/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.util;
+
+
+/**
+ * This is a concrete subclass of EnumSet designed specifically for enum type
+ * with more than 64 elements.
+ *
+ */
+@SuppressWarnings("serial")
+final class HugeEnumSet<E extends Enum<E>> extends EnumSet<E> {
+
+ final private E[] enums;
+
+ private long[] bits;
+
+ private int size;
+
+ private static final int BIT_IN_LONG = 64;
+
+ HugeEnumSet(Class<E> elementType) {
+ super(elementType);
+ enums = elementType.getEnumConstants();
+ bits = new long[(enums.length + BIT_IN_LONG - 1) / BIT_IN_LONG];
+ Arrays.fill(bits, 0);
+ }
+
+ private class HugeEnumSetIterator implements Iterator<E> {
+
+ private long[] unProcessedBits;
+
+ private int bitsPosition = 0;
+
+ /*
+ * Mask for current element.
+ */
+ private long currentElementMask = 0;
+
+ boolean canProcess = true;
+
+ private HugeEnumSetIterator() {
+ unProcessedBits = new long[bits.length];
+ System.arraycopy(bits, 0, unProcessedBits, 0, bits.length);
+ bitsPosition = unProcessedBits.length;
+ findNextNoneZeroPosition(0);
+ if (bitsPosition == unProcessedBits.length) {
+ canProcess = false;
+ }
+ }
+
+ private void findNextNoneZeroPosition(int start) {
+ for (int i = start; i < unProcessedBits.length; i++) {
+ if (0 != bits[i]) {
+ bitsPosition = i;
+ break;
+ }
+ }
+ }
+
+ public boolean hasNext() {
+ return canProcess;
+ }
+
+ public E next() {
+ if (!canProcess) {
+ throw new NoSuchElementException();
+ }
+ currentElementMask = unProcessedBits[bitsPosition]
+ & (-unProcessedBits[bitsPosition]);
+ unProcessedBits[bitsPosition] -= currentElementMask;
+ if (0 == unProcessedBits[bitsPosition]) {
+ int oldBitsPosition = bitsPosition;
+ findNextNoneZeroPosition(bitsPosition + 1);
+ if (bitsPosition == oldBitsPosition) {
+ canProcess = false;
+ }
+ }
+ return enums[Long.numberOfTrailingZeros(currentElementMask)
+ + bitsPosition * BIT_IN_LONG];
+ }
+
+ public void remove() {
+ if (currentElementMask == 0) {
+ throw new IllegalStateException();
+ }
+ bits[bitsPosition] &= ~currentElementMask;
+ size--;
+ currentElementMask = 0;
+ }
+ }
+
+ @Override
+ public boolean add(E element) {
+ if (!isValidType(element.getDeclaringClass())) {
+ throw new ClassCastException();
+ }
+ calculateElementIndex(element);
+
+ bits[bitsIndex] |= (1l << elementInBits);
+ if (oldBits == bits[bitsIndex]) {
+ return false;
+ }
+ size++;
+ return true;
+ }
+
+ @Override
+ public boolean addAll(Collection<? extends E> collection) {
+ if (0 == collection.size() || this == collection) {
+ return false;
+ }
+ if (collection instanceof EnumSet) {
+ EnumSet set = (EnumSet) collection;
+ if (!isValidType(set.elementClass)) {
+ throw new ClassCastException();
+ }
+ HugeEnumSet hugeSet = (HugeEnumSet) set;
+ boolean addSuccessful = false;
+ for (int i = 0; i < bits.length; i++) {
+ oldBits = bits[i];
+ bits[i] |= hugeSet.bits[i];
+ if (oldBits != bits[i]) {
+ addSuccessful = true;
+ size = size - Long.bitCount(oldBits)
+ + Long.bitCount(bits[i]);
+ }
+ }
+ return addSuccessful;
+ }
+ return super.addAll(collection);
+ }
+
+ @Override
+ public int size() {
+ return size;
+ }
+
+ @Override
+ public void clear() {
+ Arrays.fill(bits, 0);
+ size = 0;
+ }
+
+ @Override
+ protected void complement() {
+ if (0 != enums.length) {
+ bitsIndex = enums.length / BIT_IN_LONG;
+
+ size = 0;
+ int bitCount = 0;
+ for (int i = 0; i <= bitsIndex; i++) {
+ bits[i] = ~bits[i];
+ bitCount = Long.bitCount(bits[i]);
+ size += bitCount;
+ }
+ bits[bitsIndex] &= (-1l >>> (BIT_IN_LONG - enums.length
+ % BIT_IN_LONG));
+ size -= bitCount;
+ bitCount = Long.bitCount(bits[bitsIndex]);
+ size += bitCount;
+ }
+ }
+
+ @Override
+ public boolean contains(Object object) {
+ if (null == object) {
+ return false;
+ }
+ if (!isValidType(object.getClass())) {
+ return false;
+ }
+ calculateElementIndex((E)object);
+ return (bits[bitsIndex] & (1l << elementInBits)) != 0;
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public HugeEnumSet<E> clone() {
+ Object set = super.clone();
+ if (null != set) {
+ ((HugeEnumSet<E>) set).bits = bits.clone();
+ return (HugeEnumSet<E>) set;
+ }
+ return null;
+ }
+
+ @Override
+ public boolean containsAll(Collection<?> collection) {
+ if (collection.size() == 0) {
+ return true;
+ }
+ if (collection instanceof HugeEnumSet) {
+ HugeEnumSet set = (HugeEnumSet) collection;
+ if(isValidType(set.elementClass )) {
+ for(int i = 0; i < bits.length; i++) {
+ if((bits[i] & set.bits[i]) != set.bits[i]){
+ return false;
+ }
+
+ }
+ return true;
+ }
+ }
+ return !(collection instanceof EnumSet) && super.containsAll(collection);
+ }
+
+ @Override
+ public boolean equals(Object object) {
+ if (null == object) {
+ return false;
+ }
+ if (!isValidType(object.getClass())) {
+ return super.equals(object);
+ }
+ return Arrays.equals(bits, ((HugeEnumSet) object).bits);
+ }
+
+ @Override
+ public Iterator<E> iterator() {
+ return new HugeEnumSetIterator();
+ }
+
+ @Override
+ public boolean remove(Object object) {
+ if (!contains(object)) {
+ return false;
+ }
+ bits[bitsIndex] -= (1l << elementInBits);
+ size--;
+ return true;
+ }
+
+ @Override
+ public boolean removeAll(Collection<?> collection) {
+ if (0 == collection.size()) {
+ return false;
+ }
+
+ if (collection instanceof EnumSet) {
+ EnumSet<E> set = (EnumSet<E>) collection;
+ if (!isValidType(set.elementClass)) {
+ return false;
+ }
+ boolean removeSuccessful = false;
+ long mask = 0;
+ for (int i = 0; i < bits.length; i++) {
+ oldBits = bits[i];
+ mask = bits[i] & ((HugeEnumSet<E>) set).bits[i];
+ if (mask != 0) {
+ bits[i] -= mask;
+ size = (size - Long.bitCount(oldBits) + Long
+ .bitCount(bits[i]));
+ removeSuccessful = true;
+ }
+ }
+ return removeSuccessful;
+ }
+ return super.removeAll(collection);
+ }
+
+ @Override
+ public boolean retainAll(Collection<?> collection) {
+ if (collection instanceof EnumSet) {
+ EnumSet<E> set = (EnumSet<E>) collection;
+ if (!isValidType(set.elementClass)) {
+ clear();
+ return true;
+ }
+
+ boolean retainSuccessful = false;
+ oldBits = 0;
+ for (int i = 0; i < bits.length; i++) {
+ oldBits = bits[i];
+ bits[i] &= ((HugeEnumSet<E>) set).bits[i];
+ if (oldBits != bits[i]) {
+ size = size - Long.bitCount(oldBits)
+ + Long.bitCount(bits[i]);
+ retainSuccessful = true;
+ }
+ }
+ return retainSuccessful;
+ }
+ return super.retainAll(collection);
+ }
+
+ @Override
+ void setRange(E start, E end) {
+ calculateElementIndex(start);
+ int startBitsIndex = bitsIndex;
+ int startElementInBits = elementInBits;
+ calculateElementIndex(end);
+ int endBitsIndex = bitsIndex;
+ int endElementInBits = elementInBits;
+ long range = 0;
+ if (startBitsIndex == endBitsIndex) {
+ range = (-1l >>> (BIT_IN_LONG -(endElementInBits - startElementInBits + 1))) << startElementInBits;
+ size -= Long.bitCount(bits[bitsIndex]);
+ bits[bitsIndex] |= range;
+ size += Long.bitCount(bits[bitsIndex]);
+ } else {
+ range = (-1l >>> startElementInBits) << startElementInBits;
+ size -= Long.bitCount(bits[startBitsIndex]);
+ bits[startBitsIndex] |= range;
+ size += Long.bitCount(bits[startBitsIndex]);
+
+ // endElementInBits + 1 is the number of consecutive ones.
+ // 63 - endElementInBits is the following zeros of the right most one.
+ range = -1l >>> (BIT_IN_LONG - (endElementInBits + 1)) << (63 - endElementInBits);
+ size -= Long.bitCount(bits[endBitsIndex]);
+ bits[endBitsIndex] |= range;
+ size += Long.bitCount(bits[endBitsIndex]);
+ for(int i = (startBitsIndex + 1); i <= (endBitsIndex - 1); i++) {
+ size -= Long.bitCount(bits[i]);
+ bits[i] = -1l;
+ size += Long.bitCount(bits[i]);
+ }
+ }
+ }
+
+ private void calculateElementIndex(E element) {
+ int elementOrdinal = element.ordinal();
+ bitsIndex = elementOrdinal / BIT_IN_LONG;
+ elementInBits = elementOrdinal % BIT_IN_LONG;
+ oldBits = bits[bitsIndex];
+ }
+
+ private int bitsIndex;
+
+ private int elementInBits;
+
+ private long oldBits;
+}
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/EnumSetTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/EnumSetTest.java?view=diff&rev=440652&r1=440651&r2=440652
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/EnumSetTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/EnumSetTest.java Wed Sep 6 01:23:57 2006
@@ -24,6 +24,8 @@
import junit.framework.TestCase;
+import org.apache.harmony.testframework.serialization.SerializationTest;
+
public class EnumSetTest extends TestCase {
static enum EnumWithInnerClass {
@@ -43,6 +45,14 @@
static enum EmptyEnum {
// expected
}
+
+ static enum HugeEnumWithInnerClass {
+ a{}, b{}, c{}, d{}, e{}, f{}, g{}, h{}, i{}, j{}, k{}, l{}, m{}, n{}, o{}, p{}, q{}, r{}, s{}, t{}, u{}, v{}, w{}, x{}, y{}, z{}, A{}, B{}, C{}, D{}, E{}, F{}, G{}, H{}, I{}, J{}, K{}, L{}, M{}, N{}, O{}, P{}, Q{}, R{}, S{}, T{}, U{}, V{}, W{}, X{}, Y{}, Z{}, aa{}, bb{}, cc{}, dd{}, ee{}, ff{}, gg{}, hh{}, ii{}, jj{}, kk{}, ll{}, mm{},
+ }
+
+ static enum HugeEnum {
+ a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z, aa, bb, cc, dd, ee, ff, gg, hh, ii, jj, kk, ll, mm,
+ }
/**
* @tests java.util.EnumSet#noneOf(java.lang.Class)
@@ -75,6 +85,20 @@
EnumSet<EnumWithAllInnerClass> setWithInnerClass = EnumSet
.noneOf(EnumWithAllInnerClass.class);
assertNotNull(setWithInnerClass);
+
+ // test enum type with more than 64 elements
+ Class<HugeEnumWithInnerClass> hc = (Class<HugeEnumWithInnerClass>) HugeEnumWithInnerClass.a
+ .getClass();
+ try {
+ EnumSet.noneOf(hc);
+ fail("Should throw ClassCastException"); //$NON-NLS-1$
+ } catch (ClassCastException e) {
+ // expected
+ }
+
+ EnumSet<HugeEnumWithInnerClass> hugeSetWithInnerClass = EnumSet
+ .noneOf(HugeEnumWithInnerClass.class);
+ assertNotNull(hugeSetWithInnerClass);
}
/**
@@ -112,6 +136,21 @@
EnumSet<EnumFoo> anotherSet = EnumSet.allOf(EnumFoo.class);
assertEquals("Should be equal", enumSet, anotherSet); //$NON-NLS-1$
assertNotSame("Should not be identical", enumSet, anotherSet); //$NON-NLS-1$
+
+ // test enum with more than 64 elements
+ EnumSet<HugeEnum> hugeEnumSet = EnumSet.allOf(HugeEnum.class);
+ assertEquals(65, hugeEnumSet.size());
+
+ assertFalse(hugeEnumSet.contains(null));
+ assertTrue(hugeEnumSet.contains(HugeEnum.a));
+ assertTrue(hugeEnumSet.contains(HugeEnum.b));
+
+ hugeEnumSet.add(HugeEnum.a);
+ assertEquals(65, hugeEnumSet.size());
+
+ EnumSet<HugeEnum> anotherHugeSet = EnumSet.allOf(HugeEnum.class);
+ assertEquals(hugeEnumSet, anotherHugeSet);
+ assertNotSame(hugeEnumSet, anotherHugeSet);
}
@@ -130,6 +169,15 @@
} catch (NullPointerException e) {
// expected
}
+
+ // test enum type with more than 64 elements
+ Set rawSet = set;
+ try {
+ rawSet.add(HugeEnumWithInnerClass.b);
+ fail("Should throw ClassCastException"); //$NON-NLS-1$
+ } catch (ClassCastException e) {
+ // expected
+ }
set.clear();
try {
@@ -150,7 +198,7 @@
set.add(EnumFoo.b);
assertEquals("Size should be 2:", 2, set.size()); //$NON-NLS-1$
- Set rawSet = set;
+ rawSet = set;
try {
rawSet.add(EnumWithAllInnerClass.a);
fail("Should throw ClassCastException"); //$NON-NLS-1$
@@ -171,6 +219,43 @@
} catch(ClassCastException e) {
// expected
}
+
+ // test enum type with more than 64 elements
+ Set<HugeEnum> hugeSet = EnumSet.noneOf(HugeEnum.class);
+ result = hugeSet.add(HugeEnum.a);
+ assertTrue(result);
+
+ result = hugeSet.add(HugeEnum.a);
+ assertFalse(result);
+
+ try {
+ hugeSet.add(null);
+ fail("Should throw NullPointerException"); //$NON-NLS-1$
+ } catch (NullPointerException e) {
+ // expected
+ }
+
+ rawSet = hugeSet;
+ try {
+ rawSet.add(HugeEnumWithInnerClass.b);
+ fail("Should throw ClassCastException"); //$NON-NLS-1$
+ } catch (ClassCastException e) {
+ // expected
+ }
+
+ try {
+ rawSet.add(new Object());
+ fail("Should throw ClassCastException"); //$NON-NLS-1$
+ } catch (ClassCastException e) {
+ // expected
+ }
+
+ result = hugeSet.add(HugeEnum.mm);
+ assertTrue(result);
+ result = hugeSet.add(HugeEnum.mm);
+ assertFalse(result);
+ assertEquals(2, hugeSet.size());
+
}
/**
@@ -258,6 +343,76 @@
anotherSetWithSubclass.remove(EnumWithInnerClass.a);
result = setWithSubclass.addAll(anotherSetWithSubclass);
assertFalse("Should return false", result); //$NON-NLS-1$
+
+ // test enum type with more than 64 elements
+ Set<HugeEnum> hugeSet = EnumSet.noneOf(HugeEnum.class);
+ assertEquals(0, hugeSet.size());
+
+ try {
+ hugeSet.addAll(null);
+ fail("Should throw NullPointerException"); //$NON-NLS-1$
+ } catch (NullPointerException e) {
+ // expected
+ }
+
+ hugeSet = EnumSet.allOf(HugeEnum.class);
+ result = hugeSet.addAll(hugeSet);
+ assertFalse(result);
+
+ hugeSet = EnumSet.noneOf(HugeEnum.class);
+ Collection<HugeEnum> hugeCollection = new ArrayList<HugeEnum>();
+ hugeCollection.add(HugeEnum.a);
+ hugeCollection.add(HugeEnum.b);
+ result = hugeSet.addAll(hugeCollection);
+ assertTrue(result);
+ assertEquals(2, set.size());
+
+ hugeSet = EnumSet.noneOf(HugeEnum.class);
+
+ rawCollection = new ArrayList<Integer>();
+ result = hugeSet.addAll(rawCollection);
+ assertFalse(result);
+ rawCollection.add(1);
+ try {
+ hugeSet.addAll(rawCollection);
+ fail("Should throw ClassCastException"); //$NON-NLS-1$
+ } catch (ClassCastException e) {
+ // expected
+ }
+
+ EnumSet<HugeEnum> aHugeSet = EnumSet.noneOf(HugeEnum.class);
+ aHugeSet.add(HugeEnum.a);
+ aHugeSet.add(HugeEnum.b);
+ result = hugeSet.addAll(aHugeSet);
+ assertTrue(result);
+ assertEquals(2, hugeSet.size());
+
+ try {
+ aHugeSet.addAll(null);
+ fail("Should throw NullPointerException"); //$NON-NLS-1$
+ } catch (NullPointerException e) {
+ // expected
+ }
+
+ Set hugeSetWithSubclass = EnumSet.allOf(HugeEnumWithInnerClass.class);
+ try {
+ hugeSet.addAll(hugeSetWithSubclass);
+ fail("Should throw ClassCastException"); //$NON-NLS-1$
+ } catch (ClassCastException e) {
+ // expected
+ }
+ Set<HugeEnumWithInnerClass> hugeSetWithInnerSubclass = hugeSetWithSubclass;
+ result = hugeSetWithInnerSubclass.addAll(hugeSetWithInnerSubclass);
+ assertFalse(result);
+
+ Set<HugeEnumWithInnerClass> anotherHugeSetWithSubclass = EnumSet
+ .allOf(HugeEnumWithInnerClass.class);
+ result = hugeSetWithSubclass.addAll(anotherHugeSetWithSubclass);
+ assertFalse(result);
+
+ anotherHugeSetWithSubclass.remove(HugeEnumWithInnerClass.a);
+ result = setWithSubclass.addAll(anotherSetWithSubclass);
+ assertFalse(result);
}
@@ -285,6 +440,24 @@
assertFalse("Should return false", result); //$NON-NLS-1$
result = set.remove(EnumWithInnerClass.f);
assertFalse("Should return false", result); //$NON-NLS-1$
+
+ // test enum with more than 64 elements
+ Set<HugeEnum> hugeSet = EnumSet.allOf(HugeEnum.class);
+
+ result = hugeSet.remove(null);
+ assertFalse("'set' does not contain null", result); //$NON-NLS-1$
+
+ result = hugeSet.remove(HugeEnum.a);
+ assertTrue("Should return true", result); //$NON-NLS-1$
+ result = hugeSet.remove(HugeEnum.a);
+ assertFalse("Should return false", result); //$NON-NLS-1$
+
+ assertEquals("Size of set should be 64:", 64, hugeSet.size()); //$NON-NLS-1$
+
+ result = hugeSet.remove(HugeEnumWithInnerClass.a);
+ assertFalse("Should return false", result); //$NON-NLS-1$
+ result = hugeSet.remove(HugeEnumWithInnerClass.f);
+ assertFalse("Should return false", result); //$NON-NLS-1$
}
/**
@@ -326,6 +499,24 @@
set.clear();
assertTrue("Should be equal", set.equals(setWithInnerClass)); //$NON-NLS-1$
+ // test enum type with more than 64 elements
+ Set<HugeEnum> hugeSet = EnumSet.noneOf(HugeEnum.class);
+ assertTrue(hugeSet.equals(set));
+
+ hugeSet = EnumSet.allOf(HugeEnum.class);
+ assertFalse(hugeSet.equals(null));
+ assertFalse(hugeSet.equals(new Object()));
+
+ Set<HugeEnum> anotherHugeSet = EnumSet.allOf(HugeEnum.class);
+ anotherHugeSet.remove(HugeEnum.a);
+ assertFalse(hugeSet.equals(anotherHugeSet));
+
+ Set<HugeEnumWithInnerClass> hugeSetWithInnerClass = EnumSet
+ .allOf(HugeEnumWithInnerClass.class);
+ assertFalse(hugeSet.equals(hugeSetWithInnerClass));
+ hugeSetWithInnerClass.clear();
+ hugeSet.clear();
+ assertTrue(hugeSet.equals(hugeSetWithInnerClass));
}
/**
@@ -340,6 +531,18 @@
set.clear();
assertEquals("Size should be 0", 0, set.size()); //$NON-NLS-1$
+
+ // test enum type with more than 64 elements
+ Set<HugeEnum> hugeSet = EnumSet.allOf(HugeEnum.class);
+ assertEquals(65, hugeSet.size());
+
+ boolean result = hugeSet.contains(HugeEnum.aa);
+ assertTrue(result);
+
+ hugeSet.clear();
+ assertEquals(0, hugeSet.size());
+ result = hugeSet.contains(HugeEnum.aa);
+ assertFalse(result);
}
/**
@@ -350,6 +553,12 @@
set.add(EnumFoo.a);
set.add(EnumFoo.b);
assertEquals("Size should be 2", 2, set.size()); //$NON-NLS-1$
+
+ // test enum type with more than 64 elements
+ Set<HugeEnum> hugeSet = EnumSet.noneOf(HugeEnum.class);
+ hugeSet.add(HugeEnum.a);
+ hugeSet.add(HugeEnum.bb);
+ assertEquals("Size should be 2", 2, hugeSet.size()); //$NON-NLS-1$
}
/**
@@ -382,6 +591,24 @@
complementOfE.contains(EnumWithInnerClass.b));
assertTrue("complementOfE should contain EnumWithSubclass.c:", //$NON-NLS-1$
complementOfE.contains(EnumWithInnerClass.c));
+
+ // test enum type with more than 64 elements
+ EnumSet<HugeEnum> hugeSet = EnumSet.noneOf(HugeEnum.class);
+ assertEquals(0, hugeSet.size());
+ Set<HugeEnum> complementHugeSet = EnumSet.complementOf(hugeSet);
+ assertEquals(65, complementHugeSet.size());
+
+ hugeSet.add(HugeEnum.A);
+ hugeSet.add(HugeEnum.mm);
+ complementHugeSet = EnumSet.complementOf(hugeSet);
+ assertEquals(63, complementHugeSet.size());
+
+ try {
+ EnumSet.complementOf((EnumSet<HugeEnum>) null);
+ fail("Should throw NullPointerException"); //$NON-NLS-1$
+ } catch (NullPointerException npe) {
+ // expected
+ }
}
/**
@@ -428,6 +655,31 @@
setWithSubclass.add(EnumWithInnerClass.f);
result = setWithSubclass.contains(EnumWithInnerClass.f);
assertTrue("Should contain EnumWithSubclass.f", result); //$NON-NLS-1$
+
+ // test enum type with more than 64 elements
+ Set<HugeEnum> hugeSet = EnumSet.allOf(HugeEnum.class);
+ hugeSet.add(HugeEnum.a);
+ result = hugeSet.contains(HugeEnum.a);
+ assertTrue(result);
+
+ result = hugeSet.contains(HugeEnum.b);
+ assertTrue(result);
+
+ result = hugeSet.contains(null);
+ assertFalse(result);
+
+ result = hugeSet.contains(HugeEnum.a);
+ assertTrue(result);
+
+ result = hugeSet.contains(HugeEnum.ll);
+ assertTrue(result);
+
+ result = hugeSet.contains(new Object());
+ assertFalse(result);
+
+ result = hugeSet.contains(Enum.class);
+ assertFalse(result);
+
}
/**
@@ -503,6 +755,82 @@
setWithSubclass.add(EnumWithInnerClass.a);
result = set.containsAll(setWithSubclass);
assertFalse("Should return false", result); //$NON-NLS-1$
+
+ // test enum type with more than 64 elements
+ Set<HugeEnum> hugeSet = EnumSet.noneOf(HugeEnum.class);
+ hugeSet.add(HugeEnum.a);
+ hugeSet.add(HugeEnum.b);
+ hugeSet.add(HugeEnum.aa);
+ hugeSet.add(HugeEnum.bb);
+ hugeSet.add(HugeEnum.cc);
+ hugeSet.add(HugeEnum.dd);
+
+ Set<HugeEnum> anotherHugeSet = EnumSet.noneOf(HugeEnum.class);
+ hugeSet.add(HugeEnum.b);
+ hugeSet.add(HugeEnum.cc);
+ result = hugeSet.containsAll(anotherHugeSet);
+ assertTrue(result);
+
+ try {
+ hugeSet.containsAll(null);
+ fail("Should throw NullPointerException"); //$NON-NLS-1$
+ } catch(NullPointerException e) {
+ // expected
+ }
+
+ Set<HugeEnumWithInnerClass> hugeSetWithInnerClass = EnumSet
+ .noneOf(HugeEnumWithInnerClass.class);
+ hugeSetWithInnerClass.add(HugeEnumWithInnerClass.a);
+ hugeSetWithInnerClass.add(HugeEnumWithInnerClass.b);
+ result = hugeSetWithInnerClass.containsAll(hugeSetWithInnerClass);
+ assertTrue(result);
+ result = hugeSet.containsAll(hugeSetWithInnerClass);
+ assertFalse(result);
+
+ rawCollection = new ArrayList();
+ result = hugeSet.containsAll(rawCollection);
+ assertTrue("Should contain empty collection:", result); //$NON-NLS-1$
+
+ rawCollection.add(1);
+ result = hugeSet.containsAll(rawCollection);
+ assertFalse("Should return false", result); //$NON-NLS-1$
+
+ rawCollection.add(EnumWithInnerClass.a);
+ result = set.containsAll(rawCollection);
+ assertFalse("Should return false", result); //$NON-NLS-1$
+
+ rawSet = EnumSet.noneOf(HugeEnum.class);
+ result = hugeSet.containsAll(rawSet);
+ assertTrue("Should contain empty set", result); //$NON-NLS-1$
+
+ EnumSet<HugeEnumWithInnerClass> emptyHugeSet
+ = EnumSet.noneOf(HugeEnumWithInnerClass.class);
+ result = hugeSet.containsAll(emptyHugeSet);
+ assertTrue("No class cast should be performed on empty set", result); //$NON-NLS-1$
+
+ Collection<HugeEnum> hugeCollection = new ArrayList<HugeEnum>();
+ hugeCollection.add(HugeEnum.a);
+ result = hugeSet.containsAll(hugeCollection);
+ assertTrue("Should contain all elements in collection", result); //$NON-NLS-1$
+
+ hugeSet.clear();
+ try {
+ hugeSet.containsAll(null);
+ fail("Should throw NullPointerException"); //$NON-NLS-1$
+ } catch (NullPointerException e) {
+ // expected
+ }
+
+ Collection<HugeEnumWithInnerClass> hugeCollectionWithSubclass = new ArrayList<HugeEnumWithInnerClass>();
+ hugeCollectionWithSubclass.add(HugeEnumWithInnerClass.a);
+ result = hugeSet.containsAll(hugeCollectionWithSubclass);
+ assertFalse("Should return false", result); //$NON-NLS-1$
+
+ EnumSet<HugeEnumWithInnerClass> hugeSetWithSubclass = EnumSet
+ .noneOf(HugeEnumWithInnerClass.class);
+ hugeSetWithSubclass.add(HugeEnumWithInnerClass.a);
+ result = hugeSet.containsAll(hugeSetWithSubclass);
+ assertFalse("Should return false", result); //$NON-NLS-1$
}
/**
@@ -562,6 +890,34 @@
} catch(ClassCastException e) {
// expected
}
+
+ // test enum type with more than 64 elements
+ Collection<HugeEnum> hugeEnumCollection = new ArrayList<HugeEnum>();
+ hugeEnumCollection.add(HugeEnum.b);
+
+ EnumSet<HugeEnum> copyOfHugeEnumCollection = EnumSet.copyOf(hugeEnumCollection);
+ assertEquals(1, copyOfHugeEnumCollection.size());
+ assertTrue(copyOfHugeEnumCollection.contains(HugeEnum.b));
+
+ hugeEnumCollection.add(null);
+ assertEquals(2, hugeEnumCollection.size());
+
+ try {
+ copyOfHugeEnumCollection = EnumSet.copyOf(hugeEnumCollection);
+ fail("Should throw NullPointerException"); //$NON-NLS-1$
+ } catch (NullPointerException npe) {
+ // expected
+ }
+
+ rawEnumCollection = new ArrayList();
+ rawEnumCollection.add(HugeEnum.a);
+ rawEnumCollection.add(HugeEnumWithInnerClass.a);
+ try {
+ EnumSet.copyOf(rawEnumCollection);
+ fail("Should throw ClassCastException"); //$NON-NLS-1$
+ } catch(ClassCastException e) {
+ // expected
+ }
}
/**
@@ -594,6 +950,21 @@
} catch (NullPointerException npe) {
// expected
}
+
+ // test enum type with more than 64 elements
+ EnumSet<HugeEnumWithInnerClass> hugeEnumSet = EnumSet
+ .noneOf(HugeEnumWithInnerClass.class);
+ hugeEnumSet.add(HugeEnumWithInnerClass.a);
+ hugeEnumSet.add(HugeEnumWithInnerClass.f);
+ EnumSet<HugeEnumWithInnerClass> copyOfHugeEnum = EnumSet.copyOf(hugeEnumSet);
+ assertEquals(enumSet.size(), copyOfE.size());
+
+ assertTrue(copyOfHugeEnum.contains(HugeEnumWithInnerClass.a));
+ assertTrue(copyOfHugeEnum.contains(HugeEnumWithInnerClass.f));
+
+ Object[] hugeEnumValue = copyOfHugeEnum.toArray();
+ assertSame(hugeEnumValue[0], HugeEnumWithInnerClass.a);
+ assertSame(hugeEnumValue[1], HugeEnumWithInnerClass.f);
}
/**
@@ -696,6 +1067,78 @@
result = setWithInnerClass.contains(EnumWithInnerClass.f);
assertTrue("Should return true", result); //$NON-NLS-1$
+
+ // test enum type with more than 64 elements
+ Set<HugeEnum> hugeSet = EnumSet.allOf(HugeEnum.class);
+
+ Collection<HugeEnum> hugeCollection = new ArrayList<HugeEnum>();
+ hugeCollection.add(HugeEnum.a);
+
+ result = hugeSet.removeAll(hugeCollection);
+ assertTrue(result);
+ assertEquals(64, hugeSet.size());
+
+ collection = new ArrayList();
+ result = hugeSet.removeAll(collection);
+ assertFalse(result);
+
+ Set<HugeEnum> emptyHugeSet = EnumSet.noneOf(HugeEnum.class);
+ result = hugeSet.removeAll(emptyHugeSet);
+ assertFalse(result);
+
+ Set<HugeEnumWithInnerClass> hugeSetWithSubclass = EnumSet
+ .noneOf(HugeEnumWithInnerClass.class);
+ result = hugeSet.removeAll(hugeSetWithSubclass);
+ assertFalse(result);
+
+ hugeSetWithSubclass.add(HugeEnumWithInnerClass.a);
+ result = hugeSet.removeAll(hugeSetWithSubclass);
+ assertFalse(result);
+
+ Set<HugeEnum> anotherHugeSet = EnumSet.noneOf(HugeEnum.class);
+ anotherHugeSet.add(HugeEnum.a);
+
+ hugeSet = EnumSet.allOf(HugeEnum.class);
+ result = hugeSet.removeAll(anotherHugeSet);
+ assertTrue(result);
+ assertEquals(63, set.size());
+
+ Set<HugeEnumWithInnerClass> hugeSetWithInnerClass = EnumSet
+ .noneOf(HugeEnumWithInnerClass.class);
+ hugeSetWithInnerClass.add(HugeEnumWithInnerClass.a);
+ hugeSetWithInnerClass.add(HugeEnumWithInnerClass.b);
+
+ Set<HugeEnumWithInnerClass> anotherHugeSetWithInnerClass = EnumSet
+ .noneOf(HugeEnumWithInnerClass.class);
+ anotherHugeSetWithInnerClass.add(HugeEnumWithInnerClass.c);
+ anotherHugeSetWithInnerClass.add(HugeEnumWithInnerClass.d);
+ result = anotherHugeSetWithInnerClass.removeAll(setWithInnerClass);
+ assertFalse("Should return false", result); //$NON-NLS-1$
+
+ anotherHugeSetWithInnerClass.add(HugeEnumWithInnerClass.a);
+ result = anotherHugeSetWithInnerClass.removeAll(hugeSetWithInnerClass);
+ assertTrue(result);
+ assertEquals(2, anotherHugeSetWithInnerClass.size());
+
+ anotherHugeSetWithInnerClass.remove(HugeEnumWithInnerClass.c);
+ anotherHugeSetWithInnerClass.remove(HugeEnumWithInnerClass.d);
+ result = anotherHugeSetWithInnerClass.remove(hugeSetWithInnerClass);
+ assertFalse(result);
+
+ rawSet = EnumSet.allOf(HugeEnumWithInnerClass.class);
+ result = rawSet.removeAll(EnumSet.allOf(HugeEnum.class));
+ assertFalse(result);
+
+ hugeSetWithInnerClass = EnumSet.allOf(HugeEnumWithInnerClass.class);
+ anotherHugeSetWithInnerClass = EnumSet.allOf(HugeEnumWithInnerClass.class);
+ hugeSetWithInnerClass.remove(HugeEnumWithInnerClass.a);
+ anotherHugeSetWithInnerClass.remove(HugeEnumWithInnerClass.f);
+ result = hugeSetWithInnerClass.removeAll(anotherHugeSetWithInnerClass);
+ assertTrue(result);
+ assertEquals(1, hugeSetWithInnerClass.size());
+
+ result = hugeSetWithInnerClass.contains(HugeEnumWithInnerClass.f);
+ assertTrue(result);
}
/**
@@ -795,6 +1238,96 @@
result = set.retainAll(anotherSet);
assertTrue("Should return true", result); //$NON-NLS-1$
assertEquals("size should be 0", 0, set.size()); //$NON-NLS-1$
+
+ // test enum type with more than 64 elements
+ Set<HugeEnum> hugeSet = EnumSet.allOf(HugeEnum.class);
+
+ try {
+ hugeSet.retainAll(null);
+ fail("Should throw NullPointerException"); //$NON-NLS-1$
+ } catch (NullPointerException e) {
+ // expected
+ }
+
+ hugeSet.clear();
+ result = hugeSet.retainAll(null);
+ assertFalse(result);
+
+ rawCollection = new ArrayList();
+ result = hugeSet.retainAll(rawCollection);
+ assertFalse(result);
+
+ rawCollection.add(HugeEnum.a);
+ result = hugeSet.retainAll(rawCollection);
+ assertFalse(result);
+
+ rawCollection.add(HugeEnumWithInnerClass.a);
+ result = hugeSet.retainAll(rawCollection);
+ assertFalse(result);
+ assertEquals(0, set.size());
+
+ rawCollection.remove(HugeEnum.a);
+ result = set.retainAll(rawCollection);
+ assertFalse(result);
+
+ Set<HugeEnum> anotherHugeSet = EnumSet.allOf(HugeEnum.class);
+ result = hugeSet.retainAll(anotherHugeSet);
+ assertFalse(result);
+ assertEquals(0, hugeSet.size());
+
+ Set<HugeEnumWithInnerClass> hugeSetWithInnerClass = EnumSet
+ .allOf(HugeEnumWithInnerClass.class);
+ result = hugeSet.retainAll(hugeSetWithInnerClass);
+ assertTrue(result);
+ assertEquals(0, hugeSet.size());
+
+ hugeSetWithInnerClass = EnumSet.noneOf(HugeEnumWithInnerClass.class);
+ result = hugeSet.retainAll(hugeSetWithInnerClass);
+ assertTrue(result);
+
+ Set<HugeEnumWithInnerClass> hugeSetWithAllInnerClass = EnumSet
+ .allOf(HugeEnumWithInnerClass.class);
+ result = hugeSet.retainAll(hugeSetWithAllInnerClass);
+ assertTrue(result);
+
+ hugeSet.add(HugeEnum.a);
+ result = hugeSet.retainAll(hugeSetWithInnerClass);
+ assertTrue(result);
+ assertEquals(0, hugeSet.size());
+
+ hugeSetWithInnerClass = EnumSet.allOf(HugeEnumWithInnerClass.class);
+ hugeSetWithInnerClass.remove(HugeEnumWithInnerClass.f);
+ Set<HugeEnumWithInnerClass> anotherHugeSetWithInnerClass = EnumSet
+ .noneOf(HugeEnumWithInnerClass.class);
+ anotherHugeSetWithInnerClass.add(HugeEnumWithInnerClass.e);
+ anotherHugeSetWithInnerClass.add(HugeEnumWithInnerClass.f);
+
+ result = hugeSetWithInnerClass.retainAll(anotherHugeSetWithInnerClass);
+ assertTrue(result);
+ result = hugeSetWithInnerClass.contains(HugeEnumWithInnerClass.e);
+ assertTrue("Should contain HugeEnumWithInnerClass.e", result); //$NON-NLS-1$
+ result = hugeSetWithInnerClass.contains(HugeEnumWithInnerClass.b);
+ assertFalse("Should not contain HugeEnumWithInnerClass.b", result); //$NON-NLS-1$
+ assertEquals("Size of hugeSet should be 1:", 1, hugeSetWithInnerClass.size()); //$NON-NLS-1$
+
+ anotherHugeSetWithInnerClass = EnumSet.allOf(HugeEnumWithInnerClass.class);
+ result = hugeSetWithInnerClass.retainAll(anotherHugeSetWithInnerClass);
+
+ assertFalse("Return value should be false", result); //$NON-NLS-1$
+
+ rawCollection = new ArrayList();
+ rawCollection.add(HugeEnumWithInnerClass.e);
+ rawCollection.add(HugeEnumWithInnerClass.f);
+ result = hugeSetWithInnerClass.retainAll(rawCollection);
+ assertFalse(result);
+
+ hugeSet = EnumSet.allOf(HugeEnum.class);
+ hugeSet.remove(HugeEnum.a);
+ anotherHugeSet = EnumSet.noneOf(HugeEnum.class);
+ anotherHugeSet.add(HugeEnum.a);
+ result = hugeSet.retainAll(anotherHugeSet);
+ assertTrue(result);
+ assertEquals(0, hugeSet.size());
}
/**
@@ -920,6 +1453,98 @@
// RI's bug, EnumFoo.b should not exist at the moment.
assertFalse("Should return false", set.contains(EnumFoo.b)); //$NON-NLS-1$
+ // test enum type with more than 64 elements
+ Set<HugeEnum> hugeSet = EnumSet.noneOf(HugeEnum.class);
+ hugeSet.add(HugeEnum.a);
+ hugeSet.add(HugeEnum.b);
+
+ Iterator<HugeEnum> hIterator = hugeSet.iterator();
+ Iterator<HugeEnum> anotherHugeIterator = hugeSet.iterator();
+ assertNotSame(hIterator, anotherHugeIterator);
+ try {
+ hIterator.remove();
+ fail("Should throw IllegalStateException"); //$NON-NLS-1$
+ } catch (IllegalStateException e) {
+ // expectedd
+ }
+
+ assertTrue(hIterator.hasNext());
+ assertSame(HugeEnum.a, hIterator.next());
+ hIterator.remove();
+ assertTrue(hIterator.hasNext());
+ assertSame(HugeEnum.b, hIterator.next());
+ assertFalse(hIterator.hasNext());
+ assertFalse(hIterator.hasNext());
+
+ assertEquals(1, hugeSet.size());
+
+ try {
+ hIterator.next();
+ fail("Should throw NoSuchElementException"); //$NON-NLS-1$
+ } catch (NoSuchElementException e) {
+ // expected
+ }
+
+ Set<HugeEnumWithInnerClass> hugeSetWithSubclass = EnumSet
+ .allOf(HugeEnumWithInnerClass.class);
+ hugeSetWithSubclass.remove(HugeEnumWithInnerClass.e);
+ Iterator<HugeEnumWithInnerClass> hugeIteratorWithSubclass = hugeSetWithSubclass
+ .iterator();
+ assertSame(HugeEnumWithInnerClass.a, hugeIteratorWithSubclass.next());
+
+ assertTrue(hugeIteratorWithSubclass.hasNext());
+ assertSame(HugeEnumWithInnerClass.b, hugeIteratorWithSubclass.next());
+
+ setWithSubclass.remove(HugeEnumWithInnerClass.c);
+ assertTrue(hugeIteratorWithSubclass.hasNext());
+ assertSame(HugeEnumWithInnerClass.c, hugeIteratorWithSubclass.next());
+
+ assertTrue(hugeIteratorWithSubclass.hasNext());
+ assertSame(HugeEnumWithInnerClass.d, hugeIteratorWithSubclass.next());
+
+ hugeSetWithSubclass.add(HugeEnumWithInnerClass.e);
+ assertTrue(hugeIteratorWithSubclass.hasNext());
+ assertSame(HugeEnumWithInnerClass.f, hugeIteratorWithSubclass.next());
+
+ hugeSet = EnumSet.noneOf(HugeEnum.class);
+ hIterator = hugeSet.iterator();
+ try {
+ hIterator.next();
+ fail("Should throw NoSuchElementException"); //$NON-NLS-1$
+ } catch (NoSuchElementException e) {
+ // expected
+ }
+
+ hugeSet.add(HugeEnum.a);
+ hIterator = hugeSet.iterator();
+ assertEquals(HugeEnum.a, hIterator.next());
+ assertEquals(1, hugeSet.size());
+ hIterator.remove();
+ assertEquals(0, hugeSet.size());
+ assertFalse(hugeSet.contains(HugeEnum.a));
+
+ hugeSet.add(HugeEnum.a);
+ hugeSet.add(HugeEnum.b);
+ hIterator = hugeSet.iterator();
+ hIterator.next();
+ hIterator.remove();
+
+ assertTrue(hIterator.hasNext());
+ try {
+ hIterator.remove();
+ fail("Should throw IllegalStateException"); //$NON-NLS-1$
+ } catch (IllegalStateException e) {
+ // expected
+ }
+ assertEquals(1, hugeSet.size());
+ assertTrue(hIterator.hasNext());
+ assertEquals(HugeEnum.b, hIterator.next());
+ hugeSet.remove(HugeEnum.b);
+ assertEquals(0, hugeSet.size());
+ hIterator.remove();
+ assertFalse(hugeSet.contains(HugeEnum.a));
+ // RI's bug, EnumFoo.b should not exist at the moment.
+ assertFalse("Should return false", set.contains(EnumFoo.b)); //$NON-NLS-1$
}
/**
@@ -938,6 +1563,12 @@
} catch (NullPointerException npe) {
// expected
}
+
+ // test enum type with more than 64 elements
+ EnumSet<HugeEnumWithInnerClass> hugeEnumSet = EnumSet.of(HugeEnumWithInnerClass.a);
+ assertEquals(1, hugeEnumSet.size());
+
+ assertTrue(hugeEnumSet.contains(HugeEnumWithInnerClass.a));
}
/**
@@ -977,6 +1608,38 @@
enumSet = EnumSet.of(EnumWithInnerClass.a, EnumWithInnerClass.a);
assertEquals("Size of enumSet should be 1", //$NON-NLS-1$
1, enumSet.size());
+
+ // test enum type with more than 64 elements
+ EnumSet<HugeEnumWithInnerClass> hugeEnumSet = EnumSet.of(HugeEnumWithInnerClass.a,
+ HugeEnumWithInnerClass.b);
+ assertEquals(2, hugeEnumSet.size());
+
+ assertTrue(hugeEnumSet.contains(HugeEnumWithInnerClass.a));
+ assertTrue(hugeEnumSet.contains(HugeEnumWithInnerClass.b));
+
+ try {
+ EnumSet.of((HugeEnumWithInnerClass) null, HugeEnumWithInnerClass.a);
+ fail("Should throw NullPointerException"); //$NON-NLS-1$
+ } catch (NullPointerException npe) {
+ // expected
+ }
+
+ try {
+ EnumSet.of( HugeEnumWithInnerClass.a, (HugeEnumWithInnerClass) null);
+ fail("Should throw NullPointerException"); //$NON-NLS-1$
+ } catch (NullPointerException npe) {
+ // expected
+ }
+
+ try {
+ EnumSet.of( (HugeEnumWithInnerClass) null, (HugeEnumWithInnerClass) null);
+ fail("Should throw NullPointerException"); //$NON-NLS-1$
+ } catch (NullPointerException npe) {
+ // expected
+ }
+
+ hugeEnumSet = EnumSet.of(HugeEnumWithInnerClass.a, HugeEnumWithInnerClass.a);
+ assertEquals(1, hugeEnumSet.size());
}
/**
@@ -1001,6 +1664,25 @@
enumSet = EnumSet.of(EnumWithInnerClass.a, EnumWithInnerClass.b,
EnumWithInnerClass.b);
assertEquals("enumSet should contain 2 elements:", 2, enumSet.size()); //$NON-NLS-1$
+
+ // test enum type with more than 64 elements
+ EnumSet<HugeEnumWithInnerClass> hugeEnumSet = EnumSet.of(HugeEnumWithInnerClass.a,
+ HugeEnumWithInnerClass.b, HugeEnumWithInnerClass.c);
+ assertEquals(3, hugeEnumSet.size());
+
+ assertTrue(hugeEnumSet.contains(HugeEnumWithInnerClass.a));
+ assertTrue(hugeEnumSet.contains(HugeEnumWithInnerClass.c));
+
+ try {
+ EnumSet.of((HugeEnumWithInnerClass) null, null, null);
+ fail("Should throw NullPointerException"); //$NON-NLS-1$
+ } catch (NullPointerException npe) {
+ // expected
+ }
+
+ hugeEnumSet = EnumSet.of(HugeEnumWithInnerClass.a, HugeEnumWithInnerClass.b,
+ HugeEnumWithInnerClass.b);
+ assertEquals(2, hugeEnumSet.size());
}
/**
@@ -1023,6 +1705,22 @@
} catch (NullPointerException npe) {
// expected
}
+
+ // test enum type with more than 64 elements
+ EnumSet<HugeEnumWithInnerClass> hugeEnumSet = EnumSet.of(HugeEnumWithInnerClass.a,
+ HugeEnumWithInnerClass.b, HugeEnumWithInnerClass.c,
+ HugeEnumWithInnerClass.d);
+ assertEquals(4, hugeEnumSet.size());
+
+ assertTrue(hugeEnumSet.contains(HugeEnumWithInnerClass.a));
+ assertTrue(hugeEnumSet.contains(HugeEnumWithInnerClass.d));
+
+ try {
+ EnumSet.of((HugeEnumWithInnerClass) null, null, null, null);
+ fail("Should throw NullPointerException"); //$NON-NLS-1$
+ } catch (NullPointerException npe) {
+ // expected
+ }
}
/**
@@ -1043,6 +1741,22 @@
} catch (NullPointerException npe) {
// expected
}
+
+ // test enum with more than 64 elements
+ EnumSet<HugeEnumWithInnerClass> hugeEnumSet = EnumSet.of(HugeEnumWithInnerClass.a,
+ HugeEnumWithInnerClass.b, HugeEnumWithInnerClass.c,
+ HugeEnumWithInnerClass.d, HugeEnumWithInnerClass.e);
+ assertEquals(5, hugeEnumSet.size());
+
+ assertTrue(hugeEnumSet.contains(HugeEnumWithInnerClass.a));
+ assertTrue(hugeEnumSet.contains(HugeEnumWithInnerClass.e));
+
+ try {
+ EnumSet.of((HugeEnumWithInnerClass) null, null, null, null, null);
+ fail("Should throw NullPointerException"); //$NON-NLS-1$
+ } catch (NullPointerException npe) {
+ // expected
+ }
}
/**
@@ -1071,6 +1785,30 @@
assertTrue("Should contain EnumFoo.a", set.contains(EnumFoo.a)); //$NON-NLS-1$
assertTrue("Should contain EnumFoo.c", set.contains(EnumFoo.c)); //$NON-NLS-1$
assertTrue("Should contain EnumFoo.d", set.contains(EnumFoo.d)); //$NON-NLS-1$
+
+ // test enum type with more than 64 elements
+ HugeEnumWithInnerClass[] hugeEnumArray = new HugeEnumWithInnerClass[] {
+ HugeEnumWithInnerClass.b, HugeEnumWithInnerClass.c };
+ EnumSet<HugeEnumWithInnerClass> hugeEnumSet = EnumSet.of(HugeEnumWithInnerClass.a,
+ hugeEnumArray);
+ assertEquals(3, hugeEnumSet.size());
+
+ assertTrue(hugeEnumSet.contains(HugeEnumWithInnerClass.a));
+ assertTrue(hugeEnumSet.contains(HugeEnumWithInnerClass.c));
+
+ try {
+ EnumSet.of(HugeEnumWithInnerClass.a, (HugeEnumWithInnerClass[])null);
+ fail("Should throw NullPointerException"); //$NON-NLS-1$
+ } catch (NullPointerException npe) {
+ // expected
+ }
+
+ HugeEnumWithInnerClass[] huges = {HugeEnumWithInnerClass.a, HugeEnumWithInnerClass.c, HugeEnumWithInnerClass.d};
+ EnumSet<HugeEnumWithInnerClass> hugeSet = EnumSet.of(HugeEnumWithInnerClass.c, huges);
+ assertEquals(3, hugeSet.size());
+ assertTrue(hugeSet.contains(HugeEnumWithInnerClass.a));
+ assertTrue(hugeSet.contains(HugeEnumWithInnerClass.c));
+ assertTrue(hugeSet.contains(HugeEnumWithInnerClass.d));
}
/**
@@ -1108,6 +1846,99 @@
EnumSet<EnumWithInnerClass> enumSet = EnumSet.range(
EnumWithInnerClass.a, EnumWithInnerClass.a);
assertEquals("Size of enumSet should be 1", 1, enumSet.size()); //$NON-NLS-1$
+
+ enumSet = EnumSet.range(
+ EnumWithInnerClass.a, EnumWithInnerClass.c);
+ assertEquals("Size of enumSet should be 3", 3, enumSet.size()); //$NON-NLS-1$
+
+ // test enum with more than 64 elements
+ try {
+ EnumSet.range(HugeEnumWithInnerClass.c, null);
+ fail("Should throw NullPointerException"); //$NON-NLS-1$
+ } catch (NullPointerException e) {
+ // expected
+ }
+
+ try {
+ EnumSet.range(null, HugeEnumWithInnerClass.c);
+ fail("Should throw NullPointerException"); //$NON-NLS-1$
+ } catch (NullPointerException e) {
+ // expected
+ }
+ try {
+ EnumSet.range(null, (HugeEnumWithInnerClass) null);
+ fail("Should throw NullPointerException"); //$NON-NLS-1$
+ } catch (NullPointerException e) {
+ // expected
+ }
+
+ try {
+ EnumSet.range(HugeEnumWithInnerClass.b, HugeEnumWithInnerClass.a);
+ fail("Should throw IllegalArgumentException"); //$NON-NLS-1$
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+
+ EnumSet<HugeEnumWithInnerClass> hugeEnumSet = EnumSet.range(
+ HugeEnumWithInnerClass.a, HugeEnumWithInnerClass.a);
+ assertEquals(1, hugeEnumSet.size());
+
+ hugeEnumSet = EnumSet.range(
+ HugeEnumWithInnerClass.c, HugeEnumWithInnerClass.aa);
+ assertEquals(51, hugeEnumSet.size());
+
+ hugeEnumSet = EnumSet.range(
+ HugeEnumWithInnerClass.a, HugeEnumWithInnerClass.mm);
+ assertEquals(65, hugeEnumSet.size());
+
+ hugeEnumSet = EnumSet.range(
+ HugeEnumWithInnerClass.b, HugeEnumWithInnerClass.mm);
+ assertEquals(64, hugeEnumSet.size());
+ }
+
+ /**
+ * @tests java.util.EnumSet#clone()
+ */
+ public void test_Clone() {
+ EnumSet<EnumFoo> enumSet = EnumSet.allOf(EnumFoo.class);
+ EnumSet<EnumFoo> clonedEnumSet = enumSet.clone();
+ assertEquals(enumSet, clonedEnumSet);
+ assertNotSame(enumSet, clonedEnumSet);
+ assertTrue(clonedEnumSet.contains(EnumFoo.a));
+ assertTrue(clonedEnumSet.contains(EnumFoo.b));
+ assertEquals(64, clonedEnumSet.size());
+
+ // test enum type with more than 64 elements
+ EnumSet<HugeEnum> hugeEnumSet = EnumSet.allOf(HugeEnum.class);
+ EnumSet<HugeEnum> hugeClonedEnumSet = hugeEnumSet.clone();
+ assertEquals(hugeEnumSet, hugeClonedEnumSet);
+ assertNotSame(hugeEnumSet, hugeClonedEnumSet);
+ assertTrue(hugeClonedEnumSet.contains(HugeEnum.a));
+ assertTrue(hugeClonedEnumSet.contains(HugeEnum.b));
+ assertEquals(65, hugeClonedEnumSet.size());
+
+ hugeClonedEnumSet.remove(HugeEnum.a);
+ assertEquals(64, hugeClonedEnumSet.size());
+ assertFalse(hugeClonedEnumSet.contains(HugeEnum.a));
+ assertEquals(65, hugeEnumSet.size());
+ assertTrue(hugeEnumSet.contains(HugeEnum.a));
+ }
+
+ /**
+ * @tests java.util.EnumSet#Serialization()
+ */
+ public void test_serialization() throws Exception {
+ EnumSet<EnumFoo> set = EnumSet.allOf(EnumFoo.class);
+ SerializationTest.verifySelf(set);
+ }
+
+ /**
+ * @tests serialization/deserialization compatibility with RI.
+ */
+ @SuppressWarnings( { "unchecked", "boxing" })
+ public void testSerializationCompatibility() throws Exception {
+ EnumSet<EnumFoo> set = EnumSet.allOf(EnumFoo.class);
+ SerializationTest.verifyGolden(this, set);
}
}
Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/resources/serialization/tests/api/java/util/EnumSetTest.golden.ser
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/resources/serialization/tests/api/java/util/EnumSetTest.golden.ser?view=auto&rev=440652
==============================================================================
Binary file - no diff available.
Propchange: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/resources/serialization/tests/api/java/util/EnumSetTest.golden.ser
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
|