Skip to content

Commit

Permalink
Merge pull request iluwatar#29 from ruslanpa/master
Browse files Browse the repository at this point in the history
[refactor] Makes enums more readable.
  • Loading branch information
iluwatar committed Feb 10, 2015
2 parents 67c1125 + 6da9686 commit c7a4a85
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 98 deletions.
13 changes: 9 additions & 4 deletions builder/src/main/java/com/iluwatar/Armor.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@

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;
}

}
30 changes: 10 additions & 20 deletions command/src/main/java/com/iluwatar/Size.java
Original file line number Diff line number Diff line change
@@ -1,32 +1,22 @@
package com.iluwatar;

/**
*
*
* Enumeration for target size.
*
*/
public enum Size {

SMALL, NORMAL, LARGE;

@Override
public String toString() {
SMALL("small"), NORMAL("normal"), LARGE("large"), UNDEFINED("");

private String title;

String s = "";
Size(String title) {
this.title = title;
}

switch (this) {
case LARGE:
s = "large";
break;
case NORMAL:
s = "normal";
break;
case SMALL:
s = "small";
break;
default:
break;
}
return s;
@Override
public String toString() {
return title;
}
}
24 changes: 8 additions & 16 deletions command/src/main/java/com/iluwatar/Visibility.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,16 @@
*/
public enum Visibility {

VISIBLE, INVISIBLE;
VISIBLE("visible"), INVISIBLE("invisible"), UNDEFINED("");

@Override
public String toString() {

String s = "";
private String title;

switch (this) {
case INVISIBLE:
s = "invisible";
break;
case VISIBLE:
s = "visible";
break;
default:
break;
Visibility(String title) {
this.title = title;
}

}
return s;
@Override
public String toString() {
return title;
}
}
25 changes: 9 additions & 16 deletions factory-method/src/main/java/com/iluwatar/WeaponType.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,16 @@

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;
}

}
3 changes: 1 addition & 2 deletions flyweight/src/main/java/com/iluwatar/Potion.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@
*/
public interface Potion {

public void drink();

void drink();
}
3 changes: 2 additions & 1 deletion flyweight/src/main/java/com/iluwatar/PotionFactory.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.iluwatar;

import java.util.EnumMap;
import java.util.Map;

/**
*
Expand All @@ -12,7 +13,7 @@
*/
public class PotionFactory {

private EnumMap<PotionType, Potion> potions;
private final Map<PotionType, Potion> potions;

public PotionFactory() {
potions = new EnumMap<>(PotionType.class);
Expand Down
3 changes: 1 addition & 2 deletions flyweight/src/main/java/com/iluwatar/PotionType.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@
*/
public enum PotionType {

HEALING, INVISIBILITY, STRENGTH, HOLY_WATER, POISON;

HEALING, INVISIBILITY, STRENGTH, HOLY_WATER, POISON
}
21 changes: 8 additions & 13 deletions mediator/src/main/java/com/iluwatar/Action.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,15 @@
*/
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;
}
}
33 changes: 9 additions & 24 deletions memento/src/main/java/com/iluwatar/StarType.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,16 @@

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;
}

}

0 comments on commit c7a4a85

Please sign in to comment.