Java Code Examples for java.util.Locale#clone()
The following examples show how to use
java.util.Locale#clone() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LocaleTest.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
public void TestSimpleObjectStuff() { Locale test1 = new Locale("aa", "AA"); Locale test2 = new Locale("aa", "AA"); Locale test3 = (Locale)test1.clone(); Locale test4 = new Locale("zz", "ZZ"); if (test1 == test2 || test1 == test3 || test1 == test4 || test2 == test3) errln("Some of the test variables point to the same locale!"); if (test3 == null) errln("clone() failed to produce a valid object!"); if (!test1.equals(test2) || !test1.equals(test3) || !test2.equals(test3)) errln("clone() or equals() failed: objects that should compare equal don't"); if (test1.equals(test4) || test2.equals(test4) || test3.equals(test4)) errln("equals() failed: objects that shouldn't compare equal do"); int hash1 = test1.hashCode(); int hash2 = test2.hashCode(); int hash3 = test3.hashCode(); if (hash1 != hash2 || hash1 != hash3 || hash2 != hash3) errln("hashCode() failed: objects that should have the same hash code don't"); }
Example 2
Source File: LocaleTest.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
public void TestSimpleObjectStuff() { Locale test1 = new Locale("aa", "AA"); Locale test2 = new Locale("aa", "AA"); Locale test3 = (Locale)test1.clone(); Locale test4 = new Locale("zz", "ZZ"); if (test1 == test2 || test1 == test3 || test1 == test4 || test2 == test3) errln("Some of the test variables point to the same locale!"); if (test3 == null) errln("clone() failed to produce a valid object!"); if (!test1.equals(test2) || !test1.equals(test3) || !test2.equals(test3)) errln("clone() or equals() failed: objects that should compare equal don't"); if (test1.equals(test4) || test2.equals(test4) || test3.equals(test4)) errln("equals() failed: objects that shouldn't compare equal do"); int hash1 = test1.hashCode(); int hash2 = test2.hashCode(); int hash3 = test3.hashCode(); if (hash1 != hash2 || hash1 != hash3 || hash2 != hash3) errln("hashCode() failed: objects that should have the same hash code don't"); }
Example 3
Source File: LocaleTest.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
public void TestSimpleObjectStuff() { Locale test1 = new Locale("aa", "AA"); Locale test2 = new Locale("aa", "AA"); Locale test3 = (Locale)test1.clone(); Locale test4 = new Locale("zz", "ZZ"); if (test1 == test2 || test1 == test3 || test1 == test4 || test2 == test3) errln("Some of the test variables point to the same locale!"); if (test3 == null) errln("clone() failed to produce a valid object!"); if (!test1.equals(test2) || !test1.equals(test3) || !test2.equals(test3)) errln("clone() or equals() failed: objects that should compare equal don't"); if (test1.equals(test4) || test2.equals(test4) || test3.equals(test4)) errln("equals() failed: objects that shouldn't compare equal do"); int hash1 = test1.hashCode(); int hash2 = test2.hashCode(); int hash3 = test3.hashCode(); if (hash1 != hash2 || hash1 != hash3 || hash2 != hash3) errln("hashCode() failed: objects that should have the same hash code don't"); }
Example 4
Source File: LocaleTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public void TestSimpleObjectStuff() { Locale test1 = new Locale("aa", "AA"); Locale test2 = new Locale("aa", "AA"); Locale test3 = (Locale)test1.clone(); Locale test4 = new Locale("zz", "ZZ"); if (test1 == test2 || test1 == test3 || test1 == test4 || test2 == test3) errln("Some of the test variables point to the same locale!"); if (test3 == null) errln("clone() failed to produce a valid object!"); if (!test1.equals(test2) || !test1.equals(test3) || !test2.equals(test3)) errln("clone() or equals() failed: objects that should compare equal don't"); if (test1.equals(test4) || test2.equals(test4) || test3.equals(test4)) errln("equals() failed: objects that shouldn't compare equal do"); int hash1 = test1.hashCode(); int hash2 = test2.hashCode(); int hash3 = test3.hashCode(); if (hash1 != hash2 || hash1 != hash3 || hash2 != hash3) errln("hashCode() failed: objects that should have the same hash code don't"); }
Example 5
Source File: LocaleTest.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
public void TestSimpleObjectStuff() { Locale test1 = new Locale("aa", "AA"); Locale test2 = new Locale("aa", "AA"); Locale test3 = (Locale)test1.clone(); Locale test4 = new Locale("zz", "ZZ"); if (test1 == test2 || test1 == test3 || test1 == test4 || test2 == test3) errln("Some of the test variables point to the same locale!"); if (test3 == null) errln("clone() failed to produce a valid object!"); if (!test1.equals(test2) || !test1.equals(test3) || !test2.equals(test3)) errln("clone() or equals() failed: objects that should compare equal don't"); if (test1.equals(test4) || test2.equals(test4) || test3.equals(test4)) errln("equals() failed: objects that shouldn't compare equal do"); int hash1 = test1.hashCode(); int hash2 = test2.hashCode(); int hash3 = test3.hashCode(); if (hash1 != hash2 || hash1 != hash3 || hash2 != hash3) errln("hashCode() failed: objects that should have the same hash code don't"); }
Example 6
Source File: LocaleTest.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
public void TestSimpleObjectStuff() { Locale test1 = new Locale("aa", "AA"); Locale test2 = new Locale("aa", "AA"); Locale test3 = (Locale)test1.clone(); Locale test4 = new Locale("zz", "ZZ"); if (test1 == test2 || test1 == test3 || test1 == test4 || test2 == test3) errln("Some of the test variables point to the same locale!"); if (test3 == null) errln("clone() failed to produce a valid object!"); if (!test1.equals(test2) || !test1.equals(test3) || !test2.equals(test3)) errln("clone() or equals() failed: objects that should compare equal don't"); if (test1.equals(test4) || test2.equals(test4) || test3.equals(test4)) errln("equals() failed: objects that shouldn't compare equal do"); int hash1 = test1.hashCode(); int hash2 = test2.hashCode(); int hash3 = test3.hashCode(); if (hash1 != hash2 || hash1 != hash3 || hash2 != hash3) errln("hashCode() failed: objects that should have the same hash code don't"); }
Example 7
Source File: LocaleTest.java From hottub with GNU General Public License v2.0 | 6 votes |
public void TestSimpleObjectStuff() { Locale test1 = new Locale("aa", "AA"); Locale test2 = new Locale("aa", "AA"); Locale test3 = (Locale)test1.clone(); Locale test4 = new Locale("zz", "ZZ"); if (test1 == test2 || test1 == test3 || test1 == test4 || test2 == test3) errln("Some of the test variables point to the same locale!"); if (test3 == null) errln("clone() failed to produce a valid object!"); if (!test1.equals(test2) || !test1.equals(test3) || !test2.equals(test3)) errln("clone() or equals() failed: objects that should compare equal don't"); if (test1.equals(test4) || test2.equals(test4) || test3.equals(test4)) errln("equals() failed: objects that shouldn't compare equal do"); int hash1 = test1.hashCode(); int hash2 = test2.hashCode(); int hash3 = test3.hashCode(); if (hash1 != hash2 || hash1 != hash3 || hash2 != hash3) errln("hashCode() failed: objects that should have the same hash code don't"); }
Example 8
Source File: LocaleTest.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
public void TestSimpleObjectStuff() { Locale test1 = new Locale("aa", "AA"); Locale test2 = new Locale("aa", "AA"); Locale test3 = (Locale)test1.clone(); Locale test4 = new Locale("zz", "ZZ"); if (test1 == test2 || test1 == test3 || test1 == test4 || test2 == test3) errln("Some of the test variables point to the same locale!"); if (test3 == null) errln("clone() failed to produce a valid object!"); if (!test1.equals(test2) || !test1.equals(test3) || !test2.equals(test3)) errln("clone() or equals() failed: objects that should compare equal don't"); if (test1.equals(test4) || test2.equals(test4) || test3.equals(test4)) errln("equals() failed: objects that shouldn't compare equal do"); int hash1 = test1.hashCode(); int hash2 = test2.hashCode(); int hash3 = test3.hashCode(); if (hash1 != hash2 || hash1 != hash3 || hash2 != hash3) errln("hashCode() failed: objects that should have the same hash code don't"); }
Example 9
Source File: LocaleTest.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
public void TestSimpleObjectStuff() { Locale test1 = new Locale("aa", "AA"); Locale test2 = new Locale("aa", "AA"); Locale test3 = (Locale)test1.clone(); Locale test4 = new Locale("zz", "ZZ"); if (test1 == test2 || test1 == test3 || test1 == test4 || test2 == test3) errln("Some of the test variables point to the same locale!"); if (test3 == null) errln("clone() failed to produce a valid object!"); if (!test1.equals(test2) || !test1.equals(test3) || !test2.equals(test3)) errln("clone() or equals() failed: objects that should compare equal don't"); if (test1.equals(test4) || test2.equals(test4) || test3.equals(test4)) errln("equals() failed: objects that shouldn't compare equal do"); int hash1 = test1.hashCode(); int hash2 = test2.hashCode(); int hash3 = test3.hashCode(); if (hash1 != hash2 || hash1 != hash3 || hash2 != hash3) errln("hashCode() failed: objects that should have the same hash code don't"); }
Example 10
Source File: LocaleTest.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
public void TestSimpleObjectStuff() { Locale test1 = new Locale("aa", "AA"); Locale test2 = new Locale("aa", "AA"); Locale test3 = (Locale)test1.clone(); Locale test4 = new Locale("zz", "ZZ"); if (test1 == test2 || test1 == test3 || test1 == test4 || test2 == test3) errln("Some of the test variables point to the same locale!"); if (test3 == null) errln("clone() failed to produce a valid object!"); if (!test1.equals(test2) || !test1.equals(test3) || !test2.equals(test3)) errln("clone() or equals() failed: objects that should compare equal don't"); if (test1.equals(test4) || test2.equals(test4) || test3.equals(test4)) errln("equals() failed: objects that shouldn't compare equal do"); int hash1 = test1.hashCode(); int hash2 = test2.hashCode(); int hash3 = test3.hashCode(); if (hash1 != hash2 || hash1 != hash3 || hash2 != hash3) errln("hashCode() failed: objects that should have the same hash code don't"); }
Example 11
Source File: LocaleTest.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
public void TestSimpleObjectStuff() { Locale test1 = new Locale("aa", "AA"); Locale test2 = new Locale("aa", "AA"); Locale test3 = (Locale)test1.clone(); Locale test4 = new Locale("zz", "ZZ"); if (test1 == test2 || test1 == test3 || test1 == test4 || test2 == test3) errln("Some of the test variables point to the same locale!"); if (test3 == null) errln("clone() failed to produce a valid object!"); if (!test1.equals(test2) || !test1.equals(test3) || !test2.equals(test3)) errln("clone() or equals() failed: objects that should compare equal don't"); if (test1.equals(test4) || test2.equals(test4) || test3.equals(test4)) errln("equals() failed: objects that shouldn't compare equal do"); int hash1 = test1.hashCode(); int hash2 = test2.hashCode(); int hash3 = test3.hashCode(); if (hash1 != hash2 || hash1 != hash3 || hash2 != hash3) errln("hashCode() failed: objects that should have the same hash code don't"); }
Example 12
Source File: LocaleTest.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
public void TestSimpleObjectStuff() { Locale test1 = new Locale("aa", "AA"); Locale test2 = new Locale("aa", "AA"); Locale test3 = (Locale)test1.clone(); Locale test4 = new Locale("zz", "ZZ"); if (test1 == test2 || test1 == test3 || test1 == test4 || test2 == test3) errln("Some of the test variables point to the same locale!"); if (test3 == null) errln("clone() failed to produce a valid object!"); if (!test1.equals(test2) || !test1.equals(test3) || !test2.equals(test3)) errln("clone() or equals() failed: objects that should compare equal don't"); if (test1.equals(test4) || test2.equals(test4) || test3.equals(test4)) errln("equals() failed: objects that shouldn't compare equal do"); int hash1 = test1.hashCode(); int hash2 = test2.hashCode(); int hash3 = test3.hashCode(); if (hash1 != hash2 || hash1 != hash3 || hash2 != hash3) errln("hashCode() failed: objects that should have the same hash code don't"); }
Example 13
Source File: LocaleList.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * Creates a new {@link LocaleList}. * * <p>For empty lists of {@link Locale} items it is better to use {@link #getEmptyLocaleList()}, * which returns a pre-constructed empty list.</p> * * @throws NullPointerException if any of the input locales is <code>null</code>. * @throws IllegalArgumentException if any of the input locales repeat. */ public LocaleList(@NonNull Locale... list) { if (list.length == 0) { mList = sEmptyList; mStringRepresentation = ""; } else { final Locale[] localeList = new Locale[list.length]; final HashSet<Locale> seenLocales = new HashSet<Locale>(); final StringBuilder sb = new StringBuilder(); for (int i = 0; i < list.length; i++) { final Locale l = list[i]; if (l == null) { throw new NullPointerException("list[" + i + "] is null"); } else if (seenLocales.contains(l)) { throw new IllegalArgumentException("list[" + i + "] is a repetition"); } else { final Locale localeClone = (Locale) l.clone(); localeList[i] = localeClone; sb.append(localeClone.toLanguageTag()); if (i < list.length - 1) { sb.append(','); } seenLocales.add(localeClone); } } mList = localeList; mStringRepresentation = sb.toString(); } }
Example 14
Source File: LocaleTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public void TestSimpleObjectStuff() { Locale test1 = new Locale("aa", "AA"); Locale test2 = new Locale("aa", "AA"); Locale test3 = (Locale) test1.clone(); Locale test4 = new Locale("zz", "ZZ"); if (test1 == test2 || test1 == test3 || test1 == test4 || test2 == test3) { errln("Some of the test variables point to the same locale!"); } if (test3 == null) { errln("clone() failed to produce a valid object!"); } if (!test1.equals(test2) || !test1.equals(test3) || !test2.equals(test3)) { errln("clone() or equals() failed: objects that should compare equal don't"); } if (test1.equals(test4) || test2.equals(test4) || test3.equals(test4)) { errln("equals() failed: objects that shouldn't compare equal do"); } int hash1 = test1.hashCode(); int hash2 = test2.hashCode(); int hash3 = test3.hashCode(); if (hash1 != hash2 || hash1 != hash3 || hash2 != hash3) { errln("hashCode() failed: objects that should have the same hash code don't"); } }
Example 15
Source File: LocaleList.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
/** * Constructs a locale list, with the topLocale moved to the front if it already is * in otherLocales, or added to the front if it isn't. * * {@hide} */ public LocaleList(@NonNull Locale topLocale, LocaleList otherLocales) { if (topLocale == null) { throw new NullPointerException("topLocale is null"); } final int inputLength = (otherLocales == null) ? 0 : otherLocales.mList.length; int topLocaleIndex = -1; for (int i = 0; i < inputLength; i++) { if (topLocale.equals(otherLocales.mList[i])) { topLocaleIndex = i; break; } } final int outputLength = inputLength + (topLocaleIndex == -1 ? 1 : 0); final Locale[] localeList = new Locale[outputLength]; localeList[0] = (Locale) topLocale.clone(); if (topLocaleIndex == -1) { // topLocale was not in otherLocales for (int i = 0; i < inputLength; i++) { localeList[i + 1] = (Locale) otherLocales.mList[i].clone(); } } else { for (int i = 0; i < topLocaleIndex; i++) { localeList[i + 1] = (Locale) otherLocales.mList[i].clone(); } for (int i = topLocaleIndex + 1; i < inputLength; i++) { localeList[i] = (Locale) otherLocales.mList[i].clone(); } } final StringBuilder sb = new StringBuilder(); for (int i = 0; i < outputLength; i++) { sb.append(localeList[i].toLanguageTag()); if (i < outputLength - 1) { sb.append(','); } } mList = localeList; mStringRepresentation = sb.toString(); }