Sfoglia il codice sorgente

MyArrayList - Complete

MySet - Working
add, get, contains, remove, addAll, clear, iterator
Nick Satinover 6 anni fa
parent
commit
a5145c4e66
1 ha cambiato i file con 15 aggiunte e 4 eliminazioni
  1. 15
    4
      src/main/java/MySet.java

+ 15
- 4
src/main/java/MySet.java Vedi File

@@ -51,7 +51,20 @@ public class MySet<T> extends MyArrayList implements Set {
51 51
 
52 52
     @Override
53 53
     public Iterator iterator() {
54
-        return null;
54
+        Iterator<T> genericSetIterator = new Iterator<T>() {
55
+            int index = 0;
56
+
57
+            @Override
58
+            public boolean hasNext() {
59
+                return index <  genericSet.length;
60
+            }
61
+
62
+            @Override
63
+            public T next() {
64
+                return genericSet[index++];
65
+            }
66
+        };
67
+        return genericSetIterator;
55 68
     }
56 69
 
57 70
     @Override
@@ -63,9 +76,7 @@ public class MySet<T> extends MyArrayList implements Set {
63 76
 
64 77
     @Override
65 78
     public boolean add(Object o) {
66
-        super.add(o);
67
-
68
-
79
+        //super.add(o);
69 80
         T[] newGenericSet = (T[]) Array.newInstance(this.genericSet.getClass().getComponentType(),
70 81
                 genericSet.length + 1);
71 82