瀏覽代碼

Collections simpleStringGroup

Nuridalia.Hernandez 6 年之前
父節點
當前提交
f391872fcd

+ 8
- 1
src/main/java/rocks/zipcode/io/quiz4/collections/ComparableTreeSet.java 查看文件

@@ -1,9 +1,11 @@
1 1
 package rocks.zipcode.io.quiz4.collections;
2 2
 
3
+import java.util.TreeSet;
4
+
3 5
 /**
4 6
  * @author leon on 11/12/2018.
5 7
  */
6
-public class ComparableTreeSet<_> {
8
+public class ComparableTreeSet<_ > extends TreeSet implements Comparable  {
7 9
     public ComparableTreeSet(_... arr) {
8 10
     }
9 11
 
@@ -14,4 +16,9 @@ public class ComparableTreeSet<_> {
14 16
     public Integer compareTo(ComparableTreeSet<_> o) {
15 17
         return null;
16 18
     }
19
+
20
+    @Override
21
+    public int compareTo(Object o) {
22
+        return 0;
23
+    }
17 24
 }

+ 22
- 5
src/main/java/rocks/zipcode/io/quiz4/collections/SimpleStringGroup.java 查看文件

@@ -1,31 +1,48 @@
1 1
 package rocks.zipcode.io.quiz4.collections;
2 2
 
3
+
4
+import java.util.ArrayList;
5
+import java.util.Iterator;
6
+import java.util.List;
7
+
3 8
 /**
4 9
  * @author leon on 11/12/2018.
5 10
  */
6
-public class SimpleStringGroup {
11
+public  class SimpleStringGroup implements Iterable {
12
+List<String> mySimpleGropt = new ArrayList<>();
7 13
     public SimpleStringGroup() {
8
-        throw new UnsupportedOperationException("Method not yet implemented");
14
+       // throw new UnsupportedOperationException("Method not yet implemented");
9 15
     }
10 16
 
11 17
     public Integer count() {
12
-        return null;
18
+
19
+        return mySimpleGropt.size();
13 20
     }
14 21
 
15 22
     public void insert(String string) {
23
+        mySimpleGropt.add(string);
16 24
     }
17 25
 
18 26
     public Boolean has(String valueToInsert) {
19
-        return null;
27
+
28
+        return mySimpleGropt.contains(valueToInsert);
20 29
     }
21 30
 
22 31
     public String fetch(int indexOfValue) {
23
-        return null;
32
+
33
+        return mySimpleGropt.get(indexOfValue);
24 34
     }
25 35
 
26 36
     public void delete(String valueToInsert) {
37
+        mySimpleGropt.remove(valueToInsert);
27 38
     }
28 39
 
29 40
     public void clear() {
41
+        mySimpleGropt.clear();
42
+    }
43
+
44
+    @Override
45
+    public Iterator iterator() {
46
+        return mySimpleGropt.iterator();
30 47
     }
31 48
 }

+ 1
- 0
src/main/java/rocks/zipcode/io/quiz4/collections/ZipCodeWilmington.java 查看文件

@@ -8,6 +8,7 @@ import java.util.Map;
8 8
  * @author leon on 11/12/2018.
9 9
  */
10 10
 public class ZipCodeWilmington {
11
+
11 12
     public void enroll(Student student) {
12 13
     }
13 14
 

+ 5
- 2
src/main/java/rocks/zipcode/io/quiz4/generics/GenericUtils.java 查看文件

@@ -8,11 +8,14 @@ import java.util.TreeSet;
8 8
  * @author leon on 11/12/2018.
9 9
  */
10 10
 public class GenericUtils {
11
-    public static <_ extends Comparable> Iterable<Iterable<_>> powerSet(Set<_> originalSet) {
11
+    public static <_ extends Comparable> Iterable<? extends Iterable<_>> powerSet(Set<_> originalSet) {
12
+
13
+
14
+
12 15
         return null;
13 16
     }
14 17
 
15
-    public static <_ extends Comparable> Iterable<Iterable<_>> powerSet(_... originalSet) {
18
+    public static <_ extends Comparable> Iterable<? extends Iterable<_>> powerSet(_... originalSet) {
16 19
         return powerSet(new TreeSet<>(Arrays.asList(originalSet)));
17 20
     }
18 21
 }

+ 22
- 5
src/main/java/rocks/zipcode/io/quiz4/generics/MyStack.java 查看文件

@@ -1,25 +1,42 @@
1 1
 package rocks.zipcode.io.quiz4.generics;
2 2
 
3
+import java.util.EmptyStackException;
4
+import java.util.Iterator;
5
+import java.util.Stack;
6
+
3 7
 /**
4 8
  * @author leon on 11/12/2018.
5 9
  */
6
-public class MyStack<SomeType> {
10
+public class MyStack<SomeType> implements Iterable {
11
+    Stack <SomeType> myStack = new Stack<>();
7 12
     public MyStack() {
8
-        throw new UnsupportedOperationException("Method not yet implemented");
13
+
14
+
15
+        //throw new UnsupportedOperationException("Method not yet implemented");
9 16
     }
10 17
 
11 18
     public Boolean isEmpty() {
12
-        return null;
19
+
20
+        return myStack.empty();
13 21
     }
14 22
 
15 23
     public void push(SomeType i) {
24
+        myStack.push(i);
16 25
     }
17 26
 
18 27
     public SomeType peek() {
19
-        throw new UnsupportedOperationException("Method not yet implemented");
28
+
29
+        //throw new UnsupportedOperationException("Method not yet implemented");
30
+        return myStack.peek();
20 31
     }
21 32
 
33
+
22 34
     public SomeType pop() {
23
-        return null;
35
+        return myStack.pop();
36
+    }
37
+
38
+    @Override
39
+    public Iterator iterator() {
40
+        return myStack.iterator();
24 41
     }
25 42
 }

+ 3
- 0
src/test/java/rocks/zipcode/io/quiz4/generics/stack/integerstack/IntegerStackPushTest.java 查看文件

@@ -13,12 +13,15 @@ public class IntegerStackPushTest {
13 13
 
14 14
     @Before
15 15
     public void setup() {
16
+
16 17
         this.stack = new MyStack<>();
17 18
     }
18 19
 
19 20
     @Test
20 21
     public void test1() {
22
+
21 23
         Assert.assertNull(stack.peek());
24
+
22 25
     }
23 26
 
24 27
     @Test