public class TestUtil
1:
2: package test;
3:
4: import mylist.*;
5:
6: public class TestUtil {
7:
8: /**
9: * An auxiliary method that tests whether the contents of a list match the contents of
10: * an array of objects.
11: * It returns true if the list and the array are of the same length and each object in
12: * the list equals to the object in the array at the same position.
13: */
14: public static boolean match(List list, Object[] array) {
15: boolean result = false;
16: if (list != null &&
17: array != null) {
18: int n = list.size();
19: if (n == array.length) {
20: for (int i = 0; i < n; i++) {
21: Object item = list.element(i);
22: if (item != null) {
23: if (!item.equals(array[i])) {
24: return false;
25: }
26: } else {
27: if (array[i] != null) {
28: return false;
29: }
30: }
31: }
32: result = true;
33: }
34: } else if (list == null &&
35: array == null) {
36: result = true;
37: }
38: return result;
39: }
40:
41: /**
42: * An auxiliary method that converts an array of integer values to an array of integer objects
43: */
44: public static Object[] toIntegerArray(int[] intArray) {
45: if (intArray != null) {
46: int n = intArray.length;
47: Object[] resultArray = new Object[n];
48: for (int i = 0; i < n; i++) {
49: resultArray[i] = new Integer(intArray[i]);
50: }
51: return resultArray;
52: } else {
53: return null;
54: }
55: }
56:
57: }