186 |
* |
* |
187 |
* @serial should be -1 in serial streams |
* @serial should be -1 in serial streams |
188 |
*/ |
*/ |
189 |
private int hashcode; |
private transient int hashcode; |
190 |
|
|
191 |
/** |
/** |
192 |
* The default locale. Except for during bootstrapping, this should never be |
* The default locale. Except for during bootstrapping, this should never be |
709 |
* |
* |
710 |
* @return the hashcode |
* @return the hashcode |
711 |
*/ |
*/ |
712 |
public synchronized int hashCode() |
public int hashCode() |
713 |
{ |
{ |
|
// This method is synchronized because writeObject() might reset |
|
|
// the hashcode. |
|
714 |
return hashcode; |
return hashcode; |
715 |
} |
} |
716 |
|
|
729 |
return false; |
return false; |
730 |
Locale l = (Locale) obj; |
Locale l = (Locale) obj; |
731 |
|
|
|
// ??? We might also want to add: |
|
|
// hashCode() == l.hashCode() |
|
|
// But this is a synchronized method. Is the overhead worth it? |
|
|
// Measure this to make a decision. |
|
732 |
return (language == l.language |
return (language == l.language |
733 |
&& country == l.country |
&& country == l.country |
734 |
&& variant == l.variant); |
&& variant == l.variant); |
739 |
* |
* |
740 |
* @param output the stream to write to |
* @param output the stream to write to |
741 |
* @throws IOException if the write fails |
* @throws IOException if the write fails |
742 |
* @serialData the hashcode should always be written as -1, and recomputed |
* @serialData The first three fields are Strings representing language, |
743 |
* when reading it back |
* country, and variant. The fourth field is a placeholder for |
744 |
|
* the cached hashcode, but this is always written as -1, and |
745 |
|
* recomputed when reading it back. |
746 |
*/ |
*/ |
747 |
private synchronized void writeObject(ObjectOutputStream output) |
private void writeObject(ObjectOutputStream s) |
748 |
throws IOException |
throws IOException |
749 |
{ |
{ |
750 |
// Synchronized so that hashCode() doesn't get wrong value. |
s.writeObject(language); |
751 |
int tmpHashcode = hashcode; |
s.writeObject(country); |
752 |
hashcode = -1; |
s.writeObject(variant); |
753 |
output.defaultWriteObject(); |
// Hashcode field is always written as -1. |
754 |
hashcode = tmpHashcode; |
s.writeInt(-1); |
755 |
} |
} |
756 |
|
|
757 |
/** |
/** |
762 |
* @throws ClassNotFoundException if reading fails |
* @throws ClassNotFoundException if reading fails |
763 |
* @serialData the hashCode is always invalid and must be recomputed |
* @serialData the hashCode is always invalid and must be recomputed |
764 |
*/ |
*/ |
765 |
private void readObject(ObjectInputStream input) |
private void readObject(ObjectInputStream s) |
766 |
throws IOException, ClassNotFoundException |
throws IOException, ClassNotFoundException |
767 |
{ |
{ |
768 |
input.defaultReadObject(); |
language = ((String) s.readObject()).intern(); |
769 |
|
country = ((String) s.readObject()).intern(); |
770 |
|
variant = ((String) s.readObject()).intern(); |
771 |
|
// Recompute hashcode. |
772 |
hashcode = language.hashCode() ^ country.hashCode() ^ variant.hashCode(); |
hashcode = language.hashCode() ^ country.hashCode() ^ variant.hashCode(); |
773 |
} |
} |
774 |
} // class Locale |
} // class Locale |