java.util.Locale#clone ( )源码实例Demo

下面列出了java.util.Locale#clone ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: dragonwell8_jdk   文件: LocaleTest.java
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");
}
 
源代码2 项目: TencentKona-8   文件: LocaleTest.java
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");
}
 
源代码3 项目: jdk8u60   文件: LocaleTest.java
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");
}
 
源代码4 项目: openjdk-jdk8u   文件: LocaleTest.java
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");
}
 
源代码5 项目: openjdk-jdk8u-backup   文件: LocaleTest.java
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");
}
 
源代码6 项目: jdk8u-jdk   文件: LocaleTest.java
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");
}
 
源代码7 项目: hottub   文件: LocaleTest.java
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");
}
 
源代码8 项目: openjdk-8-source   文件: LocaleTest.java
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");
}
 
源代码9 项目: openjdk-8   文件: LocaleTest.java
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");
}
 
源代码10 项目: jdk8u_jdk   文件: LocaleTest.java
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");
}
 
源代码11 项目: jdk8u-jdk   文件: LocaleTest.java
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");
}
 
源代码12 项目: jdk8u-dev-jdk   文件: LocaleTest.java
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");
}
 
源代码13 项目: android_9.0.0_r45   文件: LocaleList.java
/**
 * 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();
    }
}
 
源代码14 项目: openjdk-jdk9   文件: LocaleTest.java
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");
    }
}
 
源代码15 项目: android_9.0.0_r45   文件: LocaleList.java
/**
 * 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();
}