Skip to content

Commit 6f59f25

Browse files
committed
[refactor] Makes enums more readable.
1 parent 6e49fc0 commit 6f59f25

File tree

2 files changed

+18
-36
lines changed

2 files changed

+18
-36
lines changed
Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,22 @@
11
package com.iluwatar;
22

33
/**
4-
*
4+
*
55
* Enumeration for target size.
66
*
77
*/
88
public enum Size {
99

10-
SMALL, NORMAL, LARGE;
11-
12-
@Override
13-
public String toString() {
10+
SMALL("small"), NORMAL("normal"), LARGE("large"), UNDEFINED("");
11+
12+
private String title;
1413

15-
String s = "";
14+
Size(String title) {
15+
this.title = title;
16+
}
1617

17-
switch (this) {
18-
case LARGE:
19-
s = "large";
20-
break;
21-
case NORMAL:
22-
s = "normal";
23-
break;
24-
case SMALL:
25-
s = "small";
26-
break;
27-
default:
28-
break;
29-
}
30-
return s;
18+
@Override
19+
public String toString() {
20+
return title;
3121
}
3222
}

command/src/main/java/com/iluwatar/Visibility.java

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,16 @@
77
*/
88
public enum Visibility {
99

10-
VISIBLE, INVISIBLE;
10+
VISIBLE("visible"), INVISIBLE("invisible"), UNDEFINED("");
1111

12-
@Override
13-
public String toString() {
14-
15-
String s = "";
12+
private String title;
1613

17-
switch (this) {
18-
case INVISIBLE:
19-
s = "invisible";
20-
break;
21-
case VISIBLE:
22-
s = "visible";
23-
break;
24-
default:
25-
break;
14+
Visibility(String title) {
15+
this.title = title;
16+
}
2617

27-
}
28-
return s;
18+
@Override
19+
public String toString() {
20+
return title;
2921
}
3022
}

0 commit comments

Comments
 (0)