• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  */
10 package ohos.global.icu.util;
11 
12 import ohos.global.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 exposed on OHOS
19  */
20 public class CaseInsensitiveString {
21 
22     private String string;
23 
24     private int hash = 0;
25 
26     private String folded = null;
27 
foldCase(String foldee)28     private static String foldCase(String foldee)
29     {
30         return UCharacter.foldCase(foldee, true);
31     }
32 
getFolded()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      */
CaseInsensitiveString(String s)44     public CaseInsensitiveString(String s) {
45         string = s;
46     }
47     /**
48      * returns the underlying string
49      * @return String
50      */
getString()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     @Override
equals(Object o)59     public boolean equals(Object o) {
60         if (o == null) {
61             return false;
62         }
63         if (this == o) {
64             return true;
65         }
66         if (o instanceof CaseInsensitiveString) {
67             getFolded();
68             CaseInsensitiveString cis = (CaseInsensitiveString) o;
69             cis.getFolded();
70             return folded.equals(cis.folded);
71         }
72         return false;
73     }
74 
75     /**
76      * Returns the hashCode of this object
77      * @return int hashcode
78      */
79     @Override
hashCode()80     public int hashCode() {
81         getFolded();
82 
83         if (hash == 0) {
84             hash = folded.hashCode();
85         }
86 
87         return hash;
88     }
89 
90     /**
91      * Overrides superclass method
92      * @return a string representation of the object.
93      */
94     @Override
toString()95     public String toString() {
96         return string;
97     }
98 }
99