-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathMySet.java
More file actions
93 lines (71 loc) · 1.98 KB
/
MySet.java
File metadata and controls
93 lines (71 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import java.util.Collection;
import java.util.Iterator;
public class MySet<E> {
private MyArrayList<E> myArrayList;
public MySet() {
this.myArrayList = new MyArrayList<>();
}
public MySet(Collection<? extends E> collection) {
this.myArrayList = new MyArrayList<>(collection);
}
public MySet(int initialCapacity) {
this.myArrayList = new MyArrayList<>(initialCapacity);
}
public boolean add(E element) {
if (myArrayList.isEmpty()) {
myArrayList.add(element);
} else if (! myArrayList.contains(element)) {
myArrayList.add(element);
}
return true;
}
// Could not get this method to work
// public boolean addAll(Collection<? extends E> collection) {
// for (E element : collection) {
// myArrayList.add(element);
// }
// return true;
// }
public void clear() {
this.myArrayList.clear();
}
public boolean contains(E elementToFind) {
return this.myArrayList.contains(elementToFind);
}
// public boolean containsAll(Collection<?> collection) {
// return false;
// }
// public boolean equals(Object object) {
// return false;
// }
// public int hashCode() {
// return 0;
// }
public boolean isEmpty() {
return this.myArrayList.isEmpty();
}
// public Iterator<E> iterator() {
// return null;
// }
public void remove(E element) {
this.myArrayList.remove(element);
}
// public boolean removeAll(Collection<?> collection) {
// return false;
// }
// public boolean retainAll(Collection<?> collection) {
// return false;
// }
public int size() {
return myArrayList.size();
}
public int capacity() {
return myArrayList.capacity();
}
public Object[] toArray() {
return myArrayList.toArray();
}
// public <T> T[] toArray(T[] a) {
// return a.toArray();
// }
}