< prev index next >

src/java.base/share/classes/java/lang/StringLatin1.java

Print this page




 131     public static int compareToCI(byte[] value, byte[] other) {
 132         int len1 = value.length;
 133         int len2 = other.length;
 134         int lim = Math.min(len1, len2);
 135         for (int k = 0; k < lim; k++) {
 136             if (value[k] != other[k]) {
 137                 char c1 = (char) CharacterDataLatin1.instance.toUpperCase(getChar(value, k));
 138                 char c2 = (char) CharacterDataLatin1.instance.toUpperCase(getChar(other, k));
 139                 if (c1 != c2) {
 140                     c1 = (char) CharacterDataLatin1.instance.toLowerCase(c1);
 141                     c2 = (char) CharacterDataLatin1.instance.toLowerCase(c2);
 142                     if (c1 != c2) {
 143                         return c1 - c2;
 144                     }
 145                 }
 146             }
 147         }
 148         return len1 - len2;
 149     }
 150 













 151     public static int compareToCI_UTF16(byte[] value, byte[] other) {
 152         int len1 = length(value);
 153         int len2 = StringUTF16.length(other);
 154         int lim = Math.min(len1, len2);
 155         for (int k = 0; k < lim; k++) {
 156             char c1 = getChar(value, k);
 157             char c2 = StringUTF16.getChar(other, k);
 158             if (c1 != c2) {
 159                 c1 = Character.toUpperCase(c1);
 160                 c2 = Character.toUpperCase(c2);
 161                 if (c1 != c2) {
 162                     c1 = Character.toLowerCase(c1);
 163                     c2 = Character.toLowerCase(c2);
 164                     if (c1 != c2) {
 165                         return c1 - c2;
 166                     }
 167                 }
 168             }
 169         }
 170         return len1 - len2;




 131     public static int compareToCI(byte[] value, byte[] other) {
 132         int len1 = value.length;
 133         int len2 = other.length;
 134         int lim = Math.min(len1, len2);
 135         for (int k = 0; k < lim; k++) {
 136             if (value[k] != other[k]) {
 137                 char c1 = (char) CharacterDataLatin1.instance.toUpperCase(getChar(value, k));
 138                 char c2 = (char) CharacterDataLatin1.instance.toUpperCase(getChar(other, k));
 139                 if (c1 != c2) {
 140                     c1 = (char) CharacterDataLatin1.instance.toLowerCase(c1);
 141                     c2 = (char) CharacterDataLatin1.instance.toLowerCase(c2);
 142                     if (c1 != c2) {
 143                         return c1 - c2;
 144                     }
 145                 }
 146             }
 147         }
 148         return len1 - len2;
 149     }
 150 
 151     /**
 152      * hashCode consistent with {@link #compareToCI}
 153      */
 154     public static int hashCodeCI(byte[] value) {
 155         int h = 0;
 156         for (byte v : value) {
 157             char cu = (char) CharacterDataLatin1.instance.toUpperCase(v & 0xff);
 158             char cl = (char) CharacterDataLatin1.instance.toLowerCase(cu);
 159             h = 31 * h + cl;
 160         }
 161         return h;
 162     }
 163 
 164     public static int compareToCI_UTF16(byte[] value, byte[] other) {
 165         int len1 = length(value);
 166         int len2 = StringUTF16.length(other);
 167         int lim = Math.min(len1, len2);
 168         for (int k = 0; k < lim; k++) {
 169             char c1 = getChar(value, k);
 170             char c2 = StringUTF16.getChar(other, k);
 171             if (c1 != c2) {
 172                 c1 = Character.toUpperCase(c1);
 173                 c2 = Character.toUpperCase(c2);
 174                 if (c1 != c2) {
 175                     c1 = Character.toLowerCase(c1);
 176                     c2 = Character.toLowerCase(c2);
 177                     if (c1 != c2) {
 178                         return c1 - c2;
 179                     }
 180                 }
 181             }
 182         }
 183         return len1 - len2;


< prev index next >