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