Java Code Examples for java.util.Locale#hashCode()

The following examples show how to use java.util.Locale#hashCode() . 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 vote down vote up
/**
 * @bug 4110613
 */
public void TestSerialization() throws ClassNotFoundException, OptionalDataException,
                IOException, StreamCorruptedException
{
    ObjectOutputStream ostream;
    ByteArrayOutputStream obstream;
    byte[] bytes = null;

    obstream = new ByteArrayOutputStream();
    ostream = new ObjectOutputStream(obstream);

    Locale test1 = new Locale("zh", "TW", "");
    int dummy = test1.hashCode();   // fill in the cached hash-code value
    ostream.writeObject(test1);

    bytes = obstream.toByteArray();

    ObjectInputStream istream = new ObjectInputStream(new ByteArrayInputStream(bytes));

    Locale test2 = (Locale)(istream.readObject());

    if (!test1.equals(test2) || test1.hashCode() != test2.hashCode())
        errln("Locale failed to deserialize correctly.");
}
 
Example 2
Source File: LocaleTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
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 jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @bug 4110613
 */
public void TestSerialization() throws ClassNotFoundException, OptionalDataException,
                IOException, StreamCorruptedException
{
    ObjectOutputStream ostream;
    ByteArrayOutputStream obstream;
    byte[] bytes = null;

    obstream = new ByteArrayOutputStream();
    ostream = new ObjectOutputStream(obstream);

    Locale test1 = new Locale("zh", "TW", "");
    int dummy = test1.hashCode();   // fill in the cached hash-code value
    ostream.writeObject(test1);

    bytes = obstream.toByteArray();

    ObjectInputStream istream = new ObjectInputStream(new ByteArrayInputStream(bytes));

    Locale test2 = (Locale)(istream.readObject());

    if (!test1.equals(test2) || test1.hashCode() != test2.hashCode())
        errln("Locale failed to deserialize correctly.");
}
 
Example 4
Source File: LocaleTest.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @bug 4110613
 */
public void TestSerialization() throws ClassNotFoundException, OptionalDataException,
                IOException, StreamCorruptedException
{
    ObjectOutputStream ostream;
    ByteArrayOutputStream obstream;
    byte[] bytes = null;

    obstream = new ByteArrayOutputStream();
    ostream = new ObjectOutputStream(obstream);

    Locale test1 = new Locale("zh", "TW", "");
    int dummy = test1.hashCode();   // fill in the cached hash-code value
    ostream.writeObject(test1);

    bytes = obstream.toByteArray();

    ObjectInputStream istream = new ObjectInputStream(new ByteArrayInputStream(bytes));

    Locale test2 = (Locale)(istream.readObject());

    if (!test1.equals(test2) || test1.hashCode() != test2.hashCode())
        errln("Locale failed to deserialize correctly.");
}
 
Example 5
Source File: LocaleTest.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
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 vote down vote up
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 vote down vote up
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 jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
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 jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
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 openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @bug 4110613
 */
public void TestSerialization() throws ClassNotFoundException, OptionalDataException,
                IOException, StreamCorruptedException
{
    ObjectOutputStream ostream;
    ByteArrayOutputStream obstream;
    byte[] bytes = null;

    obstream = new ByteArrayOutputStream();
    ostream = new ObjectOutputStream(obstream);

    Locale test1 = new Locale("zh", "TW", "");
    int dummy = test1.hashCode();   // fill in the cached hash-code value
    ostream.writeObject(test1);

    bytes = obstream.toByteArray();

    ObjectInputStream istream = new ObjectInputStream(new ByteArrayInputStream(bytes));

    Locale test2 = (Locale)(istream.readObject());

    if (!test1.equals(test2) || test1.hashCode() != test2.hashCode())
        errln("Locale failed to deserialize correctly.");
}
 
Example 11
Source File: LocaleTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
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-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @bug 4110613
 */
public void TestSerialization() throws ClassNotFoundException, OptionalDataException,
                IOException, StreamCorruptedException
{
    ObjectOutputStream ostream;
    ByteArrayOutputStream obstream;
    byte[] bytes = null;

    obstream = new ByteArrayOutputStream();
    ostream = new ObjectOutputStream(obstream);

    Locale test1 = new Locale("zh", "TW", "");
    int dummy = test1.hashCode();   // fill in the cached hash-code value
    ostream.writeObject(test1);

    bytes = obstream.toByteArray();

    ObjectInputStream istream = new ObjectInputStream(new ByteArrayInputStream(bytes));

    Locale test2 = (Locale)(istream.readObject());

    if (!test1.equals(test2) || test1.hashCode() != test2.hashCode())
        errln("Locale failed to deserialize correctly.");
}
 
Example 13
Source File: LocaleTest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
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 14
Source File: LocaleTest.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @bug 4110613
 */
public void TestSerialization() throws ClassNotFoundException, OptionalDataException,
                IOException, StreamCorruptedException
{
    ObjectOutputStream ostream;
    ByteArrayOutputStream obstream;
    byte[] bytes = null;

    obstream = new ByteArrayOutputStream();
    ostream = new ObjectOutputStream(obstream);

    Locale test1 = new Locale("zh", "TW", "");
    int dummy = test1.hashCode();   // fill in the cached hash-code value
    ostream.writeObject(test1);

    bytes = obstream.toByteArray();

    ObjectInputStream istream = new ObjectInputStream(new ByteArrayInputStream(bytes));

    Locale test2 = (Locale)(istream.readObject());

    if (!test1.equals(test2) || test1.hashCode() != test2.hashCode())
        errln("Locale failed to deserialize correctly.");
}
 
Example 15
Source File: LocaleTest.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
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 16
Source File: LocaleTest.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @bug 4110613
 */
public void TestSerialization() throws ClassNotFoundException, OptionalDataException,
                IOException, StreamCorruptedException
{
    ObjectOutputStream ostream;
    ByteArrayOutputStream obstream;
    byte[] bytes = null;

    obstream = new ByteArrayOutputStream();
    ostream = new ObjectOutputStream(obstream);

    Locale test1 = new Locale("zh", "TW", "");
    int dummy = test1.hashCode();   // fill in the cached hash-code value
    ostream.writeObject(test1);

    bytes = obstream.toByteArray();

    ObjectInputStream istream = new ObjectInputStream(new ByteArrayInputStream(bytes));

    Locale test2 = (Locale)(istream.readObject());

    if (!test1.equals(test2) || test1.hashCode() != test2.hashCode())
        errln("Locale failed to deserialize correctly.");
}
 
Example 17
Source File: LocaleTest.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
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 18
Source File: LocaleTest.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
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 19
Source File: LocaleTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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 20
Source File: HashCodeTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    Locale[] locales = Locale.getAvailableLocales();
    int min = Integer.MAX_VALUE;
    int max = Integer.MIN_VALUE;
    Map<Integer, Locale> map = new HashMap<>(locales.length);
    int conflicts = 0;

    for (int i = 0; i < locales.length; i++) {
        Locale loc = locales[i];
        int hc = loc.hashCode();
        min = Math.min(hc, min);
        max = Math.max(hc, max);
        Integer key = hc;
        if (map.containsKey(key)) {
            conflicts++;
            System.out.println("conflict: " + map.get(key) + ", " + loc);
        } else {
            map.put(key, loc);
        }
    }
    System.out.println(locales.length + " locales: conflicts=" + conflicts
            + ", min=" + min + ", max=" + max + ", diff=" + (max - min));
    if (conflicts >= (locales.length / 10)) {
        throw new RuntimeException("too many conflicts: " + conflicts
                + " per " + locales.length + " locales");
    }
}