Skip to content

Commit def8a80

Browse files
fix warnings, errors in FileSystem.java
1 parent 0ca67ad commit def8a80

1 file changed

Lines changed: 7 additions & 19 deletions

File tree

src/main/java/file_system/FileSystem.java

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class FileSystem {
1515
// this is a single reference to a File System
1616
private static FileSystem singleReference = null;
1717
// this is the root directory of file system
18-
private Directory root;
18+
private final Directory root;
1919

2020
/**
2121
* This is a private constructor that creates a new file system
@@ -43,14 +43,9 @@ public Directory getRoot() {
4343
return root;
4444
}
4545

46-
public FileSystemObject getFileSystem(String path) {
47-
return null;
48-
}
49-
5046
/**
5147
* Get the directory from which the path starts (root directory if path is
5248
* full and current directory if path is relative)
53-
* @param shellState is current State of the program
5449
* @param path is the given path
5550
* @return directory from which the path starts
5651
*/
@@ -68,16 +63,13 @@ public FileSystemObject getFileSystem(String path) {
6863
*/
6964
private List<String> parsePath(String path) {
7065
// split the path by system file separator (by default: /)
71-
List<String> fileSystemObjNameList =
72-
Arrays.asList(path.split(Constants.SYSTEM_FILE_PATH_SEPERATOR));
73-
return fileSystemObjNameList;
66+
return Arrays.asList(path.split(Constants.SYSTEM_FILE_PATH_SEPERATOR));
7467
}
7568

7669
/**
7770
* This method is used when trying to create or access some file or directory
7871
* with the path. Gets the directory from which the file/directory is
7972
* attempted to be created/accessed from and its name
80-
* @param shellState holds state of the program including root directory and
8173
* current directory
8274
* @param path is the specified path that indicates which file/directory is
8375
* attempted to be created/accessed
@@ -100,7 +92,6 @@ private List<String> parsePath(String path) {
10092
/**
10193
* This method is used when trying to access some file system object such as
10294
* file or directory with the path.
103-
* @param shellState holds state of the program including root directory and
10495
* current directory
10596
* @param path is the specified path that indicates which file/directory is
10697
* attempted to be accessed
@@ -120,7 +111,6 @@ private List<String> parsePath(String path) {
120111

121112
/**
122113
* Get the file specified by path
123-
* @param shellState holds state of the program including root directory and
124114
* current directory
125115
* @param path is the specified path(complete or relative)
126116
* @return path described by path
@@ -137,7 +127,6 @@ private List<String> parsePath(String path) {
137127

138128
/**
139129
* Get the directory specified by path
140-
* @param shellState holds state of the program including root directory and
141130
* current directory
142131
* @param path is the specified path(complete or relative)
143132
* @return directory described by path
@@ -169,17 +158,16 @@ public String getTreeRepresentation() {
169158
*/
170159
private String getTreeRepresentationHelper(Directory root, int numIndent) {
171160
// initialize output with root's name
172-
String output = StringHelper.repeate(" ", numIndent) +
173-
root.getName() + "\n";
161+
StringBuilder output = new StringBuilder(StringHelper.repeate(" ", numIndent) +
162+
root.getName() + "\n");
174163
for (FileSystemObject child: root) {
175164
if (child instanceof File) {
176-
output += StringHelper.repeate(" ", numIndent + 1) +
177-
child.getName() + "\n";
165+
output.append(StringHelper.repeate(" ", numIndent + 1)).append(child.getName()).append("\n");
178166
} else {
179-
output += getTreeRepresentationHelper((Directory) child, numIndent + 2);
167+
output.append(getTreeRepresentationHelper((Directory) child, numIndent + 2));
180168
}
181169
}
182-
return output;
170+
return output.toString();
183171
}
184172

185173
/**

0 commit comments

Comments
 (0)