forked from markusgeorge1207/ProgrammingGit
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTree.java
More file actions
48 lines (37 loc) · 1.01 KB
/
Tree.java
File metadata and controls
48 lines (37 loc) · 1.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
import java.util.*;
import java.io.*;
public class Tree {
private static ArrayList<String> contents;
private String SHA1;
public Tree() {
contents = new ArrayList<String>();
}
public void add(String line) {
if (containsLine(line))
return;
contents.add(line);
}
public void remove(String s) {
for (int i = contents.size() - 1; i >= 0; i--) {
if (contents.get(i).contains(s)) {
contents.remove(i);
}
}
}
public String save() throws Exception {
String fileContents = Utils.arrayListToFileString(contents);
SHA1 = Utils.calculateSHA1(fileContents);
Utils.writeToFile("./objects/" + SHA1, fileContents);
return SHA1;
}
public String getSHA1() {
return SHA1;
}
public boolean containsLine(String line) {
for (String s : contents) {
if (s.equals(line))
return true;
}
return false;
}
}