< prev index next >

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

Print this page


   1 /*
   2  * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  86         System.arraycopy(value, srcBegin, dst, dstBegin, srcEnd - srcBegin);
  87     }
  88 
  89     @HotSpotIntrinsicCandidate
  90     public static boolean equals(byte[] value, byte[] other) {
  91         if (value.length == other.length) {
  92             for (int i = 0; i < value.length; i++) {
  93                 if (value[i] != other[i]) {
  94                     return false;
  95                 }
  96             }
  97             return true;
  98         }
  99         return false;
 100     }
 101 
 102     @HotSpotIntrinsicCandidate
 103     public static int compareTo(byte[] value, byte[] other) {
 104         int len1 = value.length;
 105         int len2 = other.length;




 106         int lim = Math.min(len1, len2);
 107         for (int k = 0; k < lim; k++) {
 108             if (value[k] != other[k]) {
 109                 return getChar(value, k) - getChar(other, k);
 110             }
 111         }
 112         return len1 - len2;
 113     }
 114 
 115     @HotSpotIntrinsicCandidate
 116     public static int compareToUTF16(byte[] value, byte[] other) {
 117         int len1 = length(value);
 118         int len2 = StringUTF16.length(other);














 119         int lim = Math.min(len1, len2);
 120         for (int k = 0; k < lim; k++) {
 121             char c1 = getChar(value, k);
 122             char c2 = StringUTF16.getChar(other, k);
 123             if (c1 != c2) {
 124                 return c1 - c2;
 125             }
 126         }
 127         return len1 - len2;
 128     }
 129 
 130     public static int compareToCI(byte[] value, byte[] other) {
 131         int len1 = value.length;
 132         int len2 = other.length;
 133         int lim = Math.min(len1, len2);
 134         for (int k = 0; k < lim; k++) {
 135             if (value[k] != other[k]) {
 136                 char c1 = (char) CharacterDataLatin1.instance.toUpperCase(getChar(value, k));
 137                 char c2 = (char) CharacterDataLatin1.instance.toUpperCase(getChar(other, k));
 138                 if (c1 != c2) {


   1 /*
   2  * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  86         System.arraycopy(value, srcBegin, dst, dstBegin, srcEnd - srcBegin);
  87     }
  88 
  89     @HotSpotIntrinsicCandidate
  90     public static boolean equals(byte[] value, byte[] other) {
  91         if (value.length == other.length) {
  92             for (int i = 0; i < value.length; i++) {
  93                 if (value[i] != other[i]) {
  94                     return false;
  95                 }
  96             }
  97             return true;
  98         }
  99         return false;
 100     }
 101 
 102     @HotSpotIntrinsicCandidate
 103     public static int compareTo(byte[] value, byte[] other) {
 104         int len1 = value.length;
 105         int len2 = other.length;
 106         return compareTo(value, other, len1, len2);
 107     }
 108 
 109     public static int compareTo(byte[] value, byte[] other, int len1, int len2) {
 110         int lim = Math.min(len1, len2);
 111         for (int k = 0; k < lim; k++) {
 112             if (value[k] != other[k]) {
 113                 return getChar(value, k) - getChar(other, k);
 114             }
 115         }
 116         return len1 - len2;
 117     }
 118 
 119     @HotSpotIntrinsicCandidate
 120     public static int compareToUTF16(byte[] value, byte[] other) {
 121         int len1 = length(value);
 122         int len2 = StringUTF16.length(other);
 123         return compareToUTF16Values(value, other, len1, len2);
 124     }
 125 
 126     /*
 127      * Checks the boundary and then compares the byte arrays.
 128      */
 129     public static int compareToUTF16(byte[] value, byte[] other, int len1, int len2) {
 130         checkOffset(len1, length(value));
 131         checkOffset(len2, StringUTF16.length(other));
 132 
 133         return compareToUTF16Values(value, other, len1, len2);
 134     }
 135 
 136     private static int compareToUTF16Values(byte[] value, byte[] other, int len1, int len2) {
 137         int lim = Math.min(len1, len2);
 138         for (int k = 0; k < lim; k++) {
 139             char c1 = getChar(value, k);
 140             char c2 = StringUTF16.getChar(other, k);
 141             if (c1 != c2) {
 142                 return c1 - c2;
 143             }
 144         }
 145         return len1 - len2;
 146     }
 147 
 148     public static int compareToCI(byte[] value, byte[] other) {
 149         int len1 = value.length;
 150         int len2 = other.length;
 151         int lim = Math.min(len1, len2);
 152         for (int k = 0; k < lim; k++) {
 153             if (value[k] != other[k]) {
 154                 char c1 = (char) CharacterDataLatin1.instance.toUpperCase(getChar(value, k));
 155                 char c2 = (char) CharacterDataLatin1.instance.toUpperCase(getChar(other, k));
 156                 if (c1 != c2) {


< prev index next >