package geniusweb.deadline; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; /** * How long a session will be allowed to run */ public class DeadlineTime implements Deadline { /** * Note, we do NOT use ISO 8601 standard because we need milliseconds * accuracy. */ private final Long durationms; /** * * @param millis number of milliseconds the session will be allowed to run */ @JsonCreator public DeadlineTime(@JsonProperty("durationms") long millis) { if (millis <= 0) { throw new IllegalArgumentException( "deadline must be positive time"); } this.durationms = millis; } /** * * @return the duration of this deadline, measured in milliseconds */ @Override public Long getDuration() { return durationms; } @Override public String toString() { return "DeadlineTime[" + durationms + "]"; } /** * NOTICE we have overridden this to use class hashcode as well. */ @Override public int hashCode() { return getClass().hashCode() + ((durationms == null) ? 0 : durationms.hashCode()); } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; DeadlineTime other = (DeadlineTime) obj; if (durationms == null) { if (other.durationms != null) return false; } else if (!durationms.equals(other.durationms)) return false; return true; } }