X Tutup
Skip to content

Commit 86abc41

Browse files
committed
Merge pull request iluwatar#14 from mafagafogigante/master
Small refactorings
2 parents b563de0 + 5e28382 commit 86abc41

File tree

3 files changed

+11
-22
lines changed

3 files changed

+11
-22
lines changed

interpreter/src/main/java/com/iluwatar/App.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,7 @@ public static void main(String[] args) {
5050
}
5151

5252
public static boolean isOperator(String s) {
53-
if (s.equals("+") || s.equals("-") || s.equals("*")) {
54-
return true;
55-
} else {
56-
return false;
57-
}
53+
return s.equals("+") || s.equals("-") || s.equals("*");
5854
}
5955

6056
public static Expression getOperatorInstance(String s, Expression left,

mediator/src/main/java/com/iluwatar/Action.java

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,16 @@ public enum Action {
66

77
public String toString() {
88

9-
String s = "";
109
switch (this) {
1110
case ENEMY:
12-
s = "spotted enemies";
13-
break;
11+
return "spotted enemies";
1412
case GOLD:
15-
s = "found gold";
16-
break;
13+
return "found gold";
1714
case HUNT:
18-
s = "hunted a rabbit";
19-
break;
15+
return "hunted a rabbit";
2016
case TALE:
21-
s = "tells a tale";
22-
break;
23-
default:
24-
break;
17+
return "tells a tale";
2518
}
26-
return s;
27-
};
19+
return "";
20+
}
2821
}

model-view-presenter/src/main/java/com/iluwatar/FileLoader.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@ public String loadData() {
2929
try {
3030
BufferedReader br = new BufferedReader(new FileReader(new File(
3131
this.fileName)));
32-
String text = "";
33-
String line = "";
32+
StringBuilder sb = new StringBuilder();
33+
String line;
3434

3535
while ((line = br.readLine()) != null) {
36-
text += line + "\n";
36+
sb.append(line).append('\n');
3737
}
3838

3939
this.loaded = true;
4040
br.close();
4141

42-
return text;
42+
return sb.toString();
4343
}
4444

4545
catch (Exception e) {

0 commit comments

Comments
 (0)
X Tutup