You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* {@link CrazyGenerics} is an exercise class. It consists of classes, interfaces and methods that should be updated
@@ -33,8 +30,8 @@ public class CrazyGenerics {
33
30
* @param <T> – value type
34
31
*/
35
32
@Data
36
-
publicstaticclassSourced { // todo: refactor class to introduce type parameter and make value generic
37
-
privateObjectvalue;
33
+
publicstaticclassSourced<T> { // todo: refactor class to introduce type parameter and make value generic
34
+
privateTvalue;
38
35
privateStringsource;
39
36
}
40
37
@@ -45,11 +42,11 @@ public static class Sourced { // todo: refactor class to introduce type paramete
45
42
* @param <T> – actual, min and max type
46
43
*/
47
44
@Data
48
-
publicstaticclassLimited {
45
+
publicstaticclassLimited<TextendsNumber> {
49
46
// todo: refactor class to introduce type param bounded by number and make fields generic numbers
50
-
privatefinalObjectactual;
51
-
privatefinalObjectmin;
52
-
privatefinalObjectmax;
47
+
privatefinalTactual;
48
+
privatefinalTmin;
49
+
privatefinalTmax;
53
50
}
54
51
55
52
/**
@@ -59,8 +56,9 @@ public static class Limited {
59
56
* @param <T> – source object type
60
57
* @param <R> - converted result type
61
58
*/
62
-
publicinterfaceConverter { // todo: introduce type parameters
59
+
publicinterfaceConverter<T, R> { // todo: introduce type parameters
63
60
// todo: add convert method
61
+
Rconvert(Tparam);
64
62
}
65
63
66
64
/**
@@ -70,10 +68,10 @@ public interface Converter { // todo: introduce type parameters
70
68
*
71
69
* @param <T> – value type
72
70
*/
73
-
publicstaticclassMaxHolder { // todo: refactor class to make it generic
74
-
privateObjectmax;
71
+
publicstaticclassMaxHolder<TextendsComparable<? superT>> { // todo: refactor class to make it generic
72
+
privateTmax;
75
73
76
-
publicMaxHolder(Objectmax) {
74
+
publicMaxHolder(Tmax) {
77
75
this.max = max;
78
76
}
79
77
@@ -82,11 +80,13 @@ public MaxHolder(Object max) {
82
80
*
83
81
* @param val a new value
84
82
*/
85
-
publicvoidput(Objectval) {
86
-
thrownewExerciseNotCompletedException(); // todo: update parameter and implement the method
83
+
publicvoidput(Tval) {
84
+
if (val.compareTo(max) > 0) {
85
+
max = val;
86
+
} // todo: update parameter and implement the method
87
87
}
88
88
89
-
publicObjectgetMax() {
89
+
publicTgetMax() {
90
90
returnmax;
91
91
}
92
92
}
@@ -97,8 +97,8 @@ public Object getMax() {
97
97
*
98
98
* @param <T> – the type of objects that can be processed
99
99
*/
100
-
interfaceStrictProcessor { // todo: make it generic
101
-
voidprocess(Objectobj);
100
+
interfaceStrictProcessor<TextendsSerializable & Comparable<? superT>> { // todo: make it generic
101
+
voidprocess(Tobj);
102
102
}
103
103
104
104
/**
@@ -108,19 +108,19 @@ interface StrictProcessor { // todo: make it generic
108
108
* @param <T> – a type of the entity that should be a subclass of {@link BaseEntity}
109
109
* @param <C> – a type of any collection
110
110
*/
111
-
interfaceCollectionRepository { // todo: update interface according to the javadoc
112
-
voidsave(Objectentity);
111
+
interfaceCollectionRepository<TextendsBaseEntity, CextendsCollection<T>> { // todo: update interface according to the javadoc
112
+
voidsave(Tentity);
113
113
114
-
Collection<Object>getEntityCollection();
114
+
CgetEntityCollection();
115
115
}
116
116
117
117
/**
118
118
* {@link ListRepository} extends {@link CollectionRepository} but specifies the underlying collection as
119
-
* {@link java.util.List}.
119
+
* {@link List}.
120
120
*
121
121
* @param <T> – a type of the entity that should be a subclass of {@link BaseEntity}
122
122
*/
123
-
interfaceListRepository { // todo: update interface according to the javadoc
123
+
interfaceListRepository<TextendsBaseEntity> extendsCollectionRepository<T, List<T>> { // todo: update interface according to the javadoc
124
124
}
125
125
126
126
/**
@@ -133,7 +133,10 @@ interface ListRepository { // todo: update interface according to the javadoc
133
133
*
134
134
* @param <E> a type of collection elements
135
135
*/
136
-
interfaceComparableCollection { // todo: refactor it to make generic and provide a default impl of compareTo
136
+
interfaceComparableCollection<E> extendsCollection<E>, Comparable<Collection<?>> { // todo: refactor it to make generic and provide a default impl of compareTo
137
+
defaultintcompareTo(Collection<?> other) {
138
+
returnInteger.compare(this.size(), other.size());
139
+
}
137
140
}
138
141
139
142
/**
@@ -147,7 +150,7 @@ static class CollectionUtil {
147
150
*
148
151
* @param list
149
152
*/
150
-
publicstaticvoidprint(List<Integer> list) {
153
+
publicstaticvoidprint(List<?> list) {
151
154
// todo: refactor it so the list of any type can be printed, not only integers
0 commit comments