/** Runs a test on the hsqldb lists */
public void testLists() {
HsqlArrayList arrayList = new HsqlArrayList();
HsqlDeque deque = new HsqlDeque();
Vector vector = new Vector();
Vector listCommandsCalled = new Vector(NUMBER_OF_ITERATIONS_PER_RUN);
Integer tempInt = null;
int tempCommandCode;
int tempPosition;
boolean arrayListException = false;
boolean dequeException = false;
boolean vectorException = false;
Object arrayListObject = null;
Object linkedListObject = null;
Object vectorObject = null;
for (int i = 0; i < getRandomInt(3, 12); i++) { // prime the contents with a couple items
tempInt = getRandomInteger();
arrayList.add(tempInt);
deque.add(tempInt);
vector.addElement(tempInt);
listCommandsCalled.addElement("Add");
}
compareLists(arrayList, deque, vector);
for (int j = 0; j < NUMBER_OF_ITERATIONS_PER_RUN; j++) {
tempCommandCode = getRandomInt(0, 15); // 0 and 8 are ignored or used for a special op
switch (tempCommandCode) {
case ADD :
tempInt = getRandomInteger();
listCommandsCalled.addElement("Add");
arrayList.add(tempInt);
deque.add(tempInt);
vector.addElement(tempInt);
break;
case ADD_AT :
tempInt = getRandomInteger();
tempPosition = getRandomInt(0, vector.size());
listCommandsCalled.addElement("Add at " + tempPosition);
try {
arrayList.add(tempPosition, tempInt);
} catch (Exception ex) {
arrayListException = true;
}
try {
deque.add(tempPosition, tempInt);
} catch (Exception ex) {
dequeException = true;
}
try {
vector.insertElementAt(tempInt, tempPosition);
} catch (Exception ex) {
vectorException = true;
}
compareLists(arrayList, deque, vector);
break;
case GET :
tempPosition = getRandomInt(0, vector.size() - 1);
listCommandsCalled.addElement("Get " + tempPosition);
try {
arrayListObject = arrayList.get(tempPosition);
} catch (Exception ex) {
arrayListException = true;
}
try {
linkedListObject = deque.get(tempPosition);
} catch (Exception ex) {
dequeException = true;
}
try {
vectorObject = vector.elementAt(tempPosition);
} catch (Exception ex) {
vectorException = true;
}
break;
case REMOVE :
tempPosition = getRandomInt(0, vector.size() - 1);
listCommandsCalled.addElement("Remove " + tempPosition);
try {
arrayListObject = arrayList.remove(tempPosition);
} catch (Exception ex) {
arrayListException = true;
}
try {
linkedListObject = deque.remove(tempPosition);
} catch (Exception ex) {
dequeException = true;
}
try {
vectorObject = vector.elementAt(tempPosition);
vector.removeElementAt(tempPosition);
} catch (Exception ex) {
vectorException = true;
}
break;
case SET :
tempInt = getRandomInteger();
tempPosition = getRandomInt(0, vector.size() - 1);
listCommandsCalled.addElement("Set " + tempPosition);
try {
arrayList.set(tempPosition, tempInt);
} catch (Exception ex) {
arrayListException = true;
}
try {
deque.set(tempPosition, tempInt);
} catch (Exception ex) {
dequeException = true;
}
try {
vector.setElementAt(tempInt, tempPosition);
} catch (Exception ex) {
vectorException = true;
}
compareLists(arrayList, deque, vector);
break;
case OPTIMIZE :
listCommandsCalled.addElement("Optimize");
arrayList.trim();
vector.trimToSize();
break;
case REMOVE_ALL :
if (getRandomInt(0, 5) == 4) { // to limit the frequency of this call
listCommandsCalled.addElement("Remove all");
if (vector.size() == 0) {
break;
}
for (int k = arrayList.size() - 1; k >= 0; k--) {
arrayList.remove(k);
deque.remove(k);
}
vector.removeAllElements();
}
break;