-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathObjectEntry.java
More file actions
52 lines (46 loc) · 1.39 KB
/
ObjectEntry.java
File metadata and controls
52 lines (46 loc) · 1.39 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
public class ObjectEntry {
String objectType;
String hash;
String objectPath;
int depth;
String parentPath;
public ObjectEntry(String objectType, String hash, String objectPath) {
this.objectType = objectType;
this.hash = hash;
this.objectPath = objectPath;
depth = getPathDepth(objectPath);
parentPath = getParent();
}
public ObjectEntry(String[] splitInfo) {
objectType = splitInfo[0];
hash = splitInfo[1];
objectPath = splitInfo[2];
}
public String toString() {
return objectType + " " + hash + " " + objectPath;
}
public static int getPathDepth(String filePath) {
int depth = 0;
for (int i = 0; i < filePath.length(); i++) {
if (filePath.charAt(i) == '/') {
depth += 1;
}
}
return depth;
}
public String getParent() {
int lastSlashIndex = getLastIndex(objectPath, "/");
if (lastSlashIndex == -1) {
return "";
}
return objectPath.substring(0, lastSlashIndex);
}
public static int getLastIndex(String myString, String subString) {
for (int i = myString.length() - subString.length(); i > -1; i--) {
if (myString.substring(i, i + subString.length()).equals(subString)) {
return i;
}
}
return -1;
}
}