X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2Fbits%2FColor.java;h=db9c0d9b2bac55f9bee47b84c72eebb1bcbf6231;hb=daa4106c096cd4d2b92c3cbae6491edccd25fcc4;hp=707b244b12664aa04a2c691cb73cfa3973d06e27;hpb=7b5261bc5b641e0769902f014e3b21f61050b02b;p=fanfix.git diff --git a/src/jexer/bits/Color.java b/src/jexer/bits/Color.java index 707b244..db9c0d9 100644 --- a/src/jexer/bits/Color.java +++ b/src/jexer/bits/Color.java @@ -1,4 +1,4 @@ -/** +/* * Jexer - Java Text User Interface * * License: LGPLv3 or later @@ -66,26 +66,27 @@ public final class Color { * @return Color.RED, Color.BLUE, etc. */ static Color getColor(final String colorName) { - switch (colorName.toLowerCase()) { - case "black": + String str = colorName.toLowerCase(); + + if (str.equals("black")) { return Color.BLACK; - case "white": + } else if (str.equals("white")) { return Color.WHITE; - case "red": + } else if (str.equals("red")) { return Color.RED; - case "cyan": + } else if (str.equals("cyan")) { return Color.CYAN; - case "green": + } else if (str.equals("green")) { return Color.GREEN; - case "magenta": + } else if (str.equals("magenta")) { return Color.MAGENTA; - case "blue": + } else if (str.equals("blue")) { return Color.BLUE; - case "yellow": + } else if (str.equals("yellow")) { return Color.YELLOW; - case "brown": + } else if (str.equals("brown")) { return Color.YELLOW; - default: + } else { // Let unknown strings become white return Color.WHITE; } @@ -215,6 +216,16 @@ public final class Color { return (value == that.value); } + /** + * Hashcode uses all fields in equals(). + * + * @return the hash + */ + @Override + public int hashCode() { + return value; + } + /** * Make human-readable description of this Color. * @@ -239,8 +250,9 @@ public final class Color { return "blue"; case SGRYELLOW: return "yellow"; + default: + throw new IllegalArgumentException("Invalid Color value: " + value); } - throw new IllegalArgumentException("Invalid Color value: " + value); } }