-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataPool.java
More file actions
49 lines (40 loc) · 1.36 KB
/
DataPool.java
File metadata and controls
49 lines (40 loc) · 1.36 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
package gitlet;
import java.io.File;
import java.io.Serializable;
import java.util.HashMap;
/**
* @author Marco Lyu
* Content: DataPool is a database for all the files committed.
* It avoids the problem of redundancy (same files stored twice.),
* and it keeps users from retrieving serialized files. which should
* be inaccessible to them and modifying these files
*/
public class DataPool implements Serializable {
private static DataPool data = null;
private HashMap<String, File> blobs = new HashMap<String, File>();
/* Only one dataPool can be created */
private DataPool() { }
/* Returns a HashMap containing all the commits */
public static DataPool getPool() {
if (data == null) {
data = new DataPool();
}
return data;
}
/* Puts an entry of a fileId and a file into the HashMap */
public void put(String fileId, File outFile) {
blobs.put(fileId, outFile);
}
/* Retrieves the file according to its fileId */
public File get(String fileId) {
return blobs.get(fileId);
}
/* Checks whether a fileId already exists (avoid redundancy) */
public boolean containsKey(String fileID) {
return blobs.containsKey(fileID);
}
/* Returns the size of the current database */
public int size() {
return blobs.size();
}
}