source: src/main/java/parties/in4010/q12015/group13/Util.java@ 127

Last change on this file since 127 was 127, checked in by Wouter Pasman, 6 years ago

#41 ROLL BACK of rev.126 . So this version is equal to rev. 125

File size: 1.8 KB
Line 
1package parties.in4010.q12015.group13;
2
3import java.util.ArrayList;
4import java.util.Collection;
5
6import genius.core.issue.Issue;
7import genius.core.issue.IssueDiscrete;
8import genius.core.issue.IssueInteger;
9import genius.core.issue.Value;
10import genius.core.issue.ValueInteger;
11import genius.core.timeline.TimeLineInfo;
12import genius.core.timeline.Timeline;
13
14public 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}
Note: See TracBrowser for help on using the repository browser.