From f7e4a8f2051f38b0651239bff523ac027ee8ab05 Mon Sep 17 00:00:00 2001 From: Craig Cornelius Date: Thu, 22 Sep 2016 22:49:46 +0000 Subject: [PATCH] ICU-12716 Resolved StringEquality issues reported by ErrorProne (Android) X-SVN-Rev: 39334 --- .../src/com/ibm/icu/charset/CharsetLMBCS.java | 2 +- .../com/ibm/icu/impl/coll/TailoredSet.java | 5 +- .../core/src/com/ibm/icu/impl/Utility.java | 9 + .../com/ibm/icu/impl/locale/AsciiUtil.java | 6 +- .../com/ibm/icu/text/CurrencyMetaInfo.java | 42 +++-- .../src/com/ibm/icu/text/SpoofChecker.java | 3 +- .../core/src/com/ibm/icu/text/UTF16.java | 177 +++++++++--------- .../ibm/icu/text/TransliteratorRegistry.java | 5 +- 8 files changed, 134 insertions(+), 115 deletions(-) diff --git a/icu4j/main/classes/charset/src/com/ibm/icu/charset/CharsetLMBCS.java b/icu4j/main/classes/charset/src/com/ibm/icu/charset/CharsetLMBCS.java index feafebe5960..b920fcba8d4 100644 --- a/icu4j/main/classes/charset/src/com/ibm/icu/charset/CharsetLMBCS.java +++ b/icu4j/main/classes/charset/src/com/ibm/icu/charset/CharsetLMBCS.java @@ -506,7 +506,7 @@ class CharsetLMBCS extends CharsetICU { } while (LocaleLMBCSGrpMap[index].LocaleID != null) { - if (LocaleLMBCSGrpMap[index].LocaleID == LocaleID) { + if (LocaleLMBCSGrpMap[index].LocaleID.equals(LocaleID)) { return LocaleLMBCSGrpMap[index].OptGroup; } else if (LocaleLMBCSGrpMap[index].LocaleID.compareTo(LocaleID) > 0){ break; diff --git a/icu4j/main/classes/collate/src/com/ibm/icu/impl/coll/TailoredSet.java b/icu4j/main/classes/collate/src/com/ibm/icu/impl/coll/TailoredSet.java index bb754f3128d..26ce864a55d 100644 --- a/icu4j/main/classes/collate/src/com/ibm/icu/impl/coll/TailoredSet.java +++ b/icu4j/main/classes/collate/src/com/ibm/icu/impl/coll/TailoredSet.java @@ -17,6 +17,7 @@ import java.util.Iterator; import com.ibm.icu.impl.Normalizer2Impl.Hangul; import com.ibm.icu.impl.Trie2; +import com.ibm.icu.impl.Utility; import com.ibm.icu.text.UnicodeSet; import com.ibm.icu.util.CharsTrie; import com.ibm.icu.util.CharsTrie.Entry; @@ -258,7 +259,7 @@ public final class TailoredSet { bp = none; } } - if (tp == none && bp == none) { + if (Utility.sameObjects(tp, none) && Utility.sameObjects(bp, none)) { break; } int cmp = tp.compareTo(bp); @@ -315,7 +316,7 @@ public final class TailoredSet { bs = none; } } - if (ts == none && bs == none) { + if (Utility.sameObjects(ts, none) && Utility.sameObjects(bs, none)) { break; } int cmp = ts.compareTo(bs); diff --git a/icu4j/main/classes/core/src/com/ibm/icu/impl/Utility.java b/icu4j/main/classes/core/src/com/ibm/icu/impl/Utility.java index 060bc163583..c1790a53f06 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/impl/Utility.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/impl/Utility.java @@ -172,6 +172,15 @@ public final class Utility { return true; } + /** + * Trivial reference equality. + * This method should help document that we really want == not equals(), + * and to have a single place to suppress warnings from static analysis tools. + */ + public static final boolean sameObjects(Object a, Object b) { + return a == b; + } + /** * Convenience utility. Does null checks on objects, then calls equals. */ diff --git a/icu4j/main/classes/core/src/com/ibm/icu/impl/locale/AsciiUtil.java b/icu4j/main/classes/core/src/com/ibm/icu/impl/locale/AsciiUtil.java index fe29229cc1e..527230eca22 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/impl/locale/AsciiUtil.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/impl/locale/AsciiUtil.java @@ -8,9 +8,11 @@ */ package com.ibm.icu.impl.locale; +import com.ibm.icu.impl.Utility; + public final class AsciiUtil { public static boolean caseIgnoreMatch(String s1, String s2) { - if (s1 == s2) { + if (Utility.sameObjects(s1, s2)) { return true; } int len = s1.length(); @@ -30,7 +32,7 @@ public final class AsciiUtil { } public static int caseIgnoreCompare(String s1, String s2) { - if (s1 == s2) { + if (Utility.sameObjects(s1, s2)) { return 0; } return AsciiUtil.toLowerString(s1).compareTo(AsciiUtil.toLowerString(s2)); diff --git a/icu4j/main/classes/core/src/com/ibm/icu/text/CurrencyMetaInfo.java b/icu4j/main/classes/core/src/com/ibm/icu/text/CurrencyMetaInfo.java index fbdde928b88..19be546efee 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/text/CurrencyMetaInfo.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/text/CurrencyMetaInfo.java @@ -14,19 +14,20 @@ import java.util.Date; import java.util.List; import com.ibm.icu.impl.Grego; +import com.ibm.icu.impl.Utility; import com.ibm.icu.util.Currency.CurrencyUsage; /** * Provides information about currencies that is not specific to a locale. - * + * * A note about currency dates. The CLDR data provides data to the day, * inclusive. The date information used by CurrencyInfo and CurrencyFilter - * is represented by milliseconds, which is overly precise. These times are + * is represented by milliseconds, which is overly precise. These times are * in GMT, so queries involving dates should use GMT times, but more generally * you should avoid relying on time of day in queries. - * + * * This class is not intended for public subclassing. - * + * * @stable ICU 4.4 */ public class CurrencyMetaInfo { @@ -43,7 +44,7 @@ public class CurrencyMetaInfo { } /** - * Returns the unique instance of the currency meta info, or null if + * Returns the unique instance of the currency meta info, or null if * noSubstitute is true and there is no data to support this API. * @param noSubstitute true if no substitute data should be used * @return the meta info, or null @@ -101,7 +102,7 @@ public class CurrencyMetaInfo { * @stable ICU 4.4 */ public final long to; - + /** * true if we are filtering only for currencies used as legal tender. * @internal @@ -116,7 +117,7 @@ public class CurrencyMetaInfo { this.from = from; this.to = to; this.tenderOnly = tenderOnly; - + } private static final CurrencyFilter ALL = new CurrencyFilter( @@ -187,7 +188,7 @@ public class CurrencyMetaInfo { public static CurrencyFilter onDateRange(Date from, Date to) { return ALL.withDateRange(from, to); } - + /** * Returns a filter that accepts all currencies in use on the given date. * @param date the date as milliseconds after Jan 1, 1970 @@ -210,7 +211,7 @@ public class CurrencyMetaInfo { public static CurrencyFilter onDateRange(long from, long to) { return ALL.withDateRange(from, to); } - + /** * Returns a CurrencyFilter for finding currencies that were either once used, * are used, or will be used as tender. @@ -268,7 +269,7 @@ public class CurrencyMetaInfo { long toLong = to == null ? Long.MAX_VALUE : to.getTime(); return new CurrencyFilter(this.region, this.currency, fromLong, toLong, this.tenderOnly); } - + /** * Returns a copy of this filter that accepts all currencies in use on * the given date. @@ -292,7 +293,7 @@ public class CurrencyMetaInfo { public CurrencyFilter withDateRange(long from, long to) { return new CurrencyFilter(this.region, this.currency, from, to, this.tenderOnly); } - + /** * Returns a copy of this filter that filters for currencies that were * either once used, are used, or will be used as tender. @@ -359,7 +360,8 @@ public class CurrencyMetaInfo { } private static boolean equals(String lhs, String rhs) { - return lhs == rhs || (lhs != null && lhs.equals(rhs)); + return (Utility.sameObjects(lhs, rhs) || + (lhs != null && lhs.equals(rhs))); } } @@ -422,8 +424,8 @@ public class CurrencyMetaInfo { public final String code; /** - * Date on which the currency was first officially used in the region. - * This is midnight at the start of the first day on which the currency was used, GMT. + * Date on which the currency was first officially used in the region. + * This is midnight at the start of the first day on which the currency was used, GMT. * If there is no date, this is Long.MIN_VALUE; * @stable ICU 4.4 */ @@ -433,7 +435,7 @@ public class CurrencyMetaInfo { * Date at which the currency stopped being officially used in the region. * This is one millisecond before midnight at the end of the last day on which the currency was used, GMT. * If there is no date, this is Long.MAX_VALUE. - * + * * @stable ICU 4.4 */ public final long to; @@ -445,8 +447,8 @@ public class CurrencyMetaInfo { * @stable ICU 49 */ public final int priority; - - + + private final boolean tender; /** @@ -456,10 +458,10 @@ public class CurrencyMetaInfo { public CurrencyInfo(String region, String code, long from, long to, int priority) { this(region, code, from, to, priority, true); } - + /** * Constructs a currency info. - * + * * @internal * @deprecated This API is ICU internal only. */ @@ -482,7 +484,7 @@ public class CurrencyMetaInfo { public String toString() { return debugString(this); } - + /** * Determine whether or not this currency was once used, is used, * or will be used as tender in this region. diff --git a/icu4j/main/classes/core/src/com/ibm/icu/text/SpoofChecker.java b/icu4j/main/classes/core/src/com/ibm/icu/text/SpoofChecker.java index 4e05205bbd6..ae64a91d208 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/text/SpoofChecker.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/text/SpoofChecker.java @@ -33,6 +33,7 @@ import java.util.regex.Pattern; import com.ibm.icu.impl.ICUBinary; import com.ibm.icu.impl.ICUBinary.Authenticate; +import com.ibm.icu.impl.Utility; import com.ibm.icu.lang.UCharacter; import com.ibm.icu.lang.UCharacterCategory; import com.ibm.icu.lang.UProperty; @@ -1792,7 +1793,7 @@ public class SpoofChecker { return false; if (!Arrays.equals(fCFUValues, otherData.fCFUValues)) return false; - if (fCFUStrings != otherData.fCFUStrings && fCFUStrings != null + if (!Utility.sameObjects(fCFUStrings, otherData.fCFUStrings) && fCFUStrings != null && !fCFUStrings.equals(otherData.fCFUStrings)) return false; return true; diff --git a/icu4j/main/classes/core/src/com/ibm/icu/text/UTF16.java b/icu4j/main/classes/core/src/com/ibm/icu/text/UTF16.java index 0c124a5f336..39ec183f9a0 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/text/UTF16.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/text/UTF16.java @@ -9,6 +9,8 @@ package com.ibm.icu.text; +import com.ibm.icu.impl.Utility; + /** *

* Standalone utility class providing UTF16 character conversions and indexing conversions. @@ -23,27 +25,27 @@ package com.ibm.icu.text; * Examples: *

* The following examples illustrate use of some of these methods. - * + * *

  * // iteration forwards: Original
  * for (int i = 0; i < s.length(); ++i) {
  *     char ch = s.charAt(i);
  *     doSomethingWith(ch);
  * }
- * 
+ *
  * // iteration forwards: Changes for UTF-32
  * int ch;
  * for (int i = 0; i < s.length(); i += UTF16.getCharCount(ch)) {
  *     ch = UTF16.charAt(s, i);
  *     doSomethingWith(ch);
  * }
- * 
+ *
  * // iteration backwards: Original
  * for (int i = s.length() - 1; i >= 0; --i) {
  *     char ch = s.charAt(i);
  *     doSomethingWith(ch);
  * }
- * 
+ *
  * // iteration backwards: Changes for UTF-32
  * int ch;
  * for (int i = s.length() - 1; i > 0; i -= UTF16.getCharCount(ch)) {
@@ -51,7 +53,7 @@ package com.ibm.icu.text;
  *     doSomethingWith(ch);
  * }
  * 
- * + * * Notes: * - * + * * @author Mark Davis, with help from Markus Scherer * @stable ICU 2.1 */ @@ -87,7 +89,7 @@ public final class UTF16 { * Value returned in {@link #bounds(String, int) bounds()}. * These values are chosen specifically so that it actually represents the position of the * character [offset16 - (value >> 2), offset16 + (value & 3)] - * + * * @stable ICU 2.1 */ public static final int SINGLE_CHAR_BOUNDARY = 1, LEAD_SURROGATE_BOUNDARY = 2, @@ -95,63 +97,63 @@ public final class UTF16 { /** * The lowest Unicode code point value. - * + * * @stable ICU 2.1 */ public static final int CODEPOINT_MIN_VALUE = 0; /** * The highest Unicode code point value (scalar value) according to the Unicode Standard. - * + * * @stable ICU 2.1 */ public static final int CODEPOINT_MAX_VALUE = 0x10ffff; /** * The minimum value for Supplementary code points - * + * * @stable ICU 2.1 */ public static final int SUPPLEMENTARY_MIN_VALUE = 0x10000; /** * Lead surrogate minimum value - * + * * @stable ICU 2.1 */ public static final int LEAD_SURROGATE_MIN_VALUE = 0xD800; /** * Trail surrogate minimum value - * + * * @stable ICU 2.1 */ public static final int TRAIL_SURROGATE_MIN_VALUE = 0xDC00; /** * Lead surrogate maximum value - * + * * @stable ICU 2.1 */ public static final int LEAD_SURROGATE_MAX_VALUE = 0xDBFF; /** * Trail surrogate maximum value - * + * * @stable ICU 2.1 */ public static final int TRAIL_SURROGATE_MAX_VALUE = 0xDFFF; /** * Surrogate minimum value - * + * * @stable ICU 2.1 */ public static final int SURROGATE_MIN_VALUE = LEAD_SURROGATE_MIN_VALUE; /** * Maximum surrogate value - * + * * @stable ICU 2.1 */ public static final int SURROGATE_MAX_VALUE = TRAIL_SURROGATE_MAX_VALUE; @@ -206,7 +208,7 @@ public final class UTF16 { * on the return value. If the char retrieved is part of a surrogate pair, its supplementary * character will be returned. If a complete supplementary character is not found the incomplete * character will be returned - * + * * @param source Array of UTF-16 chars * @param offset16 UTF-16 offset to the start of the character. * @return UTF-32 value for the UTF-32 value that contains the char at offset16. The boundaries @@ -260,7 +262,7 @@ public final class UTF16 { * on the return value. If the char retrieved is part of a surrogate pair, its supplementary * character will be returned. If a complete supplementary character is not found the incomplete * character will be returned - * + * * @param source Array of UTF-16 chars * @param offset16 UTF-16 offset to the start of the character. * @return UTF-32 value for the UTF-32 value that contains the char at offset16. The boundaries @@ -316,7 +318,7 @@ public final class UTF16 { * on the return value. If the char retrieved is part of a surrogate pair, its supplementary * character will be returned. If a complete supplementary character is not found the incomplete * character will be returned - * + * * @param source UTF-16 chars string buffer * @param offset16 UTF-16 offset to the start of the character. * @return UTF-32 value for the UTF-32 value that contains the char at offset16. The boundaries @@ -366,7 +368,7 @@ public final class UTF16 { * on the return value. If the char retrieved is part of a surrogate pair, its supplementary * character will be returned. If a complete supplementary character is not found the incomplete * character will be returned - * + * * @param source Array of UTF-16 chars * @param start Offset to substring in the source array for analyzing * @param limit Offset to substring in the source array for analyzing @@ -419,7 +421,7 @@ public final class UTF16 { * on the return value. If the char retrieved is part of a surrogate pair, its supplementary * character will be returned. If a complete supplementary character is not found the incomplete * character will be returned - * + * * @param source UTF-16 chars string buffer * @param offset16 UTF-16 offset to the start of the character. * @return UTF-32 value for the UTF-32 value that contains the char at offset16. The boundaries @@ -465,7 +467,7 @@ public final class UTF16 { * Determines how many chars this char32 requires. If a validity check is required, use * isLegal() * on char32 before calling. - * + * * @param char32 The input codepoint. * @return 2 if is in supplementary space, otherwise 1. * @stable ICU 2.1 @@ -479,7 +481,7 @@ public final class UTF16 { /** * Returns the type of the boundaries around the char at offset16. Used for random access. - * + * * @param source Text to analyse * @param offset16 UTF-16 offset * @return @@ -515,7 +517,7 @@ public final class UTF16 { /** * Returns the type of the boundaries around the char at offset16. Used for random access. - * + * * @param source String buffer to analyse * @param offset16 UTF16 offset * @return @@ -553,7 +555,7 @@ public final class UTF16 { * Returns the type of the boundaries around the char at offset16. Used for random access. Note * that the boundaries are determined with respect to the subarray, hence the char array * {0xD800, 0xDC00} has the result SINGLE_CHAR_BOUNDARY for start = offset16 = 0 and limit = 1. - * + * * @param source Char array to analyse * @param start Offset to substring in the source array for analyzing * @param limit Offset to substring in the source array for analyzing @@ -595,7 +597,7 @@ public final class UTF16 { /** * Determines whether the code value is a surrogate. - * + * * @param char16 The input character. * @return true If the input character is a surrogate. * @stable ICU 2.1 @@ -606,7 +608,7 @@ public final class UTF16 { /** * Determines whether the character is a trail surrogate. - * + * * @param char16 The input character. * @return true If the input character is a trail surrogate. * @stable ICU 2.1 @@ -617,7 +619,7 @@ public final class UTF16 { /** * Determines whether the character is a lead surrogate. - * + * * @param char16 The input character. * @return true If the input character is a lead surrogate * @stable ICU 2.1 @@ -630,7 +632,7 @@ public final class UTF16 { * Returns the lead surrogate. If a validity check is required, use * isLegal() on char32 * before calling. - * + * * @param char32 The input character. * @return lead surrogate if the getCharCount(ch) is 2;
* and 0 otherwise (note: 0 is not a valid lead surrogate). @@ -647,7 +649,7 @@ public final class UTF16 { * Returns the trail surrogate. If a validity check is required, use * isLegal() on char32 * before calling. - * + * * @param char32 The input character. * @return the trail surrogate if the getCharCount(ch) is 2;
* otherwise the character itself @@ -664,7 +666,7 @@ public final class UTF16 { * Convenience method corresponding to String.valueOf(char). Returns a one or two char string * containing the UTF-32 value in UTF16 format. If a validity check is required, use * {@link com.ibm.icu.lang.UCharacter#isLegal(int)} on char32 before calling. - * + * * @param char32 The input character. * @return string value of char32 in UTF16 format * @exception IllegalArgumentException Thrown if char32 is a invalid codepoint. @@ -684,7 +686,7 @@ public final class UTF16 { * required, use {@link com.ibm.icu.lang.UCharacter#isLegal(int)} on the * codepoint at offset16 before calling. The result returned will be a newly created String * obtained by calling source.substring(..) with the appropriate indexes. - * + * * @param source The input string. * @param offset16 The UTF16 index to the codepoint in source * @return string value of char32 in UTF16 format @@ -708,7 +710,7 @@ public final class UTF16 { * is required, use {@link com.ibm.icu.lang.UCharacter#isLegal(int)} on * the codepoint at offset16 before calling. The result returned will be a newly created String * obtained by calling source.substring(..) with the appropriate indexes. - * + * * @param source The input string buffer. * @param offset16 The UTF16 index to the codepoint in source * @return string value of char32 in UTF16 format @@ -734,7 +736,7 @@ public final class UTF16 { * {@link com.ibm.icu.lang.UCharacter#isLegal(int)} on the codepoint at * offset16 before calling. The result returned will be a newly created String containing the * relevant characters. - * + * * @param source The input char array. * @param start Start index of the subarray * @param limit End index of the subarray @@ -755,7 +757,7 @@ public final class UTF16 { /** * Returns the UTF-16 offset that corresponds to a UTF-32 offset. Used for random access. See * the {@link UTF16 class description} for notes on roundtripping. - * + * * @param source The UTF-16 string * @param offset32 UTF-32 offset * @return UTF-16 offset @@ -787,7 +789,7 @@ public final class UTF16 { /** * Returns the UTF-16 offset that corresponds to a UTF-32 offset. Used for random access. See * the {@link UTF16 class description} for notes on roundtripping. - * + * * @param source The UTF-16 string buffer * @param offset32 UTF-32 offset * @return UTF-16 offset @@ -819,7 +821,7 @@ public final class UTF16 { /** * Returns the UTF-16 offset that corresponds to a UTF-32 offset. Used for random access. See * the {@link UTF16 class description} for notes on roundtripping. - * + * * @param source The UTF-16 char array whose substring is to be analysed * @param start Offset of the substring to be analysed * @param limit Offset of the substring to be analysed @@ -858,11 +860,11 @@ public final class UTF16 { * of the lead of the pair is returned. *

* To find the UTF-32 length of a string, use: - * + * *

      * len32 = countCodePoint(source, source.length());
      * 
- * + * * @param source Text to analyse * @param offset16 UTF-16 offset < source text length. * @return UTF-32 offset @@ -909,7 +911,7 @@ public final class UTF16 { * of the lead of the pair is returned. *

* To find the UTF-32 length of a string, use: - * + * *

      * len32 = countCodePoint(source);
      * 
@@ -960,7 +962,7 @@ public final class UTF16 { * of the lead of the pair is returned. *

* To find the UTF-32 length of a substring, use: - * + * *

      * len32 = countCodePoint(source, start, limit);
      * 
@@ -1010,7 +1012,7 @@ public final class UTF16 { * Append a single UTF-32 value to the end of a StringBuffer. If a validity check is required, * use {@link com.ibm.icu.lang.UCharacter#isLegal(int)} on char32 before * calling. - * + * * @param target The buffer to append to * @param char32 Value to append. * @return the updated StringBuffer @@ -1036,7 +1038,7 @@ public final class UTF16 { /** * Cover JDK 1.5 APIs. Append the code point to the buffer and return the buffer as a * convenience. - * + * * @param target The buffer to append to * @param cp The code point to append * @return the updated StringBuffer @@ -1049,7 +1051,7 @@ public final class UTF16 { /** * Adds a codepoint to offset16 position of the argument char array. - * + * * @param target Char array to be append with the new code point * @param limit UTF16 offset which the codepoint will be appended. * @param char32 Code point to be appended @@ -1075,7 +1077,7 @@ public final class UTF16 { /** * Number of codepoints in a UTF16 String - * + * * @param source UTF16 string * @return number of codepoint in string * @stable ICU 2.1 @@ -1089,7 +1091,7 @@ public final class UTF16 { /** * Number of codepoints in a UTF16 String buffer - * + * * @param source UTF16 string buffer * @return number of codepoint in string * @stable ICU 2.1 @@ -1103,7 +1105,7 @@ public final class UTF16 { /** * Number of codepoints in a UTF16 char array substring - * + * * @param source UTF16 char array * @param start Offset of the substring * @param limit Offset of the substring @@ -1121,7 +1123,7 @@ public final class UTF16 { /** * Set a code point into a UTF16 position. Adjusts target according if we are replacing a * non-supplementary codepoint with a supplementary and vice versa. - * + * * @param target Stringbuffer * @param offset16 UTF16 position to insert into * @param char32 Code point @@ -1152,7 +1154,7 @@ public final class UTF16 { /** * Set a code point into a UTF16 position in a char array. Adjusts target according if we are * replacing a non-supplementary codepoint with a supplementary and vice versa. - * + * * @param target char array * @param limit numbers of valid chars in target, different from target.length. limit counts the * number of chars in target that represents a string, not the size of array target. @@ -1218,7 +1220,7 @@ public final class UTF16 { /** * Shifts offset16 by the argument number of codepoints - * + * * @param source string * @param offset16 UTF16 position to shift * @param shift32 number of codepoints to shift @@ -1272,7 +1274,7 @@ public final class UTF16 { /** * Shifts offset16 by the argument number of codepoints - * + * * @param source String buffer * @param offset16 UTF16 position to shift * @param shift32 Number of codepoints to shift @@ -1326,7 +1328,7 @@ public final class UTF16 { /** * Shifts offset16 by the argument number of codepoints within a subarray. - * + * * @param source Char array * @param start Position of the subarray to be performed on * @param limit Position of the subarray to be performed on @@ -1401,7 +1403,7 @@ public final class UTF16 { *

* The offset argument must be greater than or equal to 0, and less than or equal to the length * of source. - * + * * @param target String buffer to insert to * @param offset16 Offset which char32 will be inserted in * @param char32 Codepoint to be inserted @@ -1429,7 +1431,7 @@ public final class UTF16 { *

*

* The offset argument must be greater than or equal to 0, and less than or equal to the limit. - * + * * @param target Char array to insert to * @param limit End index of the char array, limit <= target.length * @param offset16 Offset which char32 will be inserted in @@ -1458,7 +1460,7 @@ public final class UTF16 { /** * Removes the codepoint at the specified position in this target (shortening target by 1 * character if the codepoint is a non-supplementary, 2 otherwise). - * + * * @param target String buffer to remove codepoint from * @param offset16 Offset which the codepoint will be removed * @return a reference to target @@ -1483,7 +1485,7 @@ public final class UTF16 { /** * Removes the codepoint at the specified position in this target (shortening target by 1 * character if the codepoint is a non-supplementary, 2 otherwise). - * + * * @param target String buffer to remove codepoint from * @param limit End index of the char array, limit <= target.length * @param offset16 Offset which the codepoint will be removed @@ -1523,7 +1525,7 @@ public final class UTF16 { *

* Note this method is provided as support to jdk 1.3, which does not support supplementary * characters to its fullest. - * + * * @param source UTF16 format Unicode string that will be searched * @param char32 Codepoint to search for * @return the index of the first occurrence of the codepoint in the argument Unicode string, or @@ -1577,7 +1579,7 @@ public final class UTF16 { *

* Note this method is provided as support to jdk 1.3, which does not support supplementary * characters to its fullest. - * + * * @param source UTF16 format Unicode string that will be searched * @param str UTF16 format Unicode string to search for * @return the index of the first occurrence of the codepoint in the argument Unicode string, or @@ -1623,7 +1625,7 @@ public final class UTF16 { *

* Note this method is provided as support to jdk 1.3, which does not support supplementary * characters to its fullest. - * + * * @param source UTF16 format Unicode string that will be searched * @param char32 Codepoint to search for * @param fromIndex The index to start the search from. @@ -1679,7 +1681,7 @@ public final class UTF16 { *

* Note this method is provided as support to jdk 1.3, which does not support supplementary * characters to its fullest. - * + * * @param source UTF16 format Unicode string that will be searched * @param str UTF16 format Unicode string to search for * @param fromIndex The index to start the search from. @@ -1726,7 +1728,7 @@ public final class UTF16 { *

* Note this method is provided as support to jdk 1.3, which does not support supplementary * characters to its fullest. - * + * * @param source UTF16 format Unicode string that will be searched * @param char32 Codepoint to search for * @return the index of the last occurrence of the codepoint in source, or -1 if the codepoint @@ -1780,7 +1782,7 @@ public final class UTF16 { *

* Note this method is provided as support to jdk 1.3, which does not support supplementary * characters to its fullest. - * + * * @param source UTF16 format Unicode string that will be searched * @param str UTF16 format Unicode string to search for * @return the index of the last occurrence of the codepoint in source, or -1 if the codepoint @@ -1832,7 +1834,7 @@ public final class UTF16 { *

* Note this method is provided as support to jdk 1.3, which does not support supplementary * characters to its fullest. - * + * * @param source UTF16 format Unicode string that will be searched * @param char32 Codepoint to search for * @param fromIndex the index to start the search from. There is no restriction on the value of @@ -1898,7 +1900,7 @@ public final class UTF16 { *

* Note this method is provided as support to jdk 1.3, which does not support supplementary * characters to its fullest. - * + * * @param source UTF16 format Unicode string that will be searched * @param str UTF16 format Unicode string to search for * @param fromIndex the index to start the search from. There is no restriction on the value of @@ -1953,7 +1955,7 @@ public final class UTF16 { *

* Note this method is provided as support to jdk 1.3, which does not support supplementary * characters to its fullest. - * + * * @param source UTF16 format Unicode string which the codepoint replacements will be based on. * @param oldChar32 Non-zero old codepoint to be replaced. * @param newChar32 The new codepoint to replace oldChar32 @@ -2014,7 +2016,7 @@ public final class UTF16 { *

* Note this method is provided as support to jdk 1.3, which does not support supplementary * characters to its fullest. - * + * * @param source UTF16 format Unicode string which the replacements will be based on. * @param oldStr Non-zero-length string to be replaced. * @param newStr The new string to replace oldStr @@ -2049,7 +2051,7 @@ public final class UTF16 { * Examples:
* UTF16.reverse(new StringBuffer( "Supplementary characters \ud800\udc00\ud801\udc01"))
* returns "\ud801\udc01\ud800\udc00 sretcarahc yratnemelppuS". - * + * * @param source The source StringBuffer that contains UTF16 format Unicode string to be reversed * @return a modified source with reversed UTF16 format Unicode string. * @stable ICU 2.6 @@ -2080,7 +2082,7 @@ public final class UTF16 { * certain range, and never needs to count more than 'number + 1' code points. Logically * equivalent to (countCodePoint(s) > number). A Unicode code point may occupy either one or two * code units. - * + * * @param source The input string. * @param number The number of code points in the string is compared against the 'number' * parameter. @@ -2142,7 +2144,7 @@ public final class UTF16 { * needs to count more than 'number + 1' code points. Logically equivalent to * (countCodePoint(source, start, limit) > number). A Unicode code point may occupy either one * or two code units. - * + * * @param source Array of UTF-16 chars * @param start Offset to substring in the source array for analyzing * @param limit Offset to substring in the source array for analyzing @@ -2209,7 +2211,7 @@ public final class UTF16 { * length is within a certain range, and never needs to count more than 'number + 1' code * points. Logically equivalent to (countCodePoint(s) > number). A Unicode code point may * occupy either one or two code units. - * + * * @param source The input string buffer. * @param number The number of code points in the string buffer is compared against the 'number' * parameter. @@ -2266,7 +2268,7 @@ public final class UTF16 { /** * Cover JDK 1.5 API. Create a String from an array of codePoints. - * + * * @param codePoints The code array * @param offset The start of the text in the code point array * @param count The number of code points @@ -2326,7 +2328,7 @@ public final class UTF16 { * supplementary code points because they are stored as pairs of surrogates which are at * \ud800..\udfff. *

- * + * * @see #FOLD_CASE_DEFAULT * @see #FOLD_CASE_EXCLUDE_SPECIAL_I * @stable ICU 2.1 @@ -2336,7 +2338,7 @@ public final class UTF16 { /** * Default constructor that does code unit comparison and case sensitive comparison. - * + * * @stable ICU 2.1 */ public StringComparator() { @@ -2345,7 +2347,7 @@ public final class UTF16 { /** * Constructor that does comparison based on the argument options. - * + * * @param codepointcompare Flag to indicate true for code point comparison or false for code unit * comparison. * @param ignorecase False for case sensitive comparison, true for case-insensitive comparison @@ -2373,7 +2375,7 @@ public final class UTF16 { * *

Comparison is case insensitive, strings are folded using default mappings defined in * Unicode data file CaseFolding.txt, before comparison. - * + * * @stable ICU 2.4 */ public static final int FOLD_CASE_DEFAULT = 0; @@ -2385,7 +2387,7 @@ public final class UTF16 { * *

Comparison is case insensitive, strings are folded using modified mappings defined in * Unicode data file CaseFolding.txt, before comparison. - * + * * @stable ICU 2.4 * @see com.ibm.icu.lang.UCharacter#FOLD_CASE_EXCLUDE_SPECIAL_I */ @@ -2398,7 +2400,7 @@ public final class UTF16 { /** * Sets the comparison mode to code point compare if flag is true. Otherwise comparison mode * is set to code unit compare - * + * * @param flag True for code point compare, false for code unit compare * @stable ICU 2.4 */ @@ -2413,7 +2415,7 @@ public final class UTF16 { /** * Sets the Comparator to case-insensitive comparison mode if argument is true, otherwise * case sensitive comparison mode if set to false. - * + * * @param ignorecase True for case-insitive comparison, false for case sensitive comparison * @param foldcaseoption FOLD_CASE_DEFAULT or FOLD_CASE_EXCLUDE_SPECIAL_I. This option is used only * when ignorecase is set to true. If ignorecase is false, this option is @@ -2434,7 +2436,7 @@ public final class UTF16 { /** * Checks if the comparison mode is code point compare. - * + * * @return true for code point compare, false for code unit compare * @stable ICU 2.4 */ @@ -2444,7 +2446,7 @@ public final class UTF16 { /** * Checks if Comparator is in the case insensitive mode. - * + * * @return true if Comparator performs case insensitive comparison, false otherwise * @stable ICU 2.4 */ @@ -2454,7 +2456,7 @@ public final class UTF16 { /** * Gets the fold case options set in Comparator to be used with case insensitive comparison. - * + * * @return either FOLD_CASE_DEFAULT or FOLD_CASE_EXCLUDE_SPECIAL_I * @see #FOLD_CASE_DEFAULT * @see #FOLD_CASE_EXCLUDE_SPECIAL_I @@ -2468,7 +2470,7 @@ public final class UTF16 { /** * Compare two strings depending on the options selected during construction. - * + * * @param a first source string. * @param b second source string. * @return 0 returned if a == b. If a < b, a negative value is returned. Otherwise if a > b, @@ -2476,8 +2478,9 @@ public final class UTF16 { * @exception ClassCastException thrown when either a or b is not a String object * @stable ICU 4.4 */ + @Override public int compare(String a, String b) { - if (a == b) { + if (Utility.sameObjects(a, b)) { return 0; } if (a == null) { @@ -2521,7 +2524,7 @@ public final class UTF16 { /** * Compares case insensitive. This is a direct port of ICU4C, to make maintainence life * easier. - * + * * @param s1 * first string to compare * @param s2 @@ -2536,7 +2539,7 @@ public final class UTF16 { /** * Compares case sensitive. This is a direct port of ICU4C, to make maintainence life * easier. - * + * * @param s1 * first string to compare * @param s2 @@ -2619,7 +2622,7 @@ public final class UTF16 { } // at this point, len = 2 - int cp = Character.codePointAt(s, 0); + int cp = Character.codePointAt(s, 0); if (cp > 0xFFFF) { // is surrogate pair return cp; } @@ -2691,7 +2694,7 @@ public final class UTF16 { *

* The result is a string whose length is 1 for non-supplementary code points, 2 otherwise. *

- * + * * @param ch * code point * @return string representation of the code point diff --git a/icu4j/main/classes/translit/src/com/ibm/icu/text/TransliteratorRegistry.java b/icu4j/main/classes/translit/src/com/ibm/icu/text/TransliteratorRegistry.java index a8dea71df8e..29603103c00 100644 --- a/icu4j/main/classes/translit/src/com/ibm/icu/text/TransliteratorRegistry.java +++ b/icu4j/main/classes/translit/src/com/ibm/icu/text/TransliteratorRegistry.java @@ -25,6 +25,7 @@ import java.util.ResourceBundle; import com.ibm.icu.impl.ICUData; import com.ibm.icu.impl.ICUResourceBundle; import com.ibm.icu.impl.LocaleUtility; +import com.ibm.icu.impl.Utility; import com.ibm.icu.lang.UScript; import com.ibm.icu.text.RuleBasedTransliterator.Data; import com.ibm.icu.util.CaseInsensitiveString; @@ -145,7 +146,7 @@ class TransliteratorRegistry { } public void reset() { - if (spec != top) { // [sic] pointer comparison + if (!Utility.sameObjects(spec, top)) { spec = top; isSpecLocale = (res != null); setupNext(); @@ -167,7 +168,7 @@ class TransliteratorRegistry { } } else { // Fallback to the script, which may be null - if (nextSpec != scriptName) { + if (!Utility.sameObjects(nextSpec, scriptName)) { nextSpec = scriptName; } else { nextSpec = null; -- 2.40.0