1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.linecorp.centraldogma.server.command;
18
19 import static java.util.Objects.requireNonNull;
20
21 import java.util.Objects;
22
23 import javax.annotation.Nullable;
24
25 import com.google.common.base.MoreObjects;
26
27 import com.linecorp.centraldogma.common.Author;
28
29 abstract class AbstractCommand<T> implements Command<T> {
30
31 private final CommandType type;
32 private final long timestamp;
33 private final Author author;
34
35 protected AbstractCommand(CommandType type, @Nullable Long timestamp, @Nullable Author author) {
36 this.type = requireNonNull(type, "type");
37 this.timestamp = timestamp != null ? timestamp : System.currentTimeMillis();
38 this.author = author != null ? author : Author.SYSTEM;
39 }
40
41 @Override
42 public final CommandType type() {
43 return type;
44 }
45
46 @Override
47 public final long timestamp() {
48 return timestamp;
49 }
50
51 @Override
52 public final Author author() {
53 return author;
54 }
55
56 @Override
57 public boolean equals(Object obj) {
58 if (this == obj) {
59 return true;
60 }
61 if (!(obj instanceof AbstractCommand)) {
62 return false;
63 }
64
65 final AbstractCommand<?> that = (AbstractCommand<?>) obj;
66 return type == that.type &&
67 timestamp == that.timestamp &&
68 author.equals(that.author);
69 }
70
71 @Override
72 public int hashCode() {
73 return Objects.hash(type, timestamp, author);
74 }
75
76 @Override
77 public final String toString() {
78 return toStringHelper().toString();
79 }
80
81 MoreObjects.ToStringHelper toStringHelper() {
82 return MoreObjects.toStringHelper(this)
83 .add("type", type)
84 .add("timestamp", timestamp)
85 .add("author", author);
86 }
87 }