-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDirectoryNode.java
More file actions
116 lines (103 loc) · 2.11 KB
/
DirectoryNode.java
File metadata and controls
116 lines (103 loc) · 2.11 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
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
/**
* A replication of a terminal with linux commands. The directories and files are stored using a tree.
* This class contains the methods in order to create a directory node.
*/
public class DirectoryNode {
private String name;
private DirectoryNode left;
private DirectoryNode right;
private DirectoryNode middle;
private boolean isFile;
/**
* creates a directory node
*/
public DirectoryNode() {
}
/**
* @param name of the directory node being created with this constructor
*/
public DirectoryNode(String name) {
this.name = name;
}
/**
* @return the name of the directory being created
*/
public String getName() {
return name;
}
/**
* @param name sets the node name to the parameter
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the left node
*/
public DirectoryNode getLeft() {
return left;
}
/**
* @return the right node
*/
public DirectoryNode getRight() {
return right;
}
/**
* @return the middle node
*/
public DirectoryNode getMiddle() {
return middle;
}
/**
* @return if node is a file
*/
public boolean getIsFile() {
return isFile;
}
/**
* @param isFile to set whether or not node is a file
*/
public void setIsFile(boolean isFile) {
this.isFile = isFile;
}
/**
* @param newChild to be added to current node
* @throws FullDirectoryException when the current node already has three kids
* @throws NotADirectoryException when user tries to add node to a file
*/
public void addChild(DirectoryNode newChild) throws FullDirectoryException, NotADirectoryException {
if (this.isFile == true) {
throw new NotADirectoryException();
}
if (left == null) {
left = newChild;
return;
}
if (middle == null) {
middle = newChild;
return;
}
if (right == null) {
right = newChild;
return;
}
else {
throw new FullDirectoryException();
}
}
public void removeChild(String where) {
if (where.equals("left")) {
left = null;
return;
}
if (where.equals("middle")) {
middle = null;
return;
}
if (where.equals("right")) {
right = null;
return;
}
}
}