Skip to content

Commit bb184a2

Browse files
fixing warnings errors
1 parent 9b09473 commit bb184a2

9 files changed

Lines changed: 32 additions & 34 deletions

File tree

src/main/java/command_decorators/CommandDecorator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88
public abstract class CommandDecorator extends Command {
99
// this is the command we want to decorate
10-
Command command;
10+
final Command command;
1111

1212
public CommandDecorator(Command command) {
1313
// create a command decorator with provided command

src/main/java/commands/Cat.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public String executeCommand(IShellState shellState, List<String> arguments)
2828
* and get the directory of the requirement file and its name
2929
*/
3030
checkArgumentsNum(arguments);
31-
String output = "";
31+
StringBuilder output = new StringBuilder();
3232
for (String path: arguments) {
3333
try {
3434
// retrieve the file object at given path
@@ -38,21 +38,21 @@ public String executeCommand(IShellState shellState, List<String> arguments)
3838
* else concatenate the current file after the previous
3939
* file with 3 lines break
4040
*/
41-
output += (output == "") ?
42-
filetoCat.getContent() : ("\n\n" + filetoCat.getContent());
41+
output.append((output.toString().equals("")) ?
42+
filetoCat.getContent() : ("\n\n" + filetoCat.getContent()));
4343
}
4444
/*
4545
* if a file given is invalid, concatenate previous input(if any)
4646
* with an error string
4747
*/
4848
catch (Exception e) {
4949
String errorString = "cannot view file " + path + ": " + e.getMessage();
50-
output += (output == "") ?
51-
errorString: "\n\n" + errorString;
50+
output.append((output.toString().equals("")) ?
51+
errorString : "\n\n" + errorString);
5252
}
5353
}
5454
// return the contents of all files
55-
return output;
55+
return output.toString();
5656
}
5757

5858

src/main/java/commands/Command.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
*/
1010
public abstract class Command {
1111
// this is maximum number of arguments that command takes
12-
protected int maxArguments;
12+
protected final int maxArguments;
1313
//this is minimum number of arguments that command takes
14-
protected int minArguments;
14+
protected final int minArguments;
1515

1616
public Command(int maxArguments, int minArguments) {
1717
this.maxArguments = maxArguments;

src/main/java/commands/Find.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ public String executeCommand(IShellState shellState,
6464
// if it has a child that is of type directory
6565
if (((Directory) fsObject).
6666
hasChildWithTypeAndName(Directory.class,name)){
67-
//FileSystemObject child = Directory.
68-
//findChild((Directory)fsObject,name);
6967
output = "directory found in " + paths;}
7068
// if it has a child that is of type file
7169
else if (((Directory) fsObject).

src/main/java/commands/Get.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ public String executeCommand(IShellState shellState, List<String> arguments)
2929
Directory currentDir = shellState.getCurrentDir();
3030

3131
//read through each line of the file and append to content
32-
String content = "";
32+
StringBuilder content = new StringBuilder();
3333
URL url = new URL(arguments.get(0));
3434
BufferedReader in = new BufferedReader(
3535
new InputStreamReader(url.openStream()));
3636
String inputLine;
3737
while ((inputLine = in.readLine()) != null)
38-
content += inputLine + "\n";
38+
content.append(inputLine).append("\n");
3939
in.close();
4040

4141
//get the url to find the file name
@@ -46,7 +46,7 @@ public String executeCommand(IShellState shellState, List<String> arguments)
4646
* create a file in current directory with founded file name
4747
* and content
4848
*/
49-
new file_system.File(fileName, currentDir, content);
49+
new file_system.File(fileName, currentDir, content.toString());
5050

5151
return "";
5252
}

src/main/java/commands/History.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ private String getHistory(IShellState shellState, int numberOfCommand)
4545
// get the history list of commands of shellState
4646
ArrayList<String> history = shellState.getHistory();
4747
int i = history.size() - 1 ;
48-
String output = "";
48+
StringBuilder output = new StringBuilder();
4949
/*
5050
* if numberOfCommand exceed the number of history,
5151
* set it to print up to all history
@@ -62,10 +62,10 @@ private String getHistory(IShellState shellState, int numberOfCommand)
6262
* or until all history commands have been printed
6363
*/
6464
while (numberOfCommand > 0 && i <= history.size()) {
65-
output = Integer.toString(i+1) + ". " + history.get(i) + "\n" + output;
65+
output.insert(0, i + 1 + ". " + history.get(i) + "\n");
6666
i--;
6767
numberOfCommand--;
6868
}
69-
return output;
69+
return output.toString();
7070
}
7171
}

src/main/java/commands/Load.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public String executeCommand(IShellState shellState, List<String> arguments)
3838
if (path.indexOf("/") == -1) {
3939
throw new Exception(Exceptions.WRONG_PATH_INPUT_MSG);
4040
}
41-
String line = null;
41+
String line;
4242

4343
FileReader fileReader = new FileReader(path);
4444
BufferedReader bufferedReader = new BufferedReader(fileReader);
@@ -59,11 +59,11 @@ public String executeCommand(IShellState shellState, List<String> arguments)
5959
if (line.equals("*****")) {
6060
nextPart = true;
6161
}
62-
else if (nextPart == false) {
62+
else if (!nextPart) {
6363
shellState.addHistory(line);
6464

6565
}
66-
else if (nextPart == true) {
66+
else{
6767
// executeCommand correct command
6868
count ++;
6969
@SuppressWarnings("unused")

src/main/java/commands/RecursiveInterface.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
*/
1111
public interface RecursiveInterface {
1212
// method for a command to execute recursively
13-
public String executeRecursively
14-
(IShellState shellState, List<String> arguments) throws Exception ;
13+
String executeRecursively
14+
(IShellState shellState, List<String> arguments);
1515
}

src/main/java/driver/IShellState.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,28 @@
77
import file_system.FileSystem;
88

99
public interface IShellState {
10-
public boolean isRunning();
10+
boolean isRunning();
1111

12-
public void stopRunning();
12+
void stopRunning();
1313

14-
public FileSystem getFileSystem();
14+
FileSystem getFileSystem();
1515

16-
public Directory getRootDir();
16+
Directory getRootDir();
1717

18-
public Directory getCurrentDir();
18+
Directory getCurrentDir();
1919

20-
public void setCurrentDir(Directory newCurrentDir);
20+
void setCurrentDir(Directory newCurrentDir);
2121

22-
public void addHistory(String inputLine);
22+
void addHistory(String inputLine);
2323

24-
public void removeHistory(int index);
24+
void removeHistory(int index);
2525

26-
public ArrayList<String> getHistory();
26+
ArrayList<String> getHistory();
2727

28-
public void addCorrectHistory(String inputLine);
28+
void addCorrectHistory(String inputLine);
2929

30-
public ArrayList<String> getCorrectHistory();
30+
ArrayList<String> getCorrectHistory();
3131

32-
public Stack<Directory> getDirectoryStack();
32+
Stack<Directory> getDirectoryStack();
3333

3434
}

0 commit comments

Comments
 (0)