source: src/main/java/genius/core/Deadline.java@ 82

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

Initial import : Genius 9.0.0

File size: 2.6 KB
Line 
1package genius.core;
2
3import java.io.Serializable;
4
5import javax.xml.bind.annotation.XmlAccessType;
6import javax.xml.bind.annotation.XmlAccessorType;
7import javax.xml.bind.annotation.XmlElement;
8import javax.xml.bind.annotation.XmlRootElement;
9
10/**
11 * Contains the deadline - either rounds based or time based.
12 * <p>
13 * Deadline is a final object and can be serialized to xml. Immutable.
14 *
15 * @author W.Pasman
16 */
17@SuppressWarnings("serial")
18@XmlRootElement
19@XmlAccessorType(XmlAccessType.FIELD)
20public class Deadline implements Serializable {
21
22 @XmlElement
23 private final Integer value;
24 @XmlElement
25 private final DeadlineType type;
26
27 /**
28 * Default timeout in seconds
29 */
30 private final static Integer DEFAULT_TIME_OUT = 180;
31
32 /**
33 * Create default value.
34 */
35 public Deadline() {
36 value = 180;
37 type = DeadlineType.TIME;
38 };
39
40 public Deadline(int val, DeadlineType tp) {
41 if (val <= 0) {
42 throw new IllegalArgumentException("value must be >0 but got " + val);
43 }
44 if (tp == null) {
45 throw new NullPointerException("type is null");
46 }
47 value = val;
48 type = tp;
49 }
50
51 /**
52 * @return the total value of the deadline (seconds or rounds)
53 */
54 public int getValue() {
55 return value;
56 }
57
58 /**
59 *
60 * @return the {@link DeadlineType} of this deadline
61 */
62 public DeadlineType getType() {
63 return type;
64 }
65
66 /**
67 * @return the default time-out for function calls in the agents
68 */
69 public Integer getDefaultTimeout() {
70 return DEFAULT_TIME_OUT;
71 }
72
73 public String toString() {
74 return "Deadline:" + valueString();
75 }
76
77 /**
78 * @return just the value of this deadline, eg "10s".
79 */
80 public String valueString() {
81 return value + type.units();
82 }
83
84 /**
85 *
86 * @return the time, or a default time time-out. This is needed to determine
87 * the time-out for code execution with {@link DeadlineType#ROUND}
88 * deadlines.
89 */
90 public int getTimeOrDefaultTimeout() {
91 if (type == DeadlineType.ROUND) {
92 return DEFAULT_TIME_OUT;
93 }
94 return value;
95
96 }
97
98 @Override
99 public int hashCode() {
100 final int prime = 31;
101 int result = 1;
102 result = prime * result + ((type == null) ? 0 : type.hashCode());
103 result = prime * result + ((value == null) ? 0 : value.hashCode());
104 return result;
105 }
106
107 @Override
108 public boolean equals(Object obj) {
109 if (this == obj)
110 return true;
111 if (obj == null)
112 return false;
113 if (getClass() != obj.getClass())
114 return false;
115 Deadline other = (Deadline) obj;
116 if (type != other.type)
117 return false;
118 if (value == null) {
119 if (other.value != null)
120 return false;
121 } else if (!value.equals(other.value))
122 return false;
123 return true;
124 }
125
126}
Note: See TracBrowser for help on using the repository browser.