/
GitItem.java
59 lines (43 loc) · 1.67 KB
/
GitItem.java
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package book.twju.timeline.provider.git;
import static book.twju.timeline.util.Assertion.checkArgument;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.revwalk.RevCommit;
import book.twju.timeline.model.Item;
public class GitItem extends Item {
static final String AUTHOR_MUST_NOT_BE_NULL = "Argument 'author' must not be null.";
static final String CONTENT_MUST_NOT_BE_NULL = "Argument 'content' must not be null.";
private final String content;
private final String author;
public static GitItem ofCommit( RevCommit commit ) {
return new GitItem( getId( commit ), getTimeStamp( commit ), getAuthor( commit ), getContent( commit ) );
}
public GitItem( String id, long timeStamp, String author, String content ) {
super( id, timeStamp );
checkArgument( author != null, AUTHOR_MUST_NOT_BE_NULL );
checkArgument( content != null, CONTENT_MUST_NOT_BE_NULL );
this.author = author;
this.content = content;
}
public String getAuthor() {
return author;
}
public String getContent() {
return content;
}
@Override
public String toString() {
return "GitItem [content=" + content + ", author=" + author + ", timeStamp=" + timeStamp + ", id=" + id + "]";
}
static String getContent( RevCommit commit ) {
return commit.getShortMessage();
}
static String getAuthor( RevCommit commit ) {
return commit.getAuthorIdent().getName();
}
static long getTimeStamp( RevCommit commit ) {
return commit.getCommitterIdent().getWhen().getTime();
}
static String getId( RevCommit commit ) {
return ObjectId.toString( commit.getId() );
}
}