1/* GENERATED SOURCE. DO NOT MODIFY. */
2/**
3 *******************************************************************************
4 * Copyright (C) 2001-2013, International Business Machines Corporation and    *
5 * others. All Rights Reserved.                                                *
6 *******************************************************************************
7 */
8package android.icu.util;
9
10import android.icu.lang.UCharacter;
11
12/**
13 * A string used as a key in java.util.Hashtable and other
14 * collections.  It retains case information, but its equals() and
15 * hashCode() methods ignore case.
16 * @hide Only a subset of ICU is exposed in Android
17 */
18public class CaseInsensitiveString {
19
20    private String string;
21
22    private int hash = 0;
23
24    private String folded = null;
25
26    private static String foldCase(String foldee)
27    {
28        return UCharacter.foldCase(foldee, true);
29    }
30
31    private void getFolded()
32    {
33        if (folded == null) {
34            folded = foldCase(string);
35        }
36    }
37
38    /**
39     * Constructs an CaseInsentiveString object from the given string
40     * @param s The string to construct this object from
41     */
42    public CaseInsensitiveString(String s) {
43        string = s;
44    }
45    /**
46     * returns the underlying string
47     * @return String
48     */
49    public String getString() {
50        return string;
51    }
52    /**
53     * Compare the object with this
54     * @param o Object to compare this object with
55     */
56    public boolean equals(Object o) {
57        if (o == null) {
58            return false;
59        }
60        if (this == o) {
61            return true;
62        }
63        if (o instanceof CaseInsensitiveString) {
64            getFolded();
65            CaseInsensitiveString cis = (CaseInsensitiveString) o;
66            cis.getFolded();
67            return folded.equals(cis.folded);
68        }
69        return false;
70    }
71
72    /**
73     * Returns the hashCode of this object
74     * @return int hashcode
75     */
76    public int hashCode() {
77        getFolded();
78
79        if (hash == 0) {
80            hash = folded.hashCode();
81        }
82
83        return hash;
84    }
85
86    /**
87     * Overrides superclass method
88     */
89    public String toString() {
90        return string;
91    }
92}
93