|
@@ -1,5 +1,6 @@
|
1
|
1
|
package rocks.zipcode.io.quiz3.generics;
|
2
|
2
|
|
|
3
|
+import java.util.Collections;
|
3
|
4
|
import java.util.function.Function;
|
4
|
5
|
|
5
|
6
|
/**
|
|
@@ -8,23 +9,40 @@ import java.util.function.Function;
|
8
|
9
|
public class ArrayUtility<SomeType> {
|
9
|
10
|
private final SomeType[] array;
|
10
|
11
|
|
11
|
|
- public ArrayUtility(SomeType[] array) {
|
|
12
|
+ public ArrayUtility(SomeType[] array)
|
|
13
|
+ {
|
12
|
14
|
this.array = array;
|
13
|
15
|
}
|
14
|
16
|
|
15
|
17
|
public SomeType findOddOccurringValue()
|
|
18
|
+
|
16
|
19
|
{
|
17
|
|
- return null;
|
|
20
|
+ Integer i;
|
|
21
|
+ Integer result = 0;
|
|
22
|
+ for (i = 0; i < array.length; i++)
|
|
23
|
+ {
|
|
24
|
+ result = result ^ (Integer)array[i];
|
|
25
|
+ }
|
|
26
|
+ return (SomeType) result;
|
18
|
27
|
}
|
19
|
28
|
|
20
|
29
|
|
21
|
|
- public SomeType findEvenOccurringValue() {
|
|
30
|
+ public SomeType findEvenOccurringValue()
|
|
31
|
+ {
|
22
|
32
|
return null;
|
23
|
33
|
}
|
24
|
34
|
|
25
|
|
- public Integer getNumberOfOccurrences(SomeType valueToEvaluate) {
|
26
|
|
-
|
27
|
|
- return null;
|
|
35
|
+ public Integer getNumberOfOccurrences(SomeType valueToEvaluate)
|
|
36
|
+ {
|
|
37
|
+ Integer count=0;
|
|
38
|
+ for (int i=0;i<this.array.length;i++)
|
|
39
|
+ {
|
|
40
|
+ if(valueToEvaluate.equals(array[i]))
|
|
41
|
+ {
|
|
42
|
+ count++;
|
|
43
|
+ }
|
|
44
|
+ }
|
|
45
|
+ return count;
|
28
|
46
|
}
|
29
|
47
|
|
30
|
48
|
public SomeType[] filter(Function<SomeType, Boolean> predicate) {
|