-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathIndexEntry.java
More file actions
45 lines (37 loc) · 1.24 KB
/
IndexEntry.java
File metadata and controls
45 lines (37 loc) · 1.24 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
public class IndexEntry implements Comparable<IndexEntry> {
private String filePath;
private String hash;
private boolean isBLOB;
public IndexEntry(String line) {
String[] lineContents = line.split(" ");
this.isBLOB = (lineContents[0]).equals("blob");
this.hash = lineContents[1];
this.filePath = lineContents[2];
}
public IndexEntry(String hash, String path) {
this.isBLOB = false;
this.hash = hash;
this.filePath = path;
}
public boolean isBLOB() {
return isBLOB;
}
public String getHash() {
return hash;
}
public String getFilePath() {
return filePath;
}
public String getFolderPath() {
if (!filePath.contains("/"))
return "";
return filePath.substring(0, filePath.lastIndexOf("/"));
}
public int compareTo(IndexEntry otherIndexEntry) {
String[] brokenDownPathA = filePath.split("/");
String[] brokenDownPathB = otherIndexEntry.filePath.split("/");
if (brokenDownPathA.length != brokenDownPathB.length)
return Integer.compare(brokenDownPathB.length - 1, brokenDownPathA.length - 1);
return filePath.compareTo(otherIndexEntry.filePath);
}
}