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 Map<Integer, 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.put(pos,
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 testArrayHashMapImpl(
true);
102 testArrayHashMapImpl(
false);
104 void testArrayHashMapImpl(
final boolean supportNullValue) {
110 final int p7_22_34_key, p7_22_34_idx;
111 final Dummy p7_22_34_orig;
112 final int p6_22_34_key, p6_22_34_idx;
113 final Dummy p6_22_34_orig;
115 populate(l, 10, 100, 22, 34, 100);
116 Assert.assertTrue(checkOrder(l.
getData(), 0, 10, 100));
117 populate(l, 10, 100, 22, 34, 0);
118 Assert.assertTrue(checkOrder(l.
getData(), 0, 10, 100));
119 populate(l, 6, 5, 22, 34, 4);
120 Assert.assertTrue(checkOrder(l.
getData(), 100, 6, 4));
121 p7_22_34_idx = l.
size() - 2;
123 p7_22_34_orig = l.
get(p7_22_34_key);
124 p6_22_34_idx = l.
size() - 1;
126 p6_22_34_orig = l.
get(p6_22_34_key);
128 Assert.assertNotNull(p7_22_34_orig);
129 Assert.assertEquals(7, p7_22_34_orig.i1);
130 Assert.assertEquals(l.
getData().get(p7_22_34_idx), p7_22_34_orig);
131 Assert.assertNotNull(p6_22_34_orig);
132 Assert.assertEquals(6, p6_22_34_orig.i1);
133 Assert.assertEquals(l.
getData().get(p6_22_34_idx), p6_22_34_orig);
135 final Dummy p7_22_34_other =
new Dummy(7, 22, 34);
136 Assert.assertEquals(p7_22_34_other, p7_22_34_orig);
137 Assert.assertTrue(p7_22_34_other.hashCode() == p7_22_34_orig.hashCode());
138 Assert.assertTrue(p7_22_34_other != p7_22_34_orig);
139 final Dummy p6_22_34_other =
new Dummy(6, 22, 34);
140 Assert.assertEquals(p6_22_34_other, p6_22_34_orig);
141 Assert.assertTrue(p6_22_34_other.hashCode() == p6_22_34_orig.hashCode());
142 Assert.assertTrue(p6_22_34_other != p6_22_34_orig);
145 Dummy q = l.
get(p6_22_34_key);
146 Assert.assertNotNull(q);
147 Assert.assertEquals(p6_22_34_other, q);
148 Assert.assertTrue(p6_22_34_other.hashCode() == q.hashCode());
149 Assert.assertTrue(p6_22_34_other != q);
150 Assert.assertTrue(p6_22_34_orig == q);
155 q = l.
put(p6_22_34_key, p6_22_34_other);
156 Assert.assertNotNull(q);
157 Assert.assertEquals(p6_22_34_other, q);
158 Assert.assertTrue(p6_22_34_other.hashCode() == q.hashCode());
159 Assert.assertTrue(p6_22_34_other != q);
160 Assert.assertTrue(p6_22_34_orig == q);
161 Assert.assertTrue(checkOrder(l.
getData(), 0, 10, 100));
162 Assert.assertTrue(checkOrder(l.
getData(), 100, 6, 4));
164 final Dummy p1_2_3 =
new Dummy(1, 2, 3);
165 q = l.
put(1, p1_2_3);
166 Assert.assertNull(q);
168 final Dummy pNull =
null;
169 NullPointerException npe =
null;
172 Assert.assertNull(q);
173 }
catch (
final NullPointerException _npe) { npe = _npe; }
175 Assert.assertNull(npe);
177 Assert.assertNotNull(npe);
181 public static void main(
final String args[])
throws IOException {
183 org.junit.runner.JUnitCore.
main(tstname);
HashMap implementation backed by an ArrayList to preserve order of values.
final boolean supportsNullValue()
Returns true for default behavior, i.e.
boolean containsValue(final Object value)
final ArrayList< V > getData()
Returns this object ordered ArrayList.
final V get(final Object key)
final V put(final K key, final V value)
Hashed ArrayList implementation of the List and Collection interface.
static final float DEFAULT_LOAD_FACTOR
Default load factor: {@value}.
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)
void test01ArrayHashMapWithNullValue()
void test02ArrayHashSetWithoutNullValue()
static void main(final String args[])