|
@@ -1,5 +1,6 @@
|
1
|
1
|
package rocks.zipcode.io.quiz3.generics;
|
2
|
2
|
|
|
3
|
+import java.util.Arrays;
|
3
|
4
|
import java.util.function.Function;
|
4
|
5
|
|
5
|
6
|
/**
|
|
@@ -13,6 +14,7 @@ public class ArrayUtility<SomeType> {
|
13
|
14
|
}
|
14
|
15
|
|
15
|
16
|
public SomeType findOddOccurringValue() {
|
|
17
|
+
|
16
|
18
|
return null;
|
17
|
19
|
}
|
18
|
20
|
|
|
@@ -21,10 +23,19 @@ public class ArrayUtility<SomeType> {
|
21
|
23
|
}
|
22
|
24
|
|
23
|
25
|
public Integer getNumberOfOccurrences(SomeType valueToEvaluate) {
|
24
|
|
- return null;
|
|
26
|
+ Integer occurrences = 0;
|
|
27
|
+ for (SomeType each: array){
|
|
28
|
+ if(each.equals(valueToEvaluate)){
|
|
29
|
+ occurrences++;
|
|
30
|
+ }
|
|
31
|
+ }
|
|
32
|
+ return occurrences;
|
25
|
33
|
}
|
26
|
34
|
|
27
|
35
|
public SomeType[] filter(Function<SomeType, Boolean> predicate) {
|
28
|
|
- return null;
|
|
36
|
+
|
|
37
|
+ return Arrays.stream(array)
|
|
38
|
+ .map(predicate)
|
|
39
|
+ .toArray(SomeType[].class.::new);
|
29
|
40
|
}
|
30
|
41
|
}
|