package test;
import mylist.*;
public class TestUtil {
/**
* An auxiliary method that tests whether the contents of a list match the contents of
* an array of objects.
* It returns true if the list and the array are of the same length and each object in
* the list equals to the object in the array at the same position.
*/
public static boolean match(List list, Object[] array) {
boolean result = false;
if (list != null &&
array != null) {
int n = list.size();
if (n == array.length) {
for (int i = 0; i < n; i++) {
Object item = list.element(i);
if (item != null) {
if (!item.equals(array[i])) {
return false;
}
} else {
if (array[i] != null) {
return false;
}
}
}
result = true;
}
} else if (list == null &&
array == null) {
result = true;
}
return result;
}
/**
* An auxiliary method that converts an array of integer values to an array of integer objects
*/
public static Object[] toIntegerArray(int[] intArray) {
if (intArray != null) {
int n = intArray.length;
Object[] resultArray = new Object[n];
for (int i = 0; i < n; i++) {
resultArray[i] = new Integer(intArray[i]);
}
return resultArray;
} else {
return null;
}
}
}