1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.linecorp.centraldogma.common;
18
19 import static java.util.Objects.requireNonNull;
20
21 import java.time.Instant;
22 import java.time.format.DateTimeFormatter;
23
24 import javax.annotation.Nullable;
25
26 import com.google.common.base.MoreObjects;
27
28
29
30
31 public class PushResult {
32
33 private final Revision revision;
34 private final long when;
35 @Nullable
36 private String whenAsText;
37
38
39
40
41
42
43
44
45 public PushResult(Revision revision, long when) {
46 this.revision = requireNonNull(revision, "revision");
47 this.when = when / 1000L * 1000L;
48 }
49
50
51
52
53 public Revision revision() {
54 return revision;
55 }
56
57
58
59
60
61
62 public long when() {
63 return when;
64 }
65
66
67
68
69
70
71 public String whenAsText() {
72 if (whenAsText == null) {
73 whenAsText = DateTimeFormatter.ISO_INSTANT.format(Instant.ofEpochMilli(when()));
74 }
75 return whenAsText;
76 }
77
78 @Override
79 public int hashCode() {
80 return revision.hashCode() * 31 + (int) (when / 1000);
81 }
82
83 @Override
84 public boolean equals(Object o) {
85 if (this == o) {
86 return true;
87 }
88 if (!(o instanceof PushResult)) {
89 return false;
90 }
91
92 final PushResult that = (PushResult) o;
93 return revision.equals(that.revision) && when == that.when;
94 }
95
96 @Override
97 public String toString() {
98 return MoreObjects.toStringHelper(this)
99 .addValue(revision.text())
100 .add("when", whenAsText())
101 .toString();
102 }
103 }