Rev | Line | |
---|
[1] | 1 | package geniusweb.events;
|
---|
| 2 |
|
---|
| 3 | public abstract class AbstractEvent implements NegotiationEvent {
|
---|
| 4 |
|
---|
| 5 | private final Long time;
|
---|
| 6 |
|
---|
| 7 | @Override
|
---|
| 8 | public Long getTime() {
|
---|
| 9 | return time;
|
---|
| 10 | }
|
---|
| 11 |
|
---|
| 12 | public AbstractEvent() {
|
---|
| 13 | this.time = System.currentTimeMillis();
|
---|
| 14 | }
|
---|
| 15 |
|
---|
| 16 | /**
|
---|
| 17 | * @param now the current time to use. see {@link System#currentTimeMillis()}.
|
---|
| 18 | */
|
---|
| 19 | public AbstractEvent(Long now) {
|
---|
| 20 | if (now == null || now < 0) {
|
---|
| 21 | throw new IllegalArgumentException("time must be non-null and positive");
|
---|
| 22 | }
|
---|
| 23 | this.time = now;
|
---|
| 24 | }
|
---|
| 25 |
|
---|
| 26 | @Override
|
---|
| 27 | public String toString() {
|
---|
| 28 | return this.getClass().getSimpleName() + "[" + time + "]";
|
---|
| 29 | }
|
---|
| 30 |
|
---|
| 31 | @Override
|
---|
| 32 | public int hashCode() {
|
---|
| 33 | final int prime = 31;
|
---|
| 34 | int result = 1;
|
---|
| 35 | result = prime * result + ((time == null) ? 0 : time.hashCode());
|
---|
| 36 | return result;
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | @Override
|
---|
| 40 | public boolean equals(Object obj) {
|
---|
| 41 | if (this == obj)
|
---|
| 42 | return true;
|
---|
| 43 | if (obj == null)
|
---|
| 44 | return false;
|
---|
| 45 | if (getClass() != obj.getClass())
|
---|
| 46 | return false;
|
---|
| 47 | AbstractEvent other = (AbstractEvent) obj;
|
---|
| 48 | if (time == null) {
|
---|
| 49 | if (other.time != null)
|
---|
| 50 | return false;
|
---|
| 51 | } else if (!time.equals(other.time))
|
---|
| 52 | return false;
|
---|
| 53 | return true;
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.