ICU-13413 Migrating some Utility class methods with Java 7 Objects class method

Previously, some developers accidentally introduced Java 7 Objects class utility methods. At that time, we once added Java 6 compatible implementation in com.ibm.icu.impl.Utility class. Now, we use Java 7 as the minimum supported Java version, so we can use Java 7 Objects class and methods.

There are some extra changes dropping generics type from constructor. For example from `ArrayList<String> output = new ArrayList<String>();` to `ArrayList<String> output = new ArrayList<>();`. The updated syntax is allowed since Java 7. We have eclipse project configured to normalize such expression, therefore, files touched by this commit were automatically updated. These changes are not directly related to Java 7 Objects method replacement.
This commit is contained in:
Yoshito Umaoka 2018-07-27 17:20:55 -04:00 committed by Shane Carr
parent d1c761762a
commit 135bb1e380
No known key found for this signature in database
GPG key ID: FCED3B24AAB18B5C
18 changed files with 199 additions and 240 deletions

View file

@ -13,13 +13,13 @@ import java.lang.reflect.Method;
import java.text.CharacterIterator;
import java.text.ParseException;
import java.util.Arrays;
import java.util.Objects;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import com.ibm.icu.impl.ClassLoaderUtil;
import com.ibm.icu.impl.Normalizer2Impl;
import com.ibm.icu.impl.Normalizer2Impl.ReorderingBuffer;
import com.ibm.icu.impl.Utility;
import com.ibm.icu.impl.coll.BOCSU;
import com.ibm.icu.impl.coll.Collation;
import com.ibm.icu.impl.coll.CollationCompare;
@ -72,7 +72,7 @@ import com.ibm.icu.util.VersionInfo;
*
* <p>
* <strong>Note</strong> that there are some differences between the Collation rule syntax used in Java and ICU4J:
*
*
* <ul>
* <li>According to the JDK documentation: <br>
* <i>Modifier '!' : Turns on Thai/Lao vowel-consonant swapping. If this rule is in force when a Thai vowel of the range
@ -91,7 +91,7 @@ import com.ibm.icu.util.VersionInfo;
* <strong>Examples</strong>
* <p>
* Creating Customized RuleBasedCollators: <blockquote>
*
*
* <pre>
* String simple = "&amp; a &lt; b &lt; c &lt; d";
* RuleBasedCollator simpleCollator = new RuleBasedCollator(simple);
@ -106,11 +106,11 @@ import com.ibm.icu.util.VersionInfo;
* + ", &#92;u00C6 &lt; &#92;u00F8 , &#92;u00D8";
* RuleBasedCollator norwegianCollator = new RuleBasedCollator(norwegian);
* </pre>
*
*
* </blockquote>
*
*
* Concatenating rules to combine <code>Collator</code>s: <blockquote>
*
*
* <pre>
* // Create an en_US Collator object
* RuleBasedCollator en_USCollator = (RuleBasedCollator)
@ -127,12 +127,12 @@ import com.ibm.icu.util.VersionInfo;
* new RuleBasedCollator(en_USRules + da_DKRules);
* // newCollator has the combined rules
* </pre>
*
*
* </blockquote>
*
*
* Making changes to an existing RuleBasedCollator to create a new <code>Collator</code> object, by appending changes to
* the existing rule: <blockquote>
*
*
* <pre>
* // Create a new Collator object with additional rules
* String addRules = "&amp; C &lt; ch, cH, Ch, CH";
@ -140,11 +140,11 @@ import com.ibm.icu.util.VersionInfo;
* new RuleBasedCollator(en_USCollator.getRules() + addRules);
* // myCollator contains the new rules
* </pre>
*
*
* </blockquote>
*
*
* How to change the order of non-spacing accents: <blockquote>
*
*
* <pre>
* // old rule with main accents
* String oldRules = "= &#92;u0301 ; &#92;u0300 ; &#92;u0302 ; &#92;u0308 "
@ -158,12 +158,12 @@ import com.ibm.icu.util.VersionInfo;
* String addOn = "&amp; &#92;u0300 ; &#92;u0308 ; &#92;u0302";
* RuleBasedCollator myCollator = new RuleBasedCollator(oldRules + addOn);
* </pre>
*
*
* </blockquote>
*
*
* Putting in a new primary ordering before the default setting, e.g. sort English characters before or after Japanese
* characters in the Japanese <code>Collator</code>: <blockquote>
*
*
* <pre>
* // get en_US Collator rules
* RuleBasedCollator en_USCollator
@ -176,7 +176,7 @@ import com.ibm.icu.util.VersionInfo;
* RuleBasedCollator myJapaneseCollator
* = new RuleBasedCollator(en_USCollator.getRules() + jaString);
* </pre>
*
*
* </blockquote>
* <p>
* This class is not subclassable
@ -240,7 +240,7 @@ public final class RuleBasedCollator extends Collator {
/**
* Clones the RuleBasedCollator
*
*
* @return a new instance of this RuleBasedCollator object
* @stable ICU 2.8
*/
@ -262,7 +262,7 @@ public final class RuleBasedCollator extends Collator {
/**
* Return a CollationElementIterator for the given String.
*
*
* @see CollationElementIterator
* @stable ICU 2.8
*/
@ -274,7 +274,7 @@ public final class RuleBasedCollator extends Collator {
/**
* Return a CollationElementIterator for the given CharacterIterator. The source iterator's integrity will be
* preserved since a new copy will be created for use.
*
*
* @see CollationElementIterator
* @stable ICU 2.8
*/
@ -287,7 +287,7 @@ public final class RuleBasedCollator extends Collator {
/**
* Return a CollationElementIterator for the given UCharacterIterator. The source iterator's integrity will be
* preserved since a new copy will be created for use.
*
*
* @see CollationElementIterator
* @stable ICU 2.8
*/
@ -336,7 +336,7 @@ public final class RuleBasedCollator extends Collator {
try {
RuleBasedCollator result = (RuleBasedCollator) super.clone();
// since all collation data in the RuleBasedCollator do not change
// we can safely assign the result.fields to this collator
// we can safely assign the result.fields to this collator
// except in cases where we can't
result.settings = settings.clone();
result.collationBuffer = null;
@ -407,7 +407,7 @@ public final class RuleBasedCollator extends Collator {
* Sets whether uppercase characters sort before lowercase characters or vice versa, in strength TERTIARY. The
* default mode is false, and so lowercase characters sort before uppercase characters. If true, sort upper case
* characters first.
*
*
* @param upperfirst
* true to sort uppercase characters before lowercase characters, false to sort lowercase characters
* before uppercase characters
@ -429,7 +429,7 @@ public final class RuleBasedCollator extends Collator {
* Sets the orders of lower cased characters to sort before upper cased characters, in strength TERTIARY. The
* default mode is false. If true is set, the RuleBasedCollator will sort lower cased characters before the upper
* cased ones. Otherwise, if false is set, the RuleBasedCollator will ignore case preferences.
*
*
* @param lowerfirst
* true for sorting lower cased characters before upper cased characters, false to ignore case
* preferences.
@ -450,7 +450,7 @@ public final class RuleBasedCollator extends Collator {
/**
* Sets the case first mode to the initial mode set during construction of the RuleBasedCollator. See
* setUpperCaseFirst(boolean) and setLowerCaseFirst(boolean) for more details.
*
*
* @see #isLowerCaseFirst
* @see #isUpperCaseFirst
* @see #setLowerCaseFirst(boolean)
@ -469,7 +469,7 @@ public final class RuleBasedCollator extends Collator {
/**
* Sets the alternate handling mode to the initial mode set during construction of the RuleBasedCollator. See
* setAlternateHandling(boolean) for more details.
*
*
* @see #setAlternateHandlingShifted(boolean)
* @see #isAlternateHandlingShifted()
* @stable ICU 2.8
@ -486,7 +486,7 @@ public final class RuleBasedCollator extends Collator {
/**
* Sets the case level mode to the initial mode set during construction of the RuleBasedCollator. See
* setCaseLevel(boolean) for more details.
*
*
* @see #setCaseLevel(boolean)
* @see #isCaseLevel
* @stable ICU 2.8
@ -503,7 +503,7 @@ public final class RuleBasedCollator extends Collator {
/**
* Sets the decomposition mode to the initial mode set during construction of the RuleBasedCollator. See
* setDecomposition(int) for more details.
*
*
* @see #getDecomposition
* @see #setDecomposition(int)
* @stable ICU 2.8
@ -520,7 +520,7 @@ public final class RuleBasedCollator extends Collator {
/**
* Sets the French collation mode to the initial mode set during construction of the RuleBasedCollator. See
* setFrenchCollation(boolean) for more details.
*
*
* @see #isFrenchCollation
* @see #setFrenchCollation(boolean)
* @stable ICU 2.8
@ -537,7 +537,7 @@ public final class RuleBasedCollator extends Collator {
/**
* Sets the collation strength to the initial mode set during the construction of the RuleBasedCollator. See
* setStrength(int) for more details.
*
*
* @see #setStrength(int)
* @see #getStrength
* @stable ICU 2.8
@ -572,7 +572,7 @@ public final class RuleBasedCollator extends Collator {
* which treats SECONDARY weights in the order they appear. If set to true, the SECONDARY weights will be sorted
* backwards. See the section on <a href="http://userguide.icu-project.org/collation/architecture">
* French collation</a> for more information.
*
*
* @param flag
* true to set the French collation on, false to set it off
* @stable ICU 2.8
@ -595,7 +595,7 @@ public final class RuleBasedCollator extends Collator {
* the code points with non-ignorable primary weights in the same way. If the mode is set to true, the behavior
* corresponds to SHIFTED defined in UCA, this causes code points with PRIMARY orders that are equal or below the
* variable top value to be ignored in PRIMARY order and moved to the QUATERNARY order.
*
*
* @param shifted
* true if SHIFTED behavior for alternate handling is desired, false for the NON_IGNORABLE behavior.
* @see #isAlternateHandlingShifted
@ -692,7 +692,7 @@ public final class RuleBasedCollator extends Collator {
* considered significant during comparison.
*
* <p>See the Collator class description for an example of use.
*
*
* @param newStrength
* the new strength value.
* @see #getStrength
@ -780,7 +780,7 @@ public final class RuleBasedCollator extends Collator {
* the top of one of the supported reordering groups,
* and it must not be beyond the last of those groups.
* See {@link #setMaxVariable(int)}.
*
*
* @param varTop
* one or more (if contraction) characters to which the variable top should be set
* @return variable top primary weight
@ -829,7 +829,7 @@ public final class RuleBasedCollator extends Collator {
* the top of one of the supported reordering groups,
* and it must not be beyond the last of those groups.
* See {@link #setMaxVariable(int)}.
*
*
* @param varTop primary weight, as returned by setVariableTop or getVariableTop
* @see #getVariableTop
* @see #setVariableTop(String)
@ -947,7 +947,7 @@ public final class RuleBasedCollator extends Collator {
/**
* Gets the collation tailoring rules for this RuleBasedCollator.
* Equivalent to String getRules(false).
*
*
* @return the collation tailoring rules
* @see #getRules(boolean)
* @stable ICU 2.8
@ -960,7 +960,7 @@ public final class RuleBasedCollator extends Collator {
* Returns current rules.
* The argument defines whether full rules (root collation + tailored) rules are returned
* or just the tailoring.
*
*
* <p>The root collation rules are an <i>approximation</i> of the root collator's sort order.
* They are almost never used or useful at runtime and can be removed from the data.
* See <a href="http://userguide.icu-project.org/collation/customization#TOC-Building-on-Existing-Locales">User Guide:
@ -983,7 +983,7 @@ public final class RuleBasedCollator extends Collator {
/**
* Get a UnicodeSet that contains all the characters and sequences tailored in this collator.
*
*
* @return a pointer to a UnicodeSet object containing all the code points and sequences that may sort differently
* than in the root collator.
* @stable ICU 2.4
@ -999,7 +999,7 @@ public final class RuleBasedCollator extends Collator {
/**
* Gets unicode sets containing contractions and/or expansions of a collator
*
*
* @param contractions
* if not null, set to contain contractions
* @param expansions
@ -1027,6 +1027,7 @@ public final class RuleBasedCollator extends Collator {
* @internal
* @deprecated This API is ICU internal only.
*/
@Deprecated
void internalAddContractions(int c, UnicodeSet set) {
new ContractionsAndExpansions(set, null, null, false).forCodePoint(data, c);
}
@ -1075,7 +1076,7 @@ public final class RuleBasedCollator extends Collator {
* Gets the simpler form of a CollationKey for the String source following the rules of this Collator and stores the
* result into the user provided argument key. If key has a internal byte array of length that's too small for the
* result, the internal byte array will be grown to the exact required size.
*
*
* @param source the text String to be transformed into a RawCollationKey
* @param key output RawCollationKey to store results
* @return If key is null, a new instance of RawCollationKey will be created and returned, otherwise the user
@ -1267,7 +1268,7 @@ public final class RuleBasedCollator extends Collator {
/**
* Return true if an uppercase character is sorted before the corresponding lowercase character. See
* setCaseFirst(boolean) for details.
*
*
* @see #setUpperCaseFirst
* @see #setLowerCaseFirst
* @see #isLowerCaseFirst
@ -1282,7 +1283,7 @@ public final class RuleBasedCollator extends Collator {
/**
* Return true if a lowercase character is sorted before the corresponding uppercase character. See
* setCaseFirst(boolean) for details.
*
*
* @see #setUpperCaseFirst
* @see #setLowerCaseFirst
* @see #isUpperCaseFirst
@ -1299,7 +1300,7 @@ public final class RuleBasedCollator extends Collator {
* then the alternate handling attribute for the Collator is SHIFTED. Otherwise if return value is false, then the
* alternate handling attribute for the Collator is NON_IGNORABLE See setAlternateHandlingShifted(boolean) for more
* details.
*
*
* @return true or false
* @see #setAlternateHandlingShifted(boolean)
* @see #setAlternateHandlingDefault
@ -1311,7 +1312,7 @@ public final class RuleBasedCollator extends Collator {
/**
* Checks if case level is set to true. See setCaseLevel(boolean) for details.
*
*
* @return the case level mode
* @see #setCaseLevelDefault
* @see #isCaseLevel
@ -1324,7 +1325,7 @@ public final class RuleBasedCollator extends Collator {
/**
* Checks if French Collation is set to true. See setFrenchCollation(boolean) for details.
*
*
* @return true if French Collation is set to true, false otherwise
* @see #setFrenchCollation(boolean)
* @see #setFrenchCollationDefault
@ -1354,7 +1355,7 @@ public final class RuleBasedCollator extends Collator {
/**
* {@icu} Gets the variable top value of a Collator.
*
*
* @return the variable top primary weight
* @see #getMaxVariable
* @stable ICU 2.6
@ -1367,7 +1368,7 @@ public final class RuleBasedCollator extends Collator {
/**
* Method to retrieve the numeric collation value. When numeric collation is turned on, this Collator generates a
* collation key for the numeric value of substrings of digits. This is a way to get '100' to sort AFTER '2'
*
*
* @see #setNumericCollation
* @see #setNumericCollationDefault
* @return true if numeric collation is turned on, false otherwise
@ -1377,15 +1378,15 @@ public final class RuleBasedCollator extends Collator {
return (settings.readOnly().options & CollationSettings.NUMERIC) != 0;
}
/**
/**
* Retrieves the reordering codes for this collator.
* These reordering codes are a combination of UScript codes and ReorderCodes.
* @return a copy of the reordering codes for this collator;
* @return a copy of the reordering codes for this collator;
* if none are set then returns an empty array
* @see #setReorderCodes
* @see Collator#getEquivalentReorderCodes
* @stable ICU 4.8
*/
*/
@Override
public int[] getReorderCodes() {
return settings.readOnly().reorderCodes.clone();
@ -1435,7 +1436,7 @@ public final class RuleBasedCollator extends Collator {
/**
* Generates a unique hash code for this RuleBasedCollator.
*
*
* @return the unique hash code for this Collator
* @stable ICU 2.8
*/
@ -1784,7 +1785,7 @@ public final class RuleBasedCollator extends Collator {
/**
* Get the version of this collator object.
*
*
* @return the version object associated with this collator
* @stable ICU 2.8
*/
@ -1799,7 +1800,7 @@ public final class RuleBasedCollator extends Collator {
/**
* Get the UCA version of this collator object.
*
*
* @return the version object associated with this collator
* @stable ICU 2.8
*/
@ -1861,10 +1862,10 @@ public final class RuleBasedCollator extends Collator {
// Another check we could do is that the actual locale is at
// the same level or less specific than the valid locale.
// TODO: Starting with Java 7, use Objects.equals(a, b).
if(Utility.objectEquals(actual, tailoring.actualLocale)) {
if(Objects.equals(actual, tailoring.actualLocale)) {
actualLocaleIsSameAsValid = false;
} else {
assert(Utility.objectEquals(actual, valid));
assert(Objects.equals(actual, valid));
actualLocaleIsSameAsValid = true;
}
// Do not modify tailoring.actualLocale:

View file

@ -10,6 +10,8 @@
*/
package com.ibm.icu.impl;
import java.util.Objects;
import com.ibm.icu.util.Freezable;
@ -23,16 +25,16 @@ public class Row<C0, C1, C2, C3, C4> implements java.lang.Comparable, Cloneable,
* Convenience Methods
*/
public static <C0, C1> R2<C0,C1> of(C0 p0, C1 p1) {
return new R2<C0,C1>(p0,p1);
return new R2<>(p0,p1);
}
public static <C0, C1, C2> R3<C0,C1,C2> of(C0 p0, C1 p1, C2 p2) {
return new R3<C0,C1,C2>(p0,p1,p2);
return new R3<>(p0,p1,p2);
}
public static <C0, C1, C2, C3> R4<C0,C1,C2,C3> of(C0 p0, C1 p1, C2 p2, C3 p3) {
return new R4<C0,C1,C2,C3>(p0,p1,p2,p3);
return new R4<>(p0,p1,p2,p3);
}
public static <C0, C1, C2, C3, C4> R5<C0,C1,C2,C3,C4> of(C0 p0, C1 p1, C2 p2, C3 p3, C4 p4) {
return new R5<C0,C1,C2,C3,C4>(p0,p1,p2,p3,p4);
return new R5<>(p0,p1,p2,p3,p4);
}
public static class R2<C0, C1> extends Row<C0, C1, C1, C1, C1> {
@ -119,7 +121,7 @@ public class Row<C0, C1, C2, C3, C4> implements java.lang.Comparable, Cloneable,
}
int i = 0;
for (Object item : items) {
if (!Utility.objectEquals(item, that.items[i++])) {
if (!Objects.equals(item, that.items[i++])) {
return false;
}
}

View file

@ -10,7 +10,6 @@ package com.ibm.icu.impl;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Locale;
import java.util.regex.Pattern;
@ -182,15 +181,6 @@ public final class Utility {
return a == b;
}
/**
* Convenience utility. Does null checks on objects, then calls equals.
*/
public final static boolean objectEquals(Object a, Object b) {
return a == null ?
b == null ? true : false :
b == null ? false : a.equals(b);
}
/**
* Convenience utility. Does null checks on objects, then calls compare.
*/
@ -1085,7 +1075,7 @@ public final class Utility {
public static String[] split(String s, char divider) {
int last = 0;
int i;
ArrayList<String> output = new ArrayList<String>();
ArrayList<String> output = new ArrayList<>();
for (i = 0; i < s.length(); ++i) {
if (s.charAt(i) == divider) {
output.add(s.substring(last,i));
@ -1809,46 +1799,6 @@ public final class Utility {
return buffer.toString();
}
/**
* This implementation is equivalent to Java 7+ Objects#equals(Object a, Object b)
*
* @param a an object
* @param b an object to be compared with a for equality
* @return true if the arguments are equal to each other and false otherwise
*/
public static boolean equals(Object a, Object b) {
return (a == b)
|| (a != null && b != null && a.equals(b));
}
/**
* This implementation is equivalent to Java 7+ Objects#hash(Object... values)
* @param values the values to be hashed
* @return a hash value of the sequence of input values
*/
public static int hash(Object... values) {
return Arrays.hashCode(values);
}
/**
* This implementation is equivalent to Java 7+ Objects#hashCode(Object o)
* @param o an object
* @return a hash value of a non-null argument and 0 for null argument
*/
public static int hashCode(Object o) {
return o == null ? 0 : o.hashCode();
}
/**
* This implementation is equivalent to Java 7+ Objects#toString(Object o)
* @param o an object
* @return the result of calling toStirng for a non-null argument and "null" for a
* null argument
*/
public static String toString(Object o) {
return o == null ? "null" : o.toString();
}
/**
* This implementation is equivalent to Java 8+ Math#addExact(int, int)
* @param x the first value

View file

@ -8,12 +8,12 @@ import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set;
import java.util.TreeMap;
import com.ibm.icu.impl.ICUData;
import com.ibm.icu.impl.ICUResourceBundle;
import com.ibm.icu.impl.Utility;
import com.ibm.icu.impl.locale.XCldrStub.HashMultimap;
import com.ibm.icu.impl.locale.XCldrStub.Multimap;
import com.ibm.icu.impl.locale.XCldrStub.Multimaps;
@ -45,14 +45,14 @@ public class XLikelySubtags {
static final Maker HASHMAP = new Maker() {
@Override
public Map<Object,Object> make() {
return new HashMap<Object,Object>();
return new HashMap<>();
}
};
static final Maker TREEMAP = new Maker() {
@Override
public Map<Object,Object> make() {
return new TreeMap<Object,Object>();
return new TreeMap<>();
}
};
}
@ -72,7 +72,7 @@ public class XLikelySubtags {
UResourceBundle metadata = UResourceBundle.getBundleInstance(ICUData.ICU_BASE_NAME,"metadata",ICUResourceBundle.ICU_DATA_CLASS_LOADER);
UResourceBundle metadataAlias = metadata.get("alias");
UResourceBundle territoryAlias = metadataAlias.get(key);
Map<String, String> toCanonical1 = new HashMap<String, String>();
Map<String, String> toCanonical1 = new HashMap<>();
for ( int i = 0 ; i < territoryAlias.getSize(); i++ ) {
UResourceBundle res = territoryAlias.get(i);
String aliasFrom = res.getKey();
@ -207,7 +207,7 @@ public class XLikelySubtags {
}
@Override
public int hashCode() {
return Utility.hash(language, script, region);
return Objects.hash(language, script, region);
}
}
@ -218,7 +218,7 @@ public class XLikelySubtags {
}
private static Map<String, String> getDefaultRawData() {
Map<String, String> rawData = new TreeMap<String, String>();
Map<String, String> rawData = new TreeMap<>();
UResourceBundle bundle = UResourceBundle.getBundleInstance( ICUData.ICU_BASE_NAME, "likelySubtags");
for (Enumeration<String> enumer = bundle.getKeys(); enumer.hasMoreElements();) {
String key = enumer.nextElement();
@ -247,7 +247,7 @@ public class XLikelySubtags {
// Splitter bar = Splitter.on('_');
// int last = -1;
// set the base data
Map<LSR,LSR> internCache = new HashMap<LSR,LSR>();
Map<LSR,LSR> internCache = new HashMap<>();
for (Entry<String, String> sourceTarget : rawData.entrySet()) {
LSR ltp = LSR.from(sourceTarget.getKey());
final String language = ltp.language;
@ -483,7 +483,7 @@ public class XLikelySubtags {
if (value instanceof Map) {
show((Map<?,?>)value, indent+"\t", output);
} else {
output.append("\t" + Utility.toString(value)).append("\n");
output.append("\t" + Objects.toString(value)).append("\n");
}
first = indent;
}

View file

@ -14,6 +14,7 @@ import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
@ -21,7 +22,6 @@ import java.util.TreeSet;
import com.ibm.icu.impl.ICUResourceBundle;
import com.ibm.icu.impl.Row;
import com.ibm.icu.impl.Row.R4;
import com.ibm.icu.impl.Utility;
import com.ibm.icu.impl.locale.XCldrStub.CollectionUtilities;
import com.ibm.icu.impl.locale.XCldrStub.ImmutableMap;
import com.ibm.icu.impl.locale.XCldrStub.ImmutableMultimap;
@ -56,7 +56,7 @@ public class XLocaleDistance {
static final LocaleDisplayNames english = LocaleDisplayNames.getInstance(ULocale.ENGLISH);
private static List<R4<String, String, Integer, Boolean>> xGetLanguageMatcherData() {
List<R4<String, String, Integer, Boolean>> distanceList = new ArrayList<R4<String, String, Integer, Boolean>>();
List<R4<String, String, Integer, Boolean>> distanceList = new ArrayList<>();
ICUResourceBundle suppData = LocaleMatcher.getICUSupplementalData();
ICUResourceBundle languageMatchingNew = suppData.findTopLevel("languageMatchingNew");
@ -84,7 +84,7 @@ public class XLocaleDistance {
ICUResourceBundle writtenParadigmLocales = (ICUResourceBundle) languageMatchingInfo.get("written")
.get("paradigmLocales");
// paradigmLocales{ "en", "en-GB",... }
HashSet<String> paradigmLocales = new HashSet<String>(Arrays.asList(writtenParadigmLocales.getStringArray()));
HashSet<String> paradigmLocales = new HashSet<>(Arrays.asList(writtenParadigmLocales.getStringArray()));
return Collections.unmodifiableSet(paradigmLocales);
}
@ -96,7 +96,7 @@ public class XLocaleDistance {
.get("matchVariable");
// matchVariable{ americas{"019"} cnsar{"HK+MO"} ...}
HashMap<String,String> matchVariables = new HashMap<String,String>();
HashMap<String,String> matchVariables = new HashMap<>();
for (Enumeration<String> enumer = writtenMatchVariables.getKeys(); enumer.hasMoreElements(); ) {
String key = enumer.nextElement();
matchVariables.put(key, writtenMatchVariables.getString(key));
@ -255,8 +255,8 @@ public class XLocaleDistance {
}
static class IdMakerFull<T> implements IdMapper<T,Integer> {
private final Map<T, Integer> objectToInt = new HashMap<T, Integer>();
private final List<T> intToObject = new ArrayList<T>();
private final Map<T, Integer> objectToInt = new HashMap<>();
private final List<T> intToObject = new ArrayList<>();
final String name; // for debugging
IdMakerFull(String name) {
@ -358,12 +358,12 @@ public class XLocaleDistance {
(obj != null
&& obj.getClass() == this.getClass()
&& distance == (other = (StringDistanceNode) obj).distance
&& Utility.equals(distanceTable, other.distanceTable)
&& Objects.equals(distanceTable, other.distanceTable)
&& super.equals(other));
}
@Override
public int hashCode() {
return distance ^ Utility.hashCode(distanceTable);
return distance ^ Objects.hashCode(distanceTable);
}
StringDistanceNode(int distance) {
@ -511,7 +511,7 @@ public class XLocaleDistance {
DistanceNode node = getNode(desired, supported);
if (node == null) {
// get the distance it would have
Output<DistanceTable> node2 = new Output<DistanceTable>();
Output<DistanceTable> node2 = new Output<>();
int distance = getDistance(desired, supported, node2, true);
// now add it
node = addSubtable(desired, supported, distance);
@ -589,7 +589,7 @@ public class XLocaleDistance {
@Override
public String toString(boolean abbreviate) {
return toString(abbreviate, "", new IdMakerFull<Object>("interner"), new StringBuilder()).toString();
return toString(abbreviate, "", new IdMakerFull<>("interner"), new StringBuilder()).toString();
}
public StringBuilder toString(boolean abbreviate, String indent, IdMakerFull<Object> intern, StringBuilder buffer) {
@ -638,7 +638,7 @@ public class XLocaleDistance {
@Override
public Set<String> getCloser(int threshold) {
Set<String> result = new HashSet<String>();
Set<String> result = new HashSet<>();
for (Entry<String, Map<String, DistanceNode>> e1 : subtables.entrySet()) {
String desired = e1.getKey();
for (Entry<String, DistanceNode> e2 : e1.getValue().entrySet()) {
@ -671,9 +671,9 @@ public class XLocaleDistance {
@Override
public Map<String, Set<String>> getInternalMatches() {
Map<String, Set<String>> result = new LinkedHashMap<String, Set<String>>();
Map<String, Set<String>> result = new LinkedHashMap<>();
for (Entry<String, Map<String, DistanceNode>> entry : subtables.entrySet()) {
result.put(entry.getKey(), new LinkedHashSet<String>(entry.getValue().keySet()));
result.put(entry.getKey(), new LinkedHashSet<>(entry.getValue().keySet()));
}
return result;
}
@ -745,7 +745,7 @@ public class XLocaleDistance {
int threshold,
DistanceOption distanceOption) {
Output<DistanceTable> subtable = new Output<DistanceTable>();
Output<DistanceTable> subtable = new Output<>();
int distance = languageDesired2Supported.getDistance(desiredLang, supportedlang, subtable, true);
boolean scriptFirst = distanceOption == DistanceOption.SCRIPT_FIRST;
@ -874,9 +874,9 @@ public class XLocaleDistance {
@SuppressWarnings({"unchecked", "rawtypes"})
List<Row.R4<List<String>, List<String>, Integer, Boolean>>[] sorted = new ArrayList[3];
sorted[0] = new ArrayList<Row.R4<List<String>, List<String>, Integer, Boolean>>();
sorted[1] = new ArrayList<Row.R4<List<String>, List<String>, Integer, Boolean>>();
sorted[2] = new ArrayList<Row.R4<List<String>, List<String>, Integer, Boolean>>();
sorted[0] = new ArrayList<>();
sorted[1] = new ArrayList<>();
sorted[2] = new ArrayList<>();
// sort the rules so that the language-only are first, then the language-script, and finally the language-script-region.
for (R4<String, String, Integer, Boolean> info : xGetLanguageMatcherData()) {
@ -920,8 +920,8 @@ public class XLocaleDistance {
// if (rule[0].equals("en_*_*") || rule[1].equals("*_*_*")) {
// int debug = 0;
// }
List<String> desiredBase = new ArrayList<String>(bar.splitToList(rule[0]));
List<String> supportedBase = new ArrayList<String>(bar.splitToList(rule[1]));
List<String> desiredBase = new ArrayList<>(bar.splitToList(rule[0]));
List<String> supportedBase = new ArrayList<>(bar.splitToList(rule[1]));
Integer distance = 100-Integer.parseInt(rule[2]);
printMatchXml(desiredBase, supportedBase, distance, false);
@ -971,7 +971,7 @@ public class XLocaleDistance {
}
private static String fixedName(List<String> match) {
List<String> alt = new ArrayList<String>(match);
List<String> alt = new ArrayList<>(match);
int size = alt.size();
assert size >= 1 && size <= 3;
@ -1132,7 +1132,7 @@ public class XLocaleDistance {
static class Builder {
final private Multimap<String, String> regionToRawPartition = TreeMultimap.create();
final private RegionSet regionSet = new RegionSet();
final private Set<ULocale> paradigms = new LinkedHashSet<ULocale>();
final private Set<ULocale> paradigms = new LinkedHashSet<>();
void add(String variable, String barString) {
Set<String> tempRegions = regionSet.parseSet(barString);
@ -1158,9 +1158,9 @@ public class XLocaleDistance {
}
RegionMapper build() {
final IdMakerFull<Collection<String>> id = new IdMakerFull<Collection<String>>("partition");
final IdMakerFull<Collection<String>> id = new IdMakerFull<>("partition");
Multimap<String,String> variableToPartitions = TreeMultimap.create();
Map<String,String> regionToPartition = new TreeMap<String,String>();
Map<String,String> regionToPartition = new TreeMap<>();
Multimap<String,String> partitionToRegions = TreeMultimap.create();
for (Entry<String, Set<String>> e : regionToRawPartition.asMap().entrySet()) {
@ -1207,7 +1207,7 @@ public class XLocaleDistance {
private static class RegionSet {
private enum Operation {add, remove}
// temporaries used in processing
final private Set<String> tempRegions = new TreeSet<String>();
final private Set<String> tempRegions = new TreeSet<>();
private Operation operation = null;
private Set<String> parseSet(String barString) {
@ -1235,7 +1235,7 @@ public class XLocaleDistance {
}
private Set<String> inverse() {
TreeSet<String> result = new TreeSet<String>(ALL_FINAL_REGIONS);
TreeSet<String> result = new TreeSet<>(ALL_FINAL_REGIONS);
result.removeAll(tempRegions);
return result;
}
@ -1295,7 +1295,7 @@ public class XLocaleDistance {
if (toId(item) != null) {
return (Map<K, T>) intern(item);
}
Map<K,T> copy = new LinkedHashMap<K,T>();
Map<K,T> copy = new LinkedHashMap<>();
for (Entry<K,T> entry : item.entrySet()) {
T value = entry.getValue();
if (value instanceof Map) {

View file

@ -3,8 +3,8 @@
package com.ibm.icu.impl.number;
import java.math.RoundingMode;
import java.util.Objects;
import com.ibm.icu.impl.Utility;
import com.ibm.icu.number.IntegerWidth;
import com.ibm.icu.number.Notation;
import com.ibm.icu.number.NumberFormatter.DecimalSeparatorDisplay;
@ -78,7 +78,7 @@ public class MacroProps implements Cloneable {
@Override
public int hashCode() {
return Utility.hash(notation,
return Objects.hash(notation,
unit,
perUnit,
precision,
@ -105,22 +105,22 @@ public class MacroProps implements Cloneable {
if (!(_other instanceof MacroProps))
return false;
MacroProps other = (MacroProps) _other;
return Utility.equals(notation, other.notation)
&& Utility.equals(unit, other.unit)
&& Utility.equals(perUnit, other.perUnit)
&& Utility.equals(precision, other.precision)
&& Utility.equals(roundingMode, other.roundingMode)
&& Utility.equals(grouping, other.grouping)
&& Utility.equals(padder, other.padder)
&& Utility.equals(integerWidth, other.integerWidth)
&& Utility.equals(symbols, other.symbols)
&& Utility.equals(unitWidth, other.unitWidth)
&& Utility.equals(sign, other.sign)
&& Utility.equals(decimal, other.decimal)
&& Utility.equals(affixProvider, other.affixProvider)
&& Utility.equals(scale, other.scale)
&& Utility.equals(rules, other.rules)
&& Utility.equals(loc, other.loc);
return Objects.equals(notation, other.notation)
&& Objects.equals(unit, other.unit)
&& Objects.equals(perUnit, other.perUnit)
&& Objects.equals(precision, other.precision)
&& Objects.equals(roundingMode, other.roundingMode)
&& Objects.equals(grouping, other.grouping)
&& Objects.equals(padder, other.padder)
&& Objects.equals(integerWidth, other.integerWidth)
&& Objects.equals(symbols, other.symbols)
&& Objects.equals(unitWidth, other.unitWidth)
&& Objects.equals(sign, other.sign)
&& Objects.equals(decimal, other.decimal)
&& Objects.equals(affixProvider, other.affixProvider)
&& Objects.equals(scale, other.scale)
&& Objects.equals(rules, other.rules)
&& Objects.equals(loc, other.loc);
}
@Override

View file

@ -5,10 +5,10 @@ package com.ibm.icu.impl.number.parse;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Objects;
import com.ibm.icu.impl.StandardPlural;
import com.ibm.icu.impl.StringSegment;
import com.ibm.icu.impl.Utility;
import com.ibm.icu.impl.number.AffixPatternProvider;
import com.ibm.icu.impl.number.AffixUtils;
import com.ibm.icu.impl.number.PatternStringUtils;
@ -88,7 +88,7 @@ public class AffixMatcher implements NumberParseMatcher {
// The affixes have interesting characters, or we are in strict mode.
// Use initial capacity of 6, the highest possible number of AffixMatchers.
StringBuilder sb = new StringBuilder();
ArrayList<AffixMatcher> matchers = new ArrayList<AffixMatcher>(6);
ArrayList<AffixMatcher> matchers = new ArrayList<>(6);
boolean includeUnpaired = 0 != (parseFlags & ParsingUtils.PARSE_FLAG_INCLUDE_UNPAIRED_AFFIXES);
SignDisplay signDisplay = (0 != (parseFlags & ParsingUtils.PARSE_FLAG_PLUS_SIGN_ALLOWED))
? SignDisplay.ALWAYS
@ -124,7 +124,7 @@ public class AffixMatcher implements NumberParseMatcher {
if (signum == 1) {
posPrefix = prefix;
posSuffix = suffix;
} else if (Utility.equals(prefix, posPrefix) && Utility.equals(suffix, posSuffix)) {
} else if (Objects.equals(prefix, posPrefix) && Objects.equals(suffix, posSuffix)) {
// Skip adding these matchers (we already have equivalents)
continue;
}
@ -137,10 +137,10 @@ public class AffixMatcher implements NumberParseMatcher {
matchers.add(getInstance(prefix, suffix, flags));
if (includeUnpaired && prefix != null && suffix != null) {
// The following if statements are designed to prevent adding two identical matchers.
if (signum == 1 || !Utility.equals(prefix, posPrefix)) {
if (signum == 1 || !Objects.equals(prefix, posPrefix)) {
matchers.add(getInstance(prefix, null, flags));
}
if (signum == 1 || !Utility.equals(suffix, posSuffix)) {
if (signum == 1 || !Objects.equals(suffix, posSuffix)) {
matchers.add(getInstance(null, suffix, flags));
}
}
@ -255,14 +255,14 @@ public class AffixMatcher implements NumberParseMatcher {
return false;
}
AffixMatcher other = (AffixMatcher) _other;
return Utility.equals(prefix, other.prefix)
&& Utility.equals(suffix, other.suffix)
return Objects.equals(prefix, other.prefix)
&& Objects.equals(suffix, other.suffix)
&& flags == other.flags;
}
@Override
public int hashCode() {
return Utility.hashCode(prefix) ^ Utility.hashCode(suffix) ^ flags;
return Objects.hashCode(prefix) ^ Objects.hashCode(suffix) ^ flags;
}
@Override

View file

@ -4,10 +4,10 @@ package com.ibm.icu.number;
import java.math.BigInteger;
import java.text.Format;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicLongFieldUpdater;
import com.ibm.icu.impl.StandardPlural;
import com.ibm.icu.impl.Utility;
import com.ibm.icu.impl.number.DecimalQuantity;
import com.ibm.icu.impl.number.DecimalQuantity_DualStorageBCD;
import com.ibm.icu.impl.number.LocalizedNumberFormatterAsFormat;
@ -103,13 +103,13 @@ public class LocalizedNumberFormatter extends NumberFormatterSettings<LocalizedN
MeasureUnit unit = input.getUnit();
Number number = input.getNumber();
// Use this formatter if possible
if (Utility.equals(resolve().unit, unit)) {
if (Objects.equals(resolve().unit, unit)) {
return format(number);
}
// This mechanism saves the previously used unit, so if the user calls this method with the
// same unit multiple times in a row, they get a more efficient code path.
LocalizedNumberFormatter withUnit = savedWithUnit;
if (withUnit == null || !Utility.equals(withUnit.resolve().unit, unit)) {
if (withUnit == null || !Objects.equals(withUnit.resolve().unit, unit)) {
withUnit = new LocalizedNumberFormatter(this, KEY_UNIT, unit);
savedWithUnit = withUnit;
}

View file

@ -18,6 +18,7 @@ import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.MissingResourceException;
import java.util.Objects;
import java.util.Set;
import com.ibm.icu.impl.ICUCache;
@ -27,7 +28,6 @@ import com.ibm.icu.impl.SimpleCache;
import com.ibm.icu.impl.UResource;
import com.ibm.icu.impl.UResource.Key;
import com.ibm.icu.impl.UResource.Value;
import com.ibm.icu.impl.Utility;
import com.ibm.icu.util.Calendar;
import com.ibm.icu.util.Freezable;
import com.ibm.icu.util.ICUCloneNotSupportedException;
@ -247,8 +247,8 @@ public class DateIntervalInfo implements Cloneable, Freezable<DateIntervalInfo>,
public boolean equals(Object a) {
if (a instanceof PatternInfo) {
PatternInfo patternInfo = (PatternInfo)a;
return Utility.objectEquals(fIntervalPatternFirstPart, patternInfo.fIntervalPatternFirstPart) &&
Utility.objectEquals(fIntervalPatternSecondPart, patternInfo.fIntervalPatternSecondPart) &&
return Objects.equals(fIntervalPatternFirstPart, patternInfo.fIntervalPatternFirstPart) &&
Objects.equals(fIntervalPatternSecondPart, patternInfo.fIntervalPatternSecondPart) &&
fFirstDateInPtnIsLaterDate == patternInfo.fFirstDateInPtnIsLaterDate;
}
return false;
@ -310,7 +310,7 @@ public class DateIntervalInfo implements Cloneable, Freezable<DateIntervalInfo>,
private static String EARLIEST_FIRST_PREFIX = "earliestFirst:";
// DateIntervalInfo cache
private final static ICUCache<String, DateIntervalInfo> DIICACHE = new SimpleCache<String, DateIntervalInfo>();
private final static ICUCache<String, DateIntervalInfo> DIICACHE = new SimpleCache<>();
// default interval pattern on the skeleton, {0} - {1}
@ -347,7 +347,7 @@ public class DateIntervalInfo implements Cloneable, Freezable<DateIntervalInfo>,
@Deprecated
public DateIntervalInfo()
{
fIntervalPatterns = new HashMap<String, Map<String, PatternInfo>>();
fIntervalPatterns = new HashMap<>();
fFallbackIntervalPattern = "{0} \u2013 {1}";
}
@ -570,7 +570,7 @@ public class DateIntervalInfo implements Cloneable, Freezable<DateIntervalInfo>,
*/
private void setup(ULocale locale) {
int DEFAULT_HASH_SIZE = 19;
fIntervalPatterns = new HashMap<String, Map<String, PatternInfo>>(DEFAULT_HASH_SIZE);
fIntervalPatterns = new HashMap<>(DEFAULT_HASH_SIZE);
// initialize to guard if there is no interval date format defined in
// resource files
fFallbackIntervalPattern = "{0} \u2013 {1}";
@ -598,7 +598,7 @@ public class DateIntervalInfo implements Cloneable, Freezable<DateIntervalInfo>,
setFallbackIntervalPattern(fallbackPattern);
// Already loaded calendar types
Set<String> loadedCalendarTypes = new HashSet<String>();
Set<String> loadedCalendarTypes = new HashSet<>();
while (calendarTypeToUse != null) {
// Throw an exception when a loop is detected
@ -776,7 +776,7 @@ public class DateIntervalInfo implements Cloneable, Freezable<DateIntervalInfo>,
Map<String, PatternInfo> patternsOfOneSkeleton = fIntervalPatterns.get(skeleton);
boolean emptyHash = false;
if (patternsOfOneSkeleton == null) {
patternsOfOneSkeleton = new HashMap<String, PatternInfo>();
patternsOfOneSkeleton = new HashMap<>();
emptyHash = true;
}
boolean order = fFirstDateInPtnIsLaterDate;
@ -968,11 +968,11 @@ public class DateIntervalInfo implements Cloneable, Freezable<DateIntervalInfo>,
private static Map<String, Map<String, PatternInfo>> cloneIntervalPatterns(
Map<String, Map<String, PatternInfo>> patterns) {
Map<String, Map<String, PatternInfo>> result = new HashMap<String, Map<String, PatternInfo>>();
Map<String, Map<String, PatternInfo>> result = new HashMap<>();
for (Entry<String, Map<String, PatternInfo>> skeletonEntry : patterns.entrySet()) {
String skeleton = skeletonEntry.getKey();
Map<String, PatternInfo> patternsOfOneSkeleton = skeletonEntry.getValue();
Map<String, PatternInfo> oneSetPtn = new HashMap<String, PatternInfo>();
Map<String, PatternInfo> oneSetPtn = new HashMap<>();
for (Entry<String, PatternInfo> calEntry : patternsOfOneSkeleton.entrySet()) {
String calField = calEntry.getKey();
PatternInfo value = calEntry.getValue();
@ -1170,9 +1170,9 @@ public class DateIntervalInfo implements Cloneable, Freezable<DateIntervalInfo>,
*/
@Deprecated
public Map<String,Set<String>> getPatterns() {
LinkedHashMap<String,Set<String>> result = new LinkedHashMap<String,Set<String>>();
LinkedHashMap<String,Set<String>> result = new LinkedHashMap<>();
for (Entry<String, Map<String, PatternInfo>> entry : fIntervalPatterns.entrySet()) {
result.put(entry.getKey(), new LinkedHashSet<String>(entry.getValue().keySet()));
result.put(entry.getKey(), new LinkedHashSet<>(entry.getValue().keySet()));
}
return result;
}
@ -1184,9 +1184,9 @@ public class DateIntervalInfo implements Cloneable, Freezable<DateIntervalInfo>,
*/
@Deprecated
public Map<String, Map<String, PatternInfo>> getRawPatterns() {
LinkedHashMap<String, Map<String, PatternInfo>> result = new LinkedHashMap<String, Map<String, PatternInfo>>();
LinkedHashMap<String, Map<String, PatternInfo>> result = new LinkedHashMap<>();
for (Entry<String, Map<String, PatternInfo>> entry : fIntervalPatterns.entrySet()) {
result.put(entry.getKey(), new LinkedHashMap<String, PatternInfo>(entry.getValue()));
result.put(entry.getKey(), new LinkedHashMap<>(entry.getValue()));
}
return result;
}

View file

@ -32,10 +32,10 @@ import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import com.ibm.icu.impl.PatternProps;
import com.ibm.icu.impl.Utility;
import com.ibm.icu.number.NumberFormatter;
import com.ibm.icu.text.MessagePattern.ArgType;
import com.ibm.icu.text.MessagePattern.Part;
@ -791,7 +791,7 @@ public class MessageFormat extends UFormat {
"This method is not available in MessageFormat objects " +
"that use alphanumeric argument names.");
}
ArrayList<Format> list = new ArrayList<Format>();
ArrayList<Format> list = new ArrayList<>();
for (int partIndex = 0; (partIndex = nextTopLevelArgStart(partIndex)) >= 0;) {
int argNumber = msgPattern.getPart(partIndex + 1).getValue();
while (argNumber >= list.size()) {
@ -824,7 +824,7 @@ public class MessageFormat extends UFormat {
* @stable ICU 3.0
*/
public Format[] getFormats() {
ArrayList<Format> list = new ArrayList<Format>();
ArrayList<Format> list = new ArrayList<>();
for (int partIndex = 0; (partIndex = nextTopLevelArgStart(partIndex)) >= 0;) {
list.add(cachedFormatters == null ? null : cachedFormatters.get(partIndex));
}
@ -838,7 +838,7 @@ public class MessageFormat extends UFormat {
* @stable ICU 4.8
*/
public Set<String> getArgumentNames() {
Set<String> result = new HashSet<String>();
Set<String> result = new HashSet<>();
for (int partIndex = 0; (partIndex = nextTopLevelArgStart(partIndex)) >= 0;) {
result.add(getArgName(partIndex + 1));
}
@ -1185,7 +1185,7 @@ public class MessageFormat extends UFormat {
* @stable ICU 3.8
*/
public Map<String, Object> parseToMap(String source, ParsePosition pos) {
Map<String, Object> result = new HashMap<String, Object>();
Map<String, Object> result = new HashMap<>();
int backupStartPos = pos.getIndex();
parse(0, source, pos, null, result);
if (pos.getIndex() == backupStartPos) {
@ -1372,7 +1372,7 @@ public class MessageFormat extends UFormat {
*/
public Map<String, Object> parseToMap(String source) throws ParseException {
ParsePosition pos = new ParsePosition(0);
Map<String, Object> result = new HashMap<String, Object>();
Map<String, Object> result = new HashMap<>();
parse(0, source, pos, null, result);
if (pos.getIndex() == 0) // unchanged, returned object is null
throw new ParseException("MessageFormat parse error!",
@ -1426,7 +1426,7 @@ public class MessageFormat extends UFormat {
MessageFormat other = (MessageFormat) super.clone();
if (customFormatArgStarts != null) {
other.customFormatArgStarts = new HashSet<Integer>();
other.customFormatArgStarts = new HashSet<>();
for (Integer key : customFormatArgStarts) {
other.customFormatArgStarts.add(key);
}
@ -1435,7 +1435,7 @@ public class MessageFormat extends UFormat {
}
if (cachedFormatters != null) {
other.cachedFormatters = new HashMap<Integer, Format>();
other.cachedFormatters = new HashMap<>();
Iterator<Map.Entry<Integer, Format>> it = cachedFormatters.entrySet().iterator();
while (it.hasNext()){
Map.Entry<Integer, Format> entry = it.next();
@ -1467,10 +1467,10 @@ public class MessageFormat extends UFormat {
if (obj == null || getClass() != obj.getClass())
return false;
MessageFormat other = (MessageFormat) obj;
return Utility.objectEquals(ulocale, other.ulocale)
&& Utility.objectEquals(msgPattern, other.msgPattern)
&& Utility.objectEquals(cachedFormatters, other.cachedFormatters)
&& Utility.objectEquals(customFormatArgStarts, other.customFormatArgStarts);
return Objects.equals(ulocale, other.ulocale)
&& Objects.equals(msgPattern, other.msgPattern)
&& Objects.equals(cachedFormatters, other.cachedFormatters)
&& Objects.equals(customFormatArgStarts, other.customFormatArgStarts);
// Note: It might suffice to only compare custom formatters
// rather than all formatters.
}
@ -2439,7 +2439,7 @@ public class MessageFormat extends UFormat {
*/
private void setArgStartFormat(int argStart, Format formatter) {
if (cachedFormatters == null) {
cachedFormatters = new HashMap<Integer, Format>();
cachedFormatters = new HashMap<>();
}
cachedFormatters.put(argStart, formatter);
}
@ -2451,7 +2451,7 @@ public class MessageFormat extends UFormat {
private void setCustomArgStartFormat(int argStart, Format formatter) {
setArgStartFormat(argStart, formatter);
if (customFormatArgStarts == null) {
customFormatArgStarts = new HashSet<Integer>();
customFormatArgStarts = new HashSet<>();
}
customFormatArgStarts.add(argStart);
}
@ -2578,7 +2578,7 @@ public class MessageFormat extends UFormat {
}
public void useAttributes() {
attributes = new ArrayList<AttributeAndPosition>();
attributes = new ArrayList<>();
}
public void append(CharSequence s) {

View file

@ -11,9 +11,9 @@ package com.ibm.icu.text;
import java.text.FieldPosition;
import java.text.ParsePosition;
import java.util.List;
import java.util.Objects;
import com.ibm.icu.impl.PatternProps;
import com.ibm.icu.impl.Utility;
/**
* A class representing a single rule in a RuleBasedNumberFormat. A rule
@ -610,6 +610,7 @@ final class NFRule {
* @param that The rule to compare this one against
* @return True if the two rules are functionally equivalent
*/
@Override
public boolean equals(Object that) {
if (that instanceof NFRule) {
NFRule that2 = (NFRule)that;
@ -618,12 +619,13 @@ final class NFRule {
&& radix == that2.radix
&& exponent == that2.exponent
&& ruleText.equals(that2.ruleText)
&& Utility.objectEquals(sub1, that2.sub1)
&& Utility.objectEquals(sub2, that2.sub2);
&& Objects.equals(sub1, that2.sub1)
&& Objects.equals(sub2, that2.sub2);
}
return false;
}
@Override
public int hashCode() {
assert false : "hashCode not designed";
return 42;
@ -635,6 +637,7 @@ final class NFRule {
* was created with, but it will produce the same result.
* @return A textual description of the rule
*/
@Override
public String toString() {
StringBuilder result = new StringBuilder();

View file

@ -12,9 +12,9 @@ import java.text.ParsePosition;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
import com.ibm.icu.impl.PatternProps;
import com.ibm.icu.impl.Utility;
/**
* A collection of rules used by a RuleBasedNumberFormat to format and
@ -160,7 +160,7 @@ final class NFRuleSet {
public void parseRules(String description) {
// (the number of elements in the description list isn't necessarily
// the number of rules-- some descriptions may expend into two rules)
List<NFRule> tempRules = new ArrayList<NFRule>();
List<NFRule> tempRules = new ArrayList<>();
// we keep track of the rule before the one we're currently working
// on solely to support >>> substitutions
@ -264,7 +264,7 @@ final class NFRuleSet {
private void setBestFractionRule(int originalIndex, NFRule newRule, boolean rememberRule) {
if (rememberRule) {
if (fractionRules == null) {
fractionRules = new LinkedList<NFRule>();
fractionRules = new LinkedList<>();
}
fractionRules.add(newRule);
}
@ -303,6 +303,7 @@ final class NFRuleSet {
* @param that The other rule set
* @return true if the two rule sets are functionally equivalent.
*/
@Override
public boolean equals(Object that) {
// if different classes, they're not equal
if (!(that instanceof NFRuleSet)) {
@ -320,7 +321,7 @@ final class NFRuleSet {
// ...then compare the non-numerical rule lists...
for (int i = 0; i < nonNumericalRules.length; i++) {
if (!Utility.objectEquals(nonNumericalRules[i], that2.nonNumericalRules[i])) {
if (!Objects.equals(nonNumericalRules[i], that2.nonNumericalRules[i])) {
return false;
}
}
@ -337,6 +338,7 @@ final class NFRuleSet {
}
}
@Override
public int hashCode() {
assert false : "hashCode not designed";
return 42;
@ -349,6 +351,7 @@ final class NFRuleSet {
* necessarily be the same description that the rule set was
* constructed with, but it will produce the same results.
*/
@Override
public String toString() {
StringBuilder result = new StringBuilder();

View file

@ -15,8 +15,8 @@ import java.text.FieldPosition;
import java.text.ParsePosition;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import com.ibm.icu.impl.Utility;
import com.ibm.icu.number.FormattedNumber;
import com.ibm.icu.number.LocalizedNumberFormatter;
import com.ibm.icu.text.PluralRules.FixedDecimal;
@ -834,10 +834,10 @@ public class PluralFormat extends UFormat {
}
PluralFormat pf = (PluralFormat)rhs;
return
Utility.objectEquals(ulocale, pf.ulocale) &&
Utility.objectEquals(pluralRules, pf.pluralRules) &&
Utility.objectEquals(msgPattern, pf.msgPattern) &&
Utility.objectEquals(numberFormat, pf.numberFormat);
Objects.equals(ulocale, pf.ulocale) &&
Objects.equals(pluralRules, pf.pluralRules) &&
Objects.equals(msgPattern, pf.msgPattern) &&
Objects.equals(numberFormat, pf.numberFormat);
}
/**

View file

@ -15,6 +15,7 @@ import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -24,7 +25,6 @@ import com.ibm.icu.impl.ICUResourceBundle;
import com.ibm.icu.impl.Relation;
import com.ibm.icu.impl.Row;
import com.ibm.icu.impl.Row.R3;
import com.ibm.icu.impl.Utility;
import com.ibm.icu.impl.locale.XLocaleDistance.DistanceOption;
import com.ibm.icu.impl.locale.XLocaleMatcher;
import com.ibm.icu.impl.locale.XLocaleMatcher.Builder;
@ -338,7 +338,7 @@ public class LocaleMatcher {
private void addFiltered(String desired, R3<ULocale, ULocale, Double> localeToMaxAndWeight) {
Set<R3<ULocale, ULocale, Double>> map = desiredLanguageToPossibleLocalesToMaxLocaleToData.get(desired);
if (map == null) {
desiredLanguageToPossibleLocalesToMaxLocaleToData.put(desired, map = new LinkedHashSet<R3<ULocale, ULocale, Double>>());
desiredLanguageToPossibleLocalesToMaxLocaleToData.put(desired, map = new LinkedHashSet<>());
}
map.add(localeToMaxAndWeight);
if (DEBUG) {
@ -346,9 +346,9 @@ public class LocaleMatcher {
}
}
Set<Row.R3<ULocale, ULocale, Double>> localeToMaxLocaleAndWeight = new LinkedHashSet<Row.R3<ULocale, ULocale, Double>>();
Set<Row.R3<ULocale, ULocale, Double>> localeToMaxLocaleAndWeight = new LinkedHashSet<>();
Map<String,Set<Row.R3<ULocale, ULocale, Double>>> desiredLanguageToPossibleLocalesToMaxLocaleToData
= new LinkedHashMap<String,Set<Row.R3<ULocale, ULocale, Double>>>();
= new LinkedHashMap<>();
// =============== Special Mapping Information ==============
@ -472,10 +472,10 @@ public class LocaleMatcher {
return false;
}
LocalePatternMatcher other = (LocalePatternMatcher) obj;
return Utility.objectEquals(level, other.level)
&& Utility.objectEquals(lang, other.lang)
&& Utility.objectEquals(script, other.script)
&& Utility.objectEquals(region, other.region);
return Objects.equals(level, other.level)
&& Objects.equals(lang, other.lang)
&& Objects.equals(script, other.script)
&& Objects.equals(region, other.region);
}
/* (non-Javadoc)
@ -509,7 +509,7 @@ public class LocaleMatcher {
@SuppressWarnings("unused")
private static final double maxUnequal_changeEqual = 0.75;
LinkedHashSet<Row.R3<LocalePatternMatcher,LocalePatternMatcher,Double>> scores = new LinkedHashSet<R3<LocalePatternMatcher, LocalePatternMatcher, Double>>();
LinkedHashSet<Row.R3<LocalePatternMatcher,LocalePatternMatcher,Double>> scores = new LinkedHashSet<>();
final Level level;
public ScoreData(Level level) {
@ -810,7 +810,7 @@ public class LocaleMatcher {
private static final LanguageMatcherData defaultWritten;
private static HashMap<String,String> canonicalMap = new HashMap<String, String>();
private static HashMap<String,String> canonicalMap = new HashMap<>();
static {

View file

@ -13,12 +13,12 @@ import java.text.AttributedCharacterIterator;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
import java.util.Objects;
import com.ibm.icu.impl.DateNumberFormat;
import com.ibm.icu.impl.TZDBTimeZoneNames;
import com.ibm.icu.impl.TimeZoneGenericNames;
import com.ibm.icu.impl.TimeZoneGenericNames.GenericNameType;
import com.ibm.icu.impl.Utility;
import com.ibm.icu.text.ChineseDateFormat;
import com.ibm.icu.text.ChineseDateFormatSymbols;
import com.ibm.icu.text.CompactDecimalFormat;
@ -2378,7 +2378,7 @@ public class FormatHandler
for (long date : DATES) {
String nameA = tzgna.getDisplayName(tz, nt, date);
String nameB = tzgnb.getDisplayName(tz, nt, date);
if (!Utility.objectEquals(nameA, nameB)) {
if (!Objects.equals(nameA, nameB)) {
return false;
}
}
@ -2424,7 +2424,7 @@ public class FormatHandler
for (long date : DATES) {
String nameA = tzdbna.getDisplayName(tzid, nt, date);
String nameB = tzdbnb.getDisplayName(tzid, nt, date);
if (!Utility.objectEquals(nameA, nameB)) {
if (!Objects.equals(nameA, nameB)) {
return false;
}
}

View file

@ -27,6 +27,7 @@ import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import com.ibm.icu.dev.test.format.MeasureUnitTest;
import com.ibm.icu.dev.test.format.PluralRulesTest;
@ -36,7 +37,6 @@ import com.ibm.icu.impl.JavaTimeZone;
import com.ibm.icu.impl.OlsonTimeZone;
import com.ibm.icu.impl.TimeZoneAdapter;
import com.ibm.icu.impl.URLHandler;
import com.ibm.icu.impl.Utility;
import com.ibm.icu.math.BigDecimal;
import com.ibm.icu.math.MathContext;
import com.ibm.icu.util.AnnualTimeZoneRule;
@ -708,7 +708,7 @@ public class SerializableTestUtility {
return a == null ? b == null :
b == null ? false :
a.getClass().equals(b.getClass()) &&
Utility.objectEquals(a.getMessage(), b.getMessage()) &&
Objects.equals(a.getMessage(), b.getMessage()) &&
sameThrowable(a.getCause(), b.getCause());
}
}

View file

@ -7,11 +7,11 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import com.ibm.icu.dev.test.AbstractTestLog;
import com.ibm.icu.dev.test.TestFmwk;
import com.ibm.icu.dev.util.CollectionUtilities;
import com.ibm.icu.impl.Utility;
import com.ibm.icu.impl.locale.XCldrStub.FileUtilities;
import com.ibm.icu.impl.locale.XCldrStub.Splitter;
import com.ibm.icu.util.ICUUncheckedIOException;
@ -26,8 +26,8 @@ abstract public class DataDrivenTestHelper {
protected TestFmwk framework = null;
protected int minArgumentCount = 3;
protected int maxArgumentCount = 4;
private List<List<String>> lines = new ArrayList<List<String>>();
private List<String> comments = new ArrayList<String>();
private List<List<String>> lines = new ArrayList<>();
private List<String> comments = new ArrayList<>();
public DataDrivenTestHelper setFramework(TestFmwk testFramework) {
this.framework = testFramework;
@ -165,7 +165,7 @@ abstract public class DataDrivenTestHelper {
}
protected boolean assertEquals(String message, Object expected, Object actual) {
return TestFmwk.handleAssert(Utility.equals(expected, actual), message, stringFor(expected), stringFor(actual), null, false);
return TestFmwk.handleAssert(Objects.equals(expected, actual), message, stringFor(expected), stringFor(actual), null, false);
}
private final String stringFor(Object obj) {

View file

@ -21,11 +21,11 @@ import java.text.ParsePosition;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Objects;
import java.util.Set;
import com.ibm.icu.impl.ICUConfig;
import com.ibm.icu.impl.PatternProps;
import com.ibm.icu.impl.Utility;
import com.ibm.icu.lang.UCharacter;
import com.ibm.icu.math.BigDecimal;
import com.ibm.icu.math.MathContext;
@ -2207,7 +2207,7 @@ public class DecimalFormat_ICU58 extends NumberFormat {
if (currencyPluralInfo == null) {
currencyPluralInfo = new CurrencyPluralInfo(symbols.getULocale());
}
affixPatternsForCurrency = new HashSet<AffixForCurrency>();
affixPatternsForCurrency = new HashSet<>();
// save the current pattern, since it will be changed by
// applyPatternWithoutExpandAffix
@ -2225,7 +2225,7 @@ public class DecimalFormat_ICU58 extends NumberFormat {
// add plural pattern
Iterator<String> iter = currencyPluralInfo.pluralPatternIterator();
Set<String> currencyUnitPatternSet = new HashSet<String>();
Set<String> currencyUnitPatternSet = new HashSet<>();
while (iter.hasNext()) {
String pluralCount = iter.next();
String currencyPattern = currencyPluralInfo.getCurrencyPluralPattern(pluralCount);
@ -3989,7 +3989,7 @@ public class DecimalFormat_ICU58 extends NumberFormat {
if (currencyPluralInfo != null) {
other.currencyPluralInfo = (CurrencyPluralInfo) currencyPluralInfo.clone();
}
other.attributes = new ArrayList<FieldPosition>(); // #9240
other.attributes = new ArrayList<>(); // #9240
other.currencyUsage = currencyUsage;
// TODO: We need to figure out whether we share a single copy of DigitList by
@ -4032,7 +4032,7 @@ public class DecimalFormat_ICU58 extends NumberFormat {
&& (!useSignificantDigits || minSignificantDigits == other.minSignificantDigits
&& maxSignificantDigits == other.maxSignificantDigits)
&& symbols.equals(other.symbols)
&& Utility.objectEquals(currencyPluralInfo, other.currencyPluralInfo)
&& Objects.equals(currencyPluralInfo, other.currencyPluralInfo)
&& currencyUsage.equals(other.currencyUsage);
}
@ -6059,7 +6059,7 @@ public class DecimalFormat_ICU58 extends NumberFormat {
// Proclaim JDK 1.1 serial compatibility.
private static final long serialVersionUID = 864413376551465018L;
private ArrayList<FieldPosition> attributes = new ArrayList<FieldPosition>();
private ArrayList<FieldPosition> attributes = new ArrayList<>();
// The following are used in currency format