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