use of java.util.concurrent.CopyOnWriteArraySet in project mapdb by jankotek.
the class CopyOnWriteArraySetTest method testConstructor3.
/**
* Collection-constructed set holds all of its elements
*/
public void testConstructor3() {
Integer[] ints = new Integer[SIZE];
for (int i = 0; i < SIZE - 1; ++i) ints[i] = new Integer(i);
CopyOnWriteArraySet a = new CopyOnWriteArraySet(Arrays.asList(ints));
for (int i = 0; i < SIZE; ++i) assertTrue(a.contains(ints[i]));
}
use of java.util.concurrent.CopyOnWriteArraySet in project mapdb by jankotek.
the class CopyOnWriteArraySetTest method testToString.
/**
* toString holds toString of elements
*/
public void testToString() {
assertEquals("[]", new CopyOnWriteArraySet().toString());
Collection full = populatedSet(3);
String s = full.toString();
for (int i = 0; i < 3; ++i) assertTrue(s.contains(String.valueOf(i)));
assertEquals(new ArrayList(full).toString(), full.toString());
}
use of java.util.concurrent.CopyOnWriteArraySet in project mapdb by jankotek.
the class CopyOnWriteArraySetTest method testToArray2.
/**
* toArray(Integer array) returns an Integer array containing all
* elements from the set in insertion order
*/
public void testToArray2() {
Collection empty = new CopyOnWriteArraySet();
Integer[] a;
a = new Integer[0];
assertSame(a, empty.toArray(a));
a = new Integer[SIZE / 2];
Arrays.fill(a, 42);
assertSame(a, empty.toArray(a));
assertNull(a[0]);
for (int i = 1; i < a.length; i++) assertEquals(42, (int) a[i]);
Integer[] elements = new Integer[SIZE];
for (int i = 0; i < SIZE; i++) elements[i] = i;
Collections.shuffle(Arrays.asList(elements));
Collection<Integer> full = populatedSet(elements);
Arrays.fill(a, 42);
assertTrue(Arrays.equals(elements, full.toArray(a)));
for (int i = 0; i < a.length; i++) assertEquals(42, (int) a[i]);
assertSame(Integer[].class, full.toArray(a).getClass());
a = new Integer[SIZE];
Arrays.fill(a, 42);
assertSame(a, full.toArray(a));
assertTrue(Arrays.equals(elements, a));
a = new Integer[2 * SIZE];
Arrays.fill(a, 42);
assertSame(a, full.toArray(a));
assertTrue(Arrays.equals(elements, Arrays.copyOf(a, SIZE)));
assertNull(a[SIZE]);
for (int i = SIZE + 1; i < a.length; i++) assertEquals(42, (int) a[i]);
}
use of java.util.concurrent.CopyOnWriteArraySet in project mapdb by jankotek.
the class CopyOnWriteArraySetTest method testIterator.
/**
* iterator() returns an iterator containing the elements of the
* set in insertion order
*/
public void testIterator() {
Collection empty = new CopyOnWriteArraySet();
assertFalse(empty.iterator().hasNext());
try {
empty.iterator().next();
shouldThrow();
} catch (NoSuchElementException success) {
}
Integer[] elements = new Integer[SIZE];
for (int i = 0; i < SIZE; i++) elements[i] = i;
Collections.shuffle(Arrays.asList(elements));
Collection<Integer> full = populatedSet(elements);
Iterator it = full.iterator();
for (int j = 0; j < SIZE; j++) {
assertTrue(it.hasNext());
assertEquals(elements[j], it.next());
}
assertIteratorExhausted(it);
}
use of java.util.concurrent.CopyOnWriteArraySet in project mapdb by jankotek.
the class CopyOnWriteArraySetTest method testAddAll_idempotent.
/**
* addAll is idempotent
*/
public void testAddAll_idempotent() throws Exception {
Set x = populatedSet(SIZE);
Set y = new CopyOnWriteArraySet(x);
y.addAll(x);
assertEquals(x, y);
assertEquals(y, x);
}
Aggregations