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