summaryrefslogtreecommitdiffstats
path: root/src/main/java/derms/net/tomulticast/Message.java
blob: 035e968b8d0d26e6bdd64fa0e3676362a8855b75 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package derms.net.tomulticast;

import derms.net.rmulticast.MessagePayload;

class Message<T extends MessagePayload> implements MessagePayload {
    long seq; // Sequence number.
    T payload;

    Message(long seq, T payload) {
        this.seq = seq;
        this.payload = payload;
    }

    @Override
    public int hash() {
        return (int) seq * payload.hash();
    }

    @Override
    public int hashCode() {
        return hash();
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null)
            return false;
        if (obj.getClass() != this.getClass())
            return false;
        Message<?> other = (Message<?>) obj;
        if (other.payload.getClass() != this.payload.getClass())
            return false;
        return other.seq == this.seq && other.hash() == this.hash();
    }

    @Override
    public String toString() {
        return getClass().getSimpleName() + "{" + seq + ", " + payload + "}";
    }
}