From 0f1eb75c2f82b35a2a9b40543aab3946928ae6c5 Mon Sep 17 00:00:00 2001 From: Frank Maritato Date: Thu, 16 Jul 2009 21:21:33 +0000 Subject: [PATCH] added a hashCode method and removed some redundant casts git-svn-id: https://lwes.svn.sourceforge.net/svnroot/lwes/lwes-java/trunk@140 a2f82657-cdd2-4550-bd36-68a8e7111808 --- src/org/lwes/util/CharacterEncoding.java | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/org/lwes/util/CharacterEncoding.java b/src/org/lwes/util/CharacterEncoding.java index 6de7cfd..a8b1c5b 100644 --- a/src/org/lwes/util/CharacterEncoding.java +++ b/src/org/lwes/util/CharacterEncoding.java @@ -6,7 +6,7 @@ import java.util.HashMap; /** * This is a little class to abstract the character encoding strings that Java * uses into classes which can be checked at compile time. - * + * * @author Kevin Scaldeferri */ public abstract class CharacterEncoding { @@ -106,24 +106,31 @@ public abstract class CharacterEncoding { /** * This is a highly limited implementation at the moment, so don't expect * too much from it. - */ + * @param enc the String representation of the encoding. + * @return CharacterEncoding + * @throws java.io.UnsupportedEncodingException if the encoding doesnt exist. + */ public static CharacterEncoding getInstance(String enc) throws UnsupportedEncodingException { if (ENCODING_HASH.containsKey(enc.toUpperCase())) { - return (CharacterEncoding) ENCODING_HASH.get(enc.toUpperCase()); + return ENCODING_HASH.get(enc.toUpperCase()); } else { throw new UnsupportedEncodingException(enc); } } - public boolean equals(Object o) { + @Override + public int hashCode() { + return getEncodingString().hashCode(); + } + + public boolean equals(Object o) { return (o instanceof CharacterEncoding) - && getEncodingString().equals( - ((CharacterEncoding) o).getEncodingString()); + && getEncodingString().equals(((CharacterEncoding) o).getEncodingString()); } - + static { - int i = 0; + int i; for (i = 0; i < ASCII_ALIASES.length; i++) { ENCODING_HASH.put(ASCII_ALIASES[i], ASCII); } @@ -142,5 +149,5 @@ public abstract class CharacterEncoding { for (i = 0; i < EUC_KR_ALIASES.length; i++) { ENCODING_HASH.put(EUC_KR_ALIASES[i], EUC_KR); } - } + } } -- 2.11.4.GIT