|
@@ -1,17 +1,61 @@
|
1
|
1
|
package rocks.zipcode.io.quiz4.collections;
|
2
|
2
|
|
|
3
|
+import java.util.Arrays;
|
|
4
|
+import java.util.Set;
|
|
5
|
+import java.util.TreeSet;
|
|
6
|
+
|
3
|
7
|
/**
|
4
|
8
|
* @author leon on 11/12/2018.
|
5
|
9
|
*/
|
6
|
|
-public class ComparableTreeSet<_> {
|
|
10
|
+public class ComparableTreeSet<_ extends Comparable<? super _>> implements Comparable<Object> {
|
|
11
|
+
|
|
12
|
+ private Set<_> arr;
|
|
13
|
+
|
7
|
14
|
public ComparableTreeSet(_... arr) {
|
|
15
|
+ this.arr = new TreeSet<_>(Arrays.asList(arr));;
|
8
|
16
|
}
|
9
|
17
|
|
|
18
|
+ public ComparableTreeSet(Set<_> set) {
|
|
19
|
+ this.arr = set;
|
|
20
|
+ }
|
10
|
21
|
|
11
|
22
|
public ComparableTreeSet() {
|
12
|
23
|
}
|
13
|
24
|
|
14
|
25
|
public Integer compareTo(ComparableTreeSet<_> o) {
|
15
|
|
- return null;
|
|
26
|
+ Integer count = 0;
|
|
27
|
+ Integer counter = 0;
|
|
28
|
+ Integer counter2 = 0;
|
|
29
|
+
|
|
30
|
+ for(_ element : arr){
|
|
31
|
+ for(_ element2 : o.getArr()){
|
|
32
|
+ if(counter.equals(counter2)){
|
|
33
|
+ if(element.compareTo(element2) < 1){
|
|
34
|
+ count ++;
|
|
35
|
+ counter2 ++;
|
|
36
|
+ break;
|
|
37
|
+ } else if (element.compareTo(element2) > 1){
|
|
38
|
+ count --;
|
|
39
|
+ counter2 ++;
|
|
40
|
+ break;
|
|
41
|
+ } else {
|
|
42
|
+ counter2 ++;
|
|
43
|
+ break;
|
|
44
|
+ }
|
|
45
|
+ }
|
|
46
|
+ }
|
|
47
|
+ counter ++;
|
|
48
|
+ }
|
|
49
|
+ System.out.println(count);
|
|
50
|
+ return count;
|
|
51
|
+ }
|
|
52
|
+
|
|
53
|
+ public Set<_> getArr() {
|
|
54
|
+ return arr;
|
|
55
|
+ }
|
|
56
|
+
|
|
57
|
+ @Override
|
|
58
|
+ public int compareTo(Object o) {
|
|
59
|
+ return 0;
|
16
|
60
|
}
|
17
|
61
|
}
|