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.linecorp.centraldogma.internal.Util;
27
28
29
30
31 public class Commit {
32
33 private final Revision revision;
34 private final Author author;
35 private final long when;
36 private final String summary;
37 private final String detail;
38 private final Markup markup;
39 @Nullable
40 private String whenAsText;
41
42
43
44
45
46
47
48
49
50
51 public Commit(Revision revision, Author author, String summary, String detail, Markup markup) {
52 this(revision, author, System.currentTimeMillis(), summary, detail, markup);
53 }
54
55
56
57
58
59
60
61
62
63
64
65
66 public Commit(Revision revision, Author author, long when, String summary, String detail, Markup markup) {
67 this.revision = requireNonNull(revision, "revision");
68 this.author = requireNonNull(author, "author");
69 this.summary = requireNonNull(summary, "summary");
70 this.detail = requireNonNull(detail, "detail");
71 this.markup = requireNonNull(markup, "markup");
72 this.when = when / 1000L * 1000L;
73 }
74
75
76
77
78 public Revision revision() {
79 return revision;
80 }
81
82
83
84
85
86
87 public long when() {
88 return when;
89 }
90
91
92
93
94
95
96 public String whenAsText() {
97 if (whenAsText == null) {
98 whenAsText = DateTimeFormatter.ISO_INSTANT.format(Instant.ofEpochMilli(when()));
99 }
100 return whenAsText;
101 }
102
103
104
105
106 public Author author() {
107 return author;
108 }
109
110
111
112
113 public String summary() {
114 return summary;
115 }
116
117
118
119
120 public String detail() {
121 return detail;
122 }
123
124
125
126
127 public Markup markup() {
128 return markup;
129 }
130
131 @Override
132 public int hashCode() {
133 return (revision.hashCode() * 31 + author.hashCode()) * 31 + (int) (when / 1000);
134 }
135
136 @Override
137 public boolean equals(Object o) {
138 if (this == o) {
139 return true;
140 }
141 if (!(o instanceof Commit)) {
142 return false;
143 }
144
145 final Commit that = (Commit) o;
146 return revision.equals(that.revision) && author.equals(that.author) && when == that.when &&
147 summary.equals(that.summary) && detail.equals(that.detail) && markup == that.markup;
148 }
149
150 @Override
151 public String toString() {
152 final StringBuilder buf = new StringBuilder(128);
153
154 buf.append(Util.simpleTypeName(this));
155 buf.append('[');
156 buf.append(revision.major());
157 buf.append(": author=");
158 buf.append(author.email());
159 buf.append(", when=");
160 buf.append(whenAsText());
161 buf.append(", summary=");
162 buf.append(summary);
163 buf.append(']');
164
165 return buf.toString();
166 }
167 }