source: timeline/src/main/java/geniusweb/deadline/DeadlineTime.java@ 26

Last change on this file since 26 was 26, checked in by bart, 4 years ago

Voting requests now contain Offers. Fixed windows whitespace issue. Partiesserver now supports up to 8 parties simultaneously.

File size: 1.5 KB
Line 
1package geniusweb.deadline;
2
3import com.fasterxml.jackson.annotation.JsonCreator;
4import com.fasterxml.jackson.annotation.JsonProperty;
5import com.fasterxml.jackson.annotation.JsonTypeName;
6
7/**
8 * How long a session will be allowed to run
9 */
10@JsonTypeName("deadlinetime")
11public class DeadlineTime implements Deadline {
12
13 /**
14 * Note, we do NOT use ISO 8601 standard because we need milliseconds
15 * accuracy.
16 */
17 private final Long durationms;
18
19 /**
20 *
21 * @param millis number of milliseconds the session will be allowed to run
22 */
23 @JsonCreator
24 public DeadlineTime(@JsonProperty("durationms") long millis) {
25 if (millis <= 0) {
26 throw new IllegalArgumentException(
27 "deadline must be positive time");
28 }
29 this.durationms = millis;
30 }
31
32 /**
33 *
34 * @return the duration of this deadline, measured in milliseconds
35 */
36 @Override
37 public Long getDuration() {
38 return durationms;
39 }
40
41 @Override
42 public String toString() {
43 return "DeadlineTime[" + durationms + "]";
44 }
45
46 /**
47 * NOTICE we have overridden this to use class hashcode as well.
48 */
49 @Override
50 public int hashCode() {
51 return getClass().hashCode()
52 + ((durationms == null) ? 0 : durationms.hashCode());
53 }
54
55 @Override
56 public boolean equals(Object obj) {
57 if (this == obj)
58 return true;
59 if (obj == null)
60 return false;
61 if (getClass() != obj.getClass())
62 return false;
63 DeadlineTime other = (DeadlineTime) obj;
64 if (durationms == null) {
65 if (other.durationms != null)
66 return false;
67 } else if (!durationms.equals(other.durationms))
68 return false;
69 return true;
70 }
71
72}
Note: See TracBrowser for help on using the repository browser.