1 30 31 package rcm.util; 32 33 37 public class CaselessString { 38 String string; 39 40 public CaselessString (String string) { 41 this.string = string; 42 } 43 44 public boolean equals (Object obj) { 45 if (obj instanceof String 46 || obj instanceof CaselessString) 47 return string.equalsIgnoreCase (obj.toString ()); 48 else 49 return false; 50 } 51 52 public int hashCode() { 53 int hash = 0; 54 int len = string.length (); 55 56 if (len < 16) { 57 for (int i = 0; i < len; ++i) 59 hash = (hash * 37) + Character.toUpperCase (string.charAt (i)); 60 } else { 61 int skip = len / 8; for (int i = 0; i < len; i += skip) 63 hash = (hash * 39) + Character.toUpperCase (string.charAt (i)); 64 } 65 66 return hash; 67 } 68 69 public String toString () { 70 return string; 71 } 72 } 73 | Popular Tags |