-
Notifications
You must be signed in to change notification settings - Fork 0
/
Index.java
76 lines (60 loc) · 1.67 KB
/
Index.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package gitlet;
import java.io.Serializable;
import java.util.TreeMap;
public class Index implements Serializable {
public Index() {
toAdd = new TreeMap<>();
toDelete = new TreeMap<>();
}
public TreeMap<String, String> getAdd() {
return toAdd;
}
public TreeMap<String, String> getRemove() {
return toDelete;
}
public void toStage(String filename, String blob) {
toAdd.put(filename, blob);
}
public void toRemove(String filename, String blob) {
toDelete.put(filename, blob);
}
public void reset() {
toAdd.clear();
toDelete.clear();
}
public boolean fileExistsToAdd(String filename) {
if (toAdd.containsKey(filename)) {
return true;
}
return false;
}
public boolean fileExistsToDelete(String filename) {
if (toDelete.containsKey(filename)) {
return true;
}
return false;
}
public boolean fileExists(String filename) {
if (fileExistsToAdd(filename) || fileExistsToDelete(filename)) {
return true;
}
return false;
}
public boolean empty() {
if (toDelete.isEmpty() && toAdd.isEmpty()) {
return true;
}
return false;
}
public void remove(String filename) {
if (toAdd.containsKey(filename)) {
toAdd.remove(filename);
} else if (toDelete.containsKey(filename)) {
toDelete.remove(filename);
}
}
/** Files staged for addition. */
private TreeMap<String, String> toAdd;
/** Files staged for removal. */
private TreeMap<String, String> toDelete;
}