1 | package parties.in4010.q12015.group13;
|
---|
2 |
|
---|
3 | import java.util.ArrayList;
|
---|
4 | import java.util.Collection;
|
---|
5 |
|
---|
6 | import genius.core.issue.Issue;
|
---|
7 | import genius.core.issue.IssueDiscrete;
|
---|
8 | import genius.core.issue.IssueInteger;
|
---|
9 | import genius.core.issue.Value;
|
---|
10 | import genius.core.issue.ValueInteger;
|
---|
11 | import genius.core.timeline.TimeLineInfo;
|
---|
12 | import genius.core.timeline.Timeline;
|
---|
13 |
|
---|
14 | public class Util {
|
---|
15 | /**
|
---|
16 | *
|
---|
17 | * @param issue
|
---|
18 | * (Discrete or Integer only)
|
---|
19 | * @return An arraylist containing all possible values for issue
|
---|
20 | */
|
---|
21 | public static ArrayList<Value> getValues(Issue issue) {
|
---|
22 | ArrayList<Value> ret = new ArrayList();
|
---|
23 |
|
---|
24 | switch (issue.getType()) {
|
---|
25 | case DISCRETE:
|
---|
26 | IssueDiscrete issueD = (IssueDiscrete) issue;
|
---|
27 | for (Value v : issueD.getValues()) {
|
---|
28 | ret.add(v);
|
---|
29 | }
|
---|
30 | break;
|
---|
31 | case INTEGER:
|
---|
32 | IssueInteger issueI = (IssueInteger) issue;
|
---|
33 | for (int i = issueI.getLowerBound(); i <= issueI.getUpperBound(); i++) {
|
---|
34 | ValueInteger value = new ValueInteger(i);
|
---|
35 | ret.add(value);
|
---|
36 | }
|
---|
37 | break;
|
---|
38 | default:
|
---|
39 | throw new RuntimeException("Issuetype " + issue.getType()
|
---|
40 | + " not recognized");
|
---|
41 | }
|
---|
42 |
|
---|
43 | return ret;
|
---|
44 | }
|
---|
45 |
|
---|
46 | public static double estimatedRoundsLeft(TimeLineInfo time, int currentRound) {
|
---|
47 | if (time.getType() == Timeline.Type.Rounds) {
|
---|
48 | return time.getTotalTime() - currentRound;
|
---|
49 | } else {
|
---|
50 | return (time.getTotalTime() - time.getCurrentTime())
|
---|
51 | / (time.getCurrentTime() / currentRound);
|
---|
52 | }
|
---|
53 | }
|
---|
54 |
|
---|
55 | public static <T extends Number> double getSum(Collection<T> c) {
|
---|
56 | double sum = 0;
|
---|
57 | for (T t : c) {
|
---|
58 | sum += t.doubleValue();
|
---|
59 | }
|
---|
60 |
|
---|
61 | return sum;
|
---|
62 | }
|
---|
63 |
|
---|
64 | public static <T extends Comparable> T getMaximum(Collection<T> c) {
|
---|
65 | T max = null;
|
---|
66 |
|
---|
67 | for (T t : c) {
|
---|
68 | if (max == null || t.compareTo(max) > 0) {
|
---|
69 | max = t;
|
---|
70 | }
|
---|
71 | }
|
---|
72 |
|
---|
73 | return max;
|
---|
74 | }
|
---|
75 | }
|
---|