2 *******************************************************************************
3 * Copyright (C) 2001-2013, 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) {
65 if (o instanceof CaseInsensitiveString) {
67 CaseInsensitiveString cis = (CaseInsensitiveString) o;
69 return folded.equals(cis.folded);
75 * Returns the hashCode of this object
76 * @return int hashcode
79 public int hashCode() {
83 hash = folded.hashCode();
90 * Overrides superclass method
93 public String toString() {