-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathF.java
118 lines (112 loc) · 2.64 KB
/
F.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// File/Folder Storage Object
/**
* CS320 Assignment 2
* File System
* @author rdow035 1414352
*/
class F {
private String name;
private int creationTime;
private String lastModified;
private String owner;
private String fileType;
private int fileSize;
private int permissions;
private Link[] referenceList;
//private Link[] parentReferenceList; // deleteall
private int currentPosition;
private int linkCount;
private String fileData;
private String localPath;
public F(String localPath, int creationTime, String lastModified, String owner, String fileType, int permissions){
this.referenceList = new Link[1];
//this.parentReferenceList = new Link[1]; //deleteall
this.currentPosition = 0;
this.name = localPath;
this.lastModified = lastModified;
this.owner = owner;
this.fileType = fileType;
this.permissions = permissions;
this.linkCount=0;
this.creationTime = creationTime;
this.fileSize = 0;
this.localPath = localPath;
if(fileType.equals("file")) {
fileData = "";
} else {
fileData = null;
}
}
public void addReference(Link l) {
if(currentPosition == referenceList.length) resizeList();
referenceList[currentPosition] = l;
currentPosition++;
linkCount++;
}
public void removeReference(Link l) {
if(referenceList.length>1) {
for(int i=0; i<referenceList.length; i++) {
if(referenceList[i].getLocalPath().equals(l.getLocalPath())) {
Link[] tmp = new Link[referenceList.length-1];
for(int j=0; j<i; j++) {
tmp[j] = referenceList[j];
}
for(int k=i; k<tmp.length; k++) {
tmp[k] = referenceList[k+1];
}
referenceList = tmp;
}
}
// currentPosition--;
} else {
referenceList[0]=null;
}
currentPosition--;
}
public Link[] getReferenceList() {
return referenceList;
}
private void resizeList(){
int size = referenceList.length;
Link[] tmp = new Link[size*2];
for(int i=0; i<size; i++){
tmp[i]=referenceList[i];
}
referenceList=tmp;
}
public void setFileSize() {
this.fileSize = fileData.length();
}
public int getCreationTime() {
return creationTime;
}
public String getFileType() {
return fileType;
}
public void setCreationTime(int creationTime) {
this.creationTime = creationTime;
}
public int getLinkCount() {
return linkCount;
}
public int getFileSize() {
return fileSize;
}
public void reduceLinkCount() {
linkCount--;
}
public void increaseLinkCount() {
linkCount++;
}
public void append(String data) {
if(fileType.equals("file")) {
fileData += data;
setFileSize();
} else {
System.out.println(localPath + " is not a directory!");
}
}
public String show() {
return fileData;
}
}