-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommit.java
More file actions
114 lines (97 loc) · 3.01 KB
/
Copy pathCommit.java
File metadata and controls
114 lines (97 loc) · 3.01 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package gitlet;
// TODO: any imports you need here
import java.io.Serializable;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date; // TODO: You'll likely use this in this class
import java.util.HashMap;
import java.util.List;
/** Represents a gitlet commit object.
* TODO: It's a good idea to give a description here of what else this Class
* does at a high level.
*
* @author TODO
*/
public class Commit implements Serializable {
/**
* TODO: add instance variables here.
*
* List all instance variables of the Commit class here with a useful
* comment above them describing what that variable represents and how that
* variable is used. We've provided one example for `message`.
*/
/** The message of this Commit. */
private String message;
/** Mapping the all the files made by this commit */
private HashMap<String, byte[]> CommitObject;
/** List of all the parents */
private List<String> parents;
private String id;
//gets parent
private String parent;
private Date date;
private String secondParent;
public void Commit() {
this.parents = new ArrayList<>();
message = "initial commit";
date = new Date(0);
CommitObject = new HashMap<String, byte[]>();
this.id = getID();
}
public Commit(String mess, String curpar, HashMap<String, byte[]> direc) {
message = mess;
parent = curpar;
CommitObject = direc;
if(curpar == null) {
//inital date
date = new Date(0);
} else {
date = new Date();
}
}
public String getParent() {
return parent;
}
public String getSecondParent() {
return secondParent;
}
public String getDate() {
SimpleDateFormat correctFormat = new SimpleDateFormat("EEE MMM d HH:mm:ss yyyy Z");
return correctFormat.format(this.date);
}
public List<Object> getList() {
List<Object> list = new ArrayList<>();
list.add(message);
//not inital commit
if(parent != null) {
list.add(parent);
}
list.add(getDate());
return list;
}
public void addCommit(String x , byte[] y) {
CommitObject.put(x,y);
}
public void setSecondParent(String s) {
secondParent = s;
}
public HashMap<String, byte[]> getCommitObject() {
return CommitObject;
}
public String getMessage() {
return message;
}
public String getID() {
return Utils.sha1(this.message, getTimestamp(), this.parents.toString(), this.CommitObject.toString());
}
private Object getTimestamp() {
SimpleDateFormat correctFormat = new SimpleDateFormat("EEE MMM d HH:mm:ss yyyy Z");
return correctFormat.format(date);
}
public void Commit(HashMap<String, byte[]> ob, String mess) {
message = mess;
CommitObject = ob;
}
/* TODO: fill in the rest of this class. */
}