Chaitali Patel 6 年 前
コミット
6488e68d2a

+ 20
- 7
src/main/java/rocks/zipcode/io/quiz4/collections/ComparableTreeSet.java ファイルの表示

@@ -3,16 +3,22 @@ package rocks.zipcode.io.quiz4.collections;
3 3
 /**
4 4
  * @author leon on 11/12/2018.
5 5
  */
6
-public class ComparableTreeSet<T> {
7
-    private T value;
6
+public class ComparableTreeSet<T> implements Comparable<T> {
7
+    private T[] arr;
8 8
 
9
-    public ComparableTreeSet(T... arr) {
9
+    public T[] getArr() {
10
+        return arr;
10 11
     }
11 12
 
12
-    public ComparableTreeSet(T value) {
13
-        this.value = value;
13
+    public void setArr(T[] arr) {
14
+        this.arr = arr;
14 15
     }
15 16
 
17
+    public ComparableTreeSet(T... arr) {
18
+        this.arr =arr;
19
+    }
20
+
21
+
16 22
     public ComparableTreeSet() {
17 23
     }
18 24
 
@@ -21,13 +27,20 @@ public class ComparableTreeSet<T> {
21 27
     }
22 28
 
23 29
     private ComparableTreeSet<T> getValue() {
24
-        return (ComparableTreeSet<T>) value;
30
+       // return (ComparableTreeSet<T>) value;
31
+        return null;
25 32
     }
26 33
 
27 34
     @Override
28 35
     public String toString() {
29 36
         return "ComparableTreeSet{" +
30
-                "value=" + value +
37
+                "value=" + arr +
31 38
                 '}';
32 39
     }
40
+
41
+    @Override
42
+    public int compareTo(T o) {
43
+        return 0;
44
+    }
45
+
33 46
 }

+ 15
- 26
src/main/java/rocks/zipcode/io/quiz4/collections/SimpleStringGroup.java ファイルの表示

@@ -1,9 +1,6 @@
1 1
 package rocks.zipcode.io.quiz4.collections;
2 2
 
3
-import java.util.HashSet;
4
-import java.util.Iterator;
5
-import java.util.Set;
6
-import java.util.Spliterator;
3
+import java.util.*;
7 4
 import java.util.function.Consumer;
8 5
 
9 6
 import static com.sun.jmx.snmp.ThreadContext.contains;
@@ -12,56 +9,48 @@ import static com.sun.jmx.snmp.ThreadContext.contains;
12 9
  * @author leon on 11/12/2018.
13 10
  */
14 11
 public class SimpleStringGroup implements Iterable{
12
+
13
+    List<String> val = new ArrayList<>();
15 14
     public SimpleStringGroup() {
16 15
         //throw new UnsupportedOperationException("Method not yet implemented");
17 16
     }
18 17
 
19
-    private final Set<String> set = new HashSet<>();
20
-
21
-
22 18
     public Integer count() {
23
-        return set.size();
19
+        return val.size();
24 20
     }
25 21
 
26 22
     public void insert(String string) {
27
-        if (!contains(string)) {
28
-            set.add(string);
29
-        }
23
+//        if (!contains(string)) {
24
+            val.add(string);
30 25
     }
31 26
 
32 27
     public Boolean has(String valueToInsert) {
33
-        return set.contains(valueToInsert);
28
+        if (val.contains(valueToInsert)){
29
+            return true;
30
+        }
31
+        return false;
34 32
     }
35 33
 
36 34
     public String fetch(int indexOfValue) {
37
-        //return set.add(indexOfValue);
38
-        return String.valueOf(set.equals(indexOfValue));
39
-        //return null;
35
+        return val.get(indexOfValue);
36
+
40 37
     }
41 38
 
42 39
     public void delete(String valueToInsert) {
43
-        set.remove(valueToInsert);
40
+        val.remove(valueToInsert);
44 41
     }
45 42
 
46 43
     public void clear() {
47
-        set.clear();
44
+        val.clear();
48 45
     }
49 46
 
50
-   public void get() {
51
-        set.size();
52
-   }
53
-
54 47
     @Override
55 48
     public Iterator iterator() {
56
-        return null;
49
+        return val.iterator();
57 50
     }
58 51
 
59 52
     @Override
60 53
     public void forEach(Consumer action) {
61 54
     }
62 55
 
63
-    @Override
64
-    public Spliterator spliterator() {
65
-        return null;
66
-    }
67 56
 }

+ 1
- 1
src/main/java/rocks/zipcode/io/quiz4/generics/Group.java ファイルの表示

@@ -50,7 +50,7 @@ public class Group<T> implements Iterable<T>{
50 50
 
51 51
     @Override
52 52
     public Iterator<T> iterator() {
53
-        return null;
53
+        return list.iterator();
54 54
     }
55 55
 
56 56
     @Override