2 *******************************************************************************
3 * Copyright (C) 2001-2007, International Business Machines Corporation and *
4 * others. All Rights Reserved. *
5 *******************************************************************************
7 package com.ibm.icu.util;
9 import com.ibm.icu.lang.UCharacter;
12 * A string used as a key in java.util.Hashtable and other
13 * collections. It retains case information, but its equals() and
14 * hashCode() methods ignore case.
17 public class CaseInsensitiveString {
19 private String string;
23 private String folded = null;
25 private static String foldCase(String foldee)
27 return UCharacter.foldCase(foldee, true);
30 private void getFolded()
33 folded = foldCase(string);
38 * Constructs an CaseInsentiveString object from the given string
39 * @param s The string to construct this object from
42 public CaseInsensitiveString(String s) {
46 * returns the underlying string
50 public String getString() {
54 * Compare the object with this
55 * @param o Object to compare this object with
58 public boolean equals(Object o) {
62 CaseInsensitiveString cis = (CaseInsensitiveString) o;
66 return folded.equals(cis.folded);
67 } catch (ClassCastException e) {
69 String s = (String) o;
71 return folded.equals(foldCase(s));
72 } catch (ClassCastException e2) {
79 * Returns the hashCode of this object
80 * @return int hashcode
83 public int hashCode() {
87 hash = folded.hashCode();
94 * Overrides superclass method
97 public String toString() {