29package com.jogamp.common.util;
32import java.io.IOException;
34import org.junit.Assert;
37import com.jogamp.junit.util.SingletonJunitCase;
39import org.junit.FixMethodOrder;
40import org.junit.runners.MethodSorters;
42@FixMethodOrder(MethodSorters.NAME_ASCENDING)
48 public Dummy(
final int i1,
final int i2,
final int i3) {
54 public boolean equals(
final Object o) {
55 if(o instanceof
Dummy) {
57 return this.i1 == d.i1 &&
67 hash = ((hash << 5) - hash) + i2;
68 hash = ((hash << 5) - hash) + i3;
73 return "Dummy["+super.toString()+
": "+i1+
", "+i2+
", "+i3+
"]";
77 void populate(
final List<Dummy> l,
final int start,
final int len,
78 final int i2,
final int i3,
final int expectedPlusSize) {
79 final int oldSize = l.size();
80 for(
int pos = start+len-1; pos>=start; pos--) {
81 l.add(
new Dummy(pos, i2, i3));
83 Assert.assertEquals(expectedPlusSize, l.size() - oldSize);
85 boolean checkOrder(
final List<Dummy> l,
final int startIdx,
final int start,
final int len) {
86 for(
int i=0; i<len; i++) {
87 final Dummy d = l.get(startIdx+i);
88 final int i1 = start+len-1-i;
98 testArrayHashSetImpl(
true);
102 testArrayHashSetImpl(
false);
104 void testArrayHashSetImpl(
final boolean supportNullValue) {
110 final int p7_22_34_idx;
111 final Dummy p7_22_34_orig;
112 final int p6_22_34_idx;
113 final Dummy p6_22_34_orig;
115 populate(l, 10, 100, 22, 34, 100);
116 Assert.assertTrue(checkOrder(l, 0, 10, 100));
117 populate(l, 10, 100, 22, 34, 0);
118 Assert.assertTrue(checkOrder(l, 0, 10, 100));
119 populate(l, 6, 5, 22, 34, 4);
120 Assert.assertTrue(checkOrder(l, 100, 6, 4));
121 p7_22_34_idx = l.
size() - 2;
122 p7_22_34_orig = l.
get(p7_22_34_idx);
123 p6_22_34_idx = l.
size() - 1;
124 p6_22_34_orig = l.
get(p6_22_34_idx);
126 Assert.assertNotNull(p7_22_34_orig);
127 Assert.assertEquals(7, p7_22_34_orig.i1);
128 Assert.assertEquals(l.
getData().get(p7_22_34_idx), p7_22_34_orig);
129 Assert.assertNotNull(p6_22_34_orig);
130 Assert.assertEquals(6, p6_22_34_orig.i1);
131 Assert.assertEquals(l.
getData().get(p6_22_34_idx), p6_22_34_orig);
133 final Dummy p7_22_34_other =
new Dummy(7, 22, 34);
134 Assert.assertEquals(p7_22_34_other, p7_22_34_orig);
135 Assert.assertTrue(p7_22_34_other.hashCode() == p7_22_34_orig.hashCode());
136 Assert.assertTrue(p7_22_34_other != p7_22_34_orig);
137 final Dummy p6_22_34_other =
new Dummy(6, 22, 34);
138 Assert.assertEquals(p6_22_34_other, p6_22_34_orig);
139 Assert.assertTrue(p6_22_34_other.hashCode() == p6_22_34_orig.hashCode());
140 Assert.assertTrue(p6_22_34_other != p6_22_34_orig);
143 final int i = l.
indexOf(p6_22_34_other);
145 Assert.assertNotNull(q);
146 Assert.assertEquals(p6_22_34_other, q);
147 Assert.assertTrue(p6_22_34_other.hashCode() == q.hashCode());
148 Assert.assertTrue(p6_22_34_other != q);
149 Assert.assertTrue(p6_22_34_orig == q);
152 q = l.
get(p6_22_34_other);
153 Assert.assertNotNull(q);
154 Assert.assertEquals(p6_22_34_other, q);
155 Assert.assertTrue(p6_22_34_other.hashCode() == q.hashCode());
156 Assert.assertTrue(p6_22_34_other != q);
157 Assert.assertTrue(p6_22_34_orig == q);
159 Assert.assertTrue(!l.
add(q));
160 Assert.assertTrue(!l.
add(p6_22_34_other));
163 Assert.assertNotNull(q);
164 Assert.assertEquals(p6_22_34_other, q);
165 Assert.assertTrue(p6_22_34_other.hashCode() == q.hashCode());
166 Assert.assertTrue(p6_22_34_other != q);
167 Assert.assertTrue(p6_22_34_orig == q);
168 Assert.assertTrue(checkOrder(l, 0, 10, 100));
169 Assert.assertTrue(checkOrder(l, 100, 6, 4));
171 final Dummy p1_2_3 =
new Dummy(1, 2, 3);
173 Assert.assertNotNull(q);
174 Assert.assertEquals(p1_2_3, q);
175 Assert.assertTrue(p1_2_3.hashCode() == q.hashCode());
176 Assert.assertTrue(p1_2_3 == q);
177 Assert.assertTrue(checkOrder(l, 0, 10, 100));
178 Assert.assertTrue(checkOrder(l, 100, 6, 4));
180 final Dummy pNull =
null;
181 NullPointerException npe =
null;
184 Assert.assertNull(q);
185 }
catch (
final NullPointerException _npe) { npe = _npe; }
187 Assert.assertNull(npe);
189 Assert.assertNotNull(npe);
193 Assert.assertTrue(l.
remove(pNull));
194 }
catch (
final NullPointerException _npe) { npe = _npe; }
196 Assert.assertNull(npe);
198 Assert.assertNotNull(npe);
202 public static void main(
final String args[])
throws IOException {
204 org.junit.runner.JUnitCore.
main(tstname);
Hashed ArrayList implementation of the List and Collection interface.
final ArrayList< E > getData()
Returns this object ordered ArrayList.
final E getOrAdd(final E element)
Identity method allowing to get the identical object, using the internal hash map.
static final float DEFAULT_LOAD_FACTOR
Default load factor: {@value}.
final boolean supportsNullValue()
Returns true for default behavior, i.e.
final int indexOf(final Object element)
final boolean remove(final Object element)
Remove element from this list.
final boolean add(final E element)
Add element at the end of this list, if it is not contained yet.
final E get(final int index)
static final int DEFAULT_INITIAL_CAPACITY
The default initial capacity: {@value}.
boolean equals(final Object o)
Dummy(final int i1, final int i2, final int i3)
static void main(final String args[])
void test02ArrayHashSetWithoutNullValue()
void test01ArrayHashSetWithNullValue()