41 |
|
|
42 |
import java.io.Serializable; |
import java.io.Serializable; |
43 |
import java.io.UnsupportedEncodingException; |
import java.io.UnsupportedEncodingException; |
|
import java.lang.ref.WeakReference; |
|
44 |
import java.util.Comparator; |
import java.util.Comparator; |
|
import java.util.WeakHashMap; |
|
45 |
import java.util.Locale; |
import java.util.Locale; |
46 |
import java.util.regex.Pattern; |
import java.util.regex.Pattern; |
47 |
import java.util.regex.PatternSyntaxException; |
import java.util.regex.PatternSyntaxException; |
87 |
private static final long serialVersionUID = -6849794470754667710L; |
private static final long serialVersionUID = -6849794470754667710L; |
88 |
|
|
89 |
/** |
/** |
|
* Holds the references for each intern()'d String. If all references to |
|
|
* the string disappear, and the VM properly supports weak references, |
|
|
* the String will be GC'd. |
|
|
*/ |
|
|
private static final WeakHashMap internTable = new WeakHashMap(); |
|
|
|
|
|
/** |
|
90 |
* Stores unicode multi-character uppercase expansion table. |
* Stores unicode multi-character uppercase expansion table. |
91 |
* @see #toUpperCase(char) |
* @see #toUpperCase(char) |
92 |
* @see CharData#UPPER_EXPAND |
* @see CharData#UPPER_EXPAND |
1587 |
} |
} |
1588 |
|
|
1589 |
/** |
/** |
1590 |
* Fetches this String from the intern hashtable. If two Strings are |
* If two Strings are considered equal, by the equals() method, |
1591 |
* considered equal, by the equals() method, then intern() will return the |
* then intern() will return the same String instance. ie. |
1592 |
* same String instance. ie. if (s1.equals(s2)) then |
* if (s1.equals(s2)) then (s1.intern() == s2.intern()). |
1593 |
* (s1.intern() == s2.intern()). All string literals and string-valued |
* All string literals and string-valued constant expressions |
1594 |
* constant expressions are already interned. |
* are already interned. |
1595 |
* |
* |
1596 |
* @return the interned String |
* @return the interned String |
1597 |
*/ |
*/ |
1598 |
public String intern() |
public String intern() |
1599 |
{ |
{ |
1600 |
synchronized (internTable) |
return VMString.intern(this); |
|
{ |
|
|
WeakReference ref = (WeakReference) internTable.get(this); |
|
|
if (ref != null) |
|
|
{ |
|
|
String s = (String) ref.get(); |
|
|
// If s is null, then no strong references exist to the String; |
|
|
// the weak hash map will soon delete the key. |
|
|
if (s != null) |
|
|
return s; |
|
|
} |
|
|
internTable.put(this, new WeakReference(this)); |
|
|
} |
|
|
return this; |
|
1601 |
} |
} |
1602 |
|
|
1603 |
/** |
/** |