/** Runs a test on the hsqldb lists */
public void testLists() {
HsqlArrayList arrayList = new HsqlArrayList();
HsqlLinkedList linkedList = new HsqlLinkedList();
Vector vector = new Vector();
Vector listCommandsCalled = new Vector(NUMBER_OF_ITERATIONS_PER_RUN);
Integer tempInt = null;
int tempCommandCode;
int tempPosition;
boolean arrayListException = false;
boolean linkedListException = 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);
linkedList.add(tempInt);
vector.addElement(tempInt);
listCommandsCalled.addElement("Add");
}
compareLists(arrayList, linkedList, 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);
linkedList.add(tempInt);
vector.addElement(tempInt);
break;
case ADD_AT :
tempInt = getRandomInteger();
tempPosition = getRandomInt(0, vector.size() + 1);
listCommandsCalled.addElement("Add at " + tempPosition);
try {
arrayList.add(tempPosition, tempInt);
} catch (Exception ex) {
arrayListException = true;
}
try {
linkedList.add(tempPosition, tempInt);
} catch (Exception ex) {
linkedListException = true;
}
try {
vector.insertElementAt(tempInt, tempPosition);
} catch (Exception ex) {
vectorException = true;
}
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 = linkedList.get(tempPosition);
} catch (Exception ex) {
linkedListException = 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 = linkedList.remove(tempPosition);
} catch (Exception ex) {
linkedListException = 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 {
linkedList.set(tempPosition, tempInt);
} catch (Exception ex) {
linkedListException = true;
}
try {
vector.setElementAt(tempInt, tempPosition);
} catch (Exception ex) {
vectorException = true;
}
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);
linkedList.remove(k);
}
vector.removeAllElements();
}
break;