Merge pull request #29 from ruslanpa/master
[refactor] Makes enums more readable.
This commit is contained in:
commit
c7a4a85213
@ -2,11 +2,16 @@ package com.iluwatar;
|
||||
|
||||
public enum Armor {
|
||||
|
||||
CLOTHES, LEATHER, CHAIN_MAIL, PLATE_MAIL;
|
||||
CLOTHES("clothes"), LEATHER("leather"), CHAIN_MAIL("chain mail"), PLATE_MAIL("plate mail");
|
||||
|
||||
@Override
|
||||
private String title;
|
||||
|
||||
Armor(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name().toLowerCase().replaceAll("_", " ");
|
||||
return title;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -7,26 +7,16 @@ package com.iluwatar;
|
||||
*/
|
||||
public enum Size {
|
||||
|
||||
SMALL, NORMAL, LARGE;
|
||||
SMALL("small"), NORMAL("normal"), LARGE("large"), UNDEFINED("");
|
||||
|
||||
@Override
|
||||
private String title;
|
||||
|
||||
Size(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
String s = "";
|
||||
|
||||
switch (this) {
|
||||
case LARGE:
|
||||
s = "large";
|
||||
break;
|
||||
case NORMAL:
|
||||
s = "normal";
|
||||
break;
|
||||
case SMALL:
|
||||
s = "small";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return s;
|
||||
return title;
|
||||
}
|
||||
}
|
||||
|
@ -7,24 +7,16 @@ package com.iluwatar;
|
||||
*/
|
||||
public enum Visibility {
|
||||
|
||||
VISIBLE, INVISIBLE;
|
||||
VISIBLE("visible"), INVISIBLE("invisible"), UNDEFINED("");
|
||||
|
||||
@Override
|
||||
private String title;
|
||||
|
||||
Visibility(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
String s = "";
|
||||
|
||||
switch (this) {
|
||||
case INVISIBLE:
|
||||
s = "invisible";
|
||||
break;
|
||||
case VISIBLE:
|
||||
s = "visible";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
return s;
|
||||
return title;
|
||||
}
|
||||
}
|
||||
|
@ -2,23 +2,16 @@ package com.iluwatar;
|
||||
|
||||
public enum WeaponType {
|
||||
|
||||
SHORT_SWORD, SPEAR, AXE;
|
||||
SHORT_SWORD("short sword"), SPEAR("spear"), AXE("axe"), UNDEFINED("");
|
||||
|
||||
@Override
|
||||
private String title;
|
||||
|
||||
WeaponType(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String s = "";
|
||||
switch (this) {
|
||||
case SHORT_SWORD:
|
||||
s = "short sword";
|
||||
break;
|
||||
case SPEAR:
|
||||
s = "spear";
|
||||
break;
|
||||
case AXE:
|
||||
s = "axe";
|
||||
break;
|
||||
}
|
||||
return s;
|
||||
return title;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -7,6 +7,5 @@ package com.iluwatar;
|
||||
*/
|
||||
public interface Potion {
|
||||
|
||||
public void drink();
|
||||
|
||||
void drink();
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.iluwatar;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -12,7 +13,7 @@ import java.util.EnumMap;
|
||||
*/
|
||||
public class PotionFactory {
|
||||
|
||||
private EnumMap<PotionType, Potion> potions;
|
||||
private final Map<PotionType, Potion> potions;
|
||||
|
||||
public PotionFactory() {
|
||||
potions = new EnumMap<>(PotionType.class);
|
||||
|
@ -7,6 +7,5 @@ package com.iluwatar;
|
||||
*/
|
||||
public enum PotionType {
|
||||
|
||||
HEALING, INVISIBILITY, STRENGTH, HOLY_WATER, POISON;
|
||||
|
||||
HEALING, INVISIBILITY, STRENGTH, HOLY_WATER, POISON
|
||||
}
|
||||
|
@ -7,20 +7,15 @@ package com.iluwatar;
|
||||
*/
|
||||
public enum Action {
|
||||
|
||||
HUNT, TALE, GOLD, ENEMY;
|
||||
HUNT("hunted a rabbit"), TALE("tells a tale"), GOLD("found gold"), ENEMY("spotted enemies"), NONE("");
|
||||
|
||||
public String toString() {
|
||||
private String title;
|
||||
|
||||
switch (this) {
|
||||
case ENEMY:
|
||||
return "spotted enemies";
|
||||
case GOLD:
|
||||
return "found gold";
|
||||
case HUNT:
|
||||
return "hunted a rabbit";
|
||||
case TALE:
|
||||
return "tells a tale";
|
||||
}
|
||||
return "";
|
||||
Action(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return title;
|
||||
}
|
||||
}
|
||||
|
@ -2,31 +2,16 @@ package com.iluwatar;
|
||||
|
||||
public enum StarType {
|
||||
|
||||
SUN, RED_GIANT, WHITE_DWARF, SUPERNOVA, DEAD;
|
||||
SUN("sun"), RED_GIANT("red giant"), WHITE_DWARF("white dwarf"), SUPERNOVA("supernova"), DEAD("dead star"), UNDEFINED("");
|
||||
|
||||
@Override
|
||||
private String title;
|
||||
|
||||
StarType(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String s = "";
|
||||
switch (this) {
|
||||
case RED_GIANT:
|
||||
s = "red giant";
|
||||
break;
|
||||
case SUN:
|
||||
s = "sun";
|
||||
break;
|
||||
case SUPERNOVA:
|
||||
s = "supernova";
|
||||
break;
|
||||
case WHITE_DWARF:
|
||||
s = "white dwarf";
|
||||
break;
|
||||
case DEAD:
|
||||
s = "dead star";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return s;
|
||||
return title;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user