|
@@ -18,13 +18,28 @@ public class MyArrayList<T> {
|
18
|
18
|
|
19
|
19
|
Object[] tempArray = new Object[getSize() + 1];
|
20
|
20
|
tempArray[size] = data;
|
21
|
|
- this.myArrayList = tempArray;
|
|
21
|
+ myArrayList = tempArray;
|
22
|
22
|
setSizeBy1();
|
23
|
23
|
|
24
|
24
|
}
|
25
|
25
|
|
|
26
|
+ public void copy(Object[] newArr, Object[] src) {
|
|
27
|
+ for (int i = 0; i < src.length; i++) {
|
|
28
|
+ newArr[i] = src[i];
|
|
29
|
+ }
|
|
30
|
+ }
|
|
31
|
+
|
26
|
32
|
public void add(T data, int index) {
|
27
|
|
-
|
|
33
|
+ try {
|
|
34
|
+ Object[] tempoArray = new Object[getSize() + 1];
|
|
35
|
+ copy(tempoArray, myArrayList);
|
|
36
|
+ setSizeBy1();
|
|
37
|
+ myArrayList = tempoArray;
|
|
38
|
+ add(data);
|
|
39
|
+ set(index, data);
|
|
40
|
+ } catch (ArrayIndexOutOfBoundsException e) {
|
|
41
|
+ System.out.println("That index is not in my array list!");
|
|
42
|
+ }
|
28
|
43
|
}
|
29
|
44
|
|
30
|
45
|
public int getSize() {
|
|
@@ -53,7 +68,7 @@ public class MyArrayList<T> {
|
53
|
68
|
Object[] smallerArray = new Object[this.myArrayList.length - 1];
|
54
|
69
|
int counter = 0;
|
55
|
70
|
for (int i = 0; i < myArrayList.length; i++) {
|
56
|
|
- System.out.println(myArrayList[i]);
|
|
71
|
+
|
57
|
72
|
if (!myArrayList[i].equals(data)) {
|
58
|
73
|
smallerArray[counter++] = myArrayList[i];
|
59
|
74
|
}
|
|
@@ -64,7 +79,7 @@ public class MyArrayList<T> {
|
64
|
79
|
}
|
65
|
80
|
|
66
|
81
|
|
67
|
|
- public void set(int i, T data) {
|
|
82
|
+ public void set(int i, T data) throws ArrayIndexOutOfBoundsException {
|
68
|
83
|
try {
|
69
|
84
|
this.myArrayList[i] = data;
|
70
|
85
|
} catch (ArrayIndexOutOfBoundsException e) {
|