void set(Locale dl, String s, Locale l, ClassLoader cl) { defaultLocale = dl; baseName = s; locale = l; classLoader = cl; hashcode = defaultLocale.hashCode() ^ baseName.hashCode() ^ locale.hashCode() ^ classLoader.hashCode(); }
public static void main(String[] args) { Locale[] locales = Locale.getAvailableLocales(); int min = Integer.MAX_VALUE; int max = Integer.MIN_VALUE; Map 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 = new Integer(hc); if (map.containsKey(key)) { conflicts++; System.out.println("conflict: " + (Locale) 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"); } }
public static DateFormat[] getDateTimeFormats(Locale locale, TimeZone tz, boolean lenient) { String id = "dt-" + locale.hashCode() + "-" + tz.getID() + "-" + lenient; DateFormat[] df = (DateFormat[]) formats.get(id); if (df == null) { df = new DateFormat[] { DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, locale), DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.LONG, locale), DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.MEDIUM, locale), DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.SHORT, locale), DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.FULL, locale), DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale), DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.MEDIUM, locale), DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT, locale), DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.FULL, locale), DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.LONG, locale), DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, locale), DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT, locale), DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.FULL, locale), DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.LONG, locale), DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM, locale), DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, locale) }; for (int i = 0; i < df.length; i++) { df[i].setLenient(lenient); df[i].setTimeZone(tz); } formats.put(id, df); } return df; }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((locale == null) ? 0 : locale.hashCode()); result = prime * result + ((value == null) ? 0 : value.hashCode()); return result; }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + approvedPercent; result = prime * result + coveragePercent; result = prime * result + ((locale == null) ? 0 : locale.hashCode()); result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + ((tag == null) ? 0 : tag.hashCode()); return result; }
/** @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."); }
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"); }
@Override public int hashCode() { int result = cookies != null ? cookies.hashCode() : 0; result = 31 * result + (headers != null ? headers.hashCode() : 0); result = 31 * result + (asyncIOWriter != null ? asyncIOWriter.hashCode() : 0); result = 31 * result + status; result = 31 * result + (statusMessage != null ? statusMessage.hashCode() : 0); result = 31 * result + (charSet != null ? charSet.hashCode() : 0); result = 31 * result + (int) (contentLength ^ (contentLength >>> 32)); result = 31 * result + (contentType != null ? contentType.hashCode() : 0); result = 31 * result + (isCommited ? 1 : 0); result = 31 * result + (locale != null ? locale.hashCode() : 0); result = 31 * result + (headerHandled ? 1 : 0); result = 31 * result + (atmosphereRequest != null ? atmosphereRequest.hashCode() : 0); result = 31 * result + (writeStatusAndHeader != null ? writeStatusAndHeader.hashCode() : 0); result = 31 * result + (delegateToNativeResponse ? 1 : 0); result = 31 * result + (destroyable ? 1 : 0); result = 31 * result + (response != null ? response.hashCode() : 0); return result; }
@Override public int getId() { return locale.hashCode(); }
/** * Returns a hashcode compatible with equals. * * @return a hashcode compatible with equals */ @Override public int hashCode() { return mPattern.hashCode() + 13 * (mTimeZone.hashCode() + 13 * mLocale.hashCode()); }
/** {@inheritDoc} */ @Override public int hashCode() { return (mStyle * 31 + mLocale.hashCode()) * 31 + mTimeZone.hashCode(); }
@Override public int hashCode() { return 37 * locale.hashCode() + axis.hashCode(); }
@Override public int hashCode() { int result = name.hashCode(); result = 31 * result + locale.hashCode(); return result; }
public int hashCode() { return mStyle * 31 + mLocale.hashCode(); }
/** * Return a hashcode compatible with equals. * * @return a hashcode compatible with equals */ @Override public int hashCode() { return pattern.hashCode() + 13 * (timeZone.hashCode() + 13 * locale.hashCode()); }