Package org.apache.hadoop.util
Class StringInterner
java.lang.Object
org.apache.hadoop.util.StringInterner
Provides string interning utility methods. For weak interning,
we use the standard String.intern() call, that performs very well
(no problems with PermGen overflowing, etc.) starting from JDK 7.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic String[]internStringsInArray(String[] strings) Interns all the strings in the given array in place, returning the same array.static StringstrongIntern(String sample) Interns and returns a reference to the representative instance for any of a collection of string instances that are equal to each other.static StringweakIntern(String sample) Interns and returns a reference to the representative instance for any of a collection of string instances that are equal to each other.
-
Constructor Details
-
StringInterner
public StringInterner()
-
-
Method Details
-
strongIntern
Interns and returns a reference to the representative instance for any of a collection of string instances that are equal to each other. Retains strong reference to the instance, thus preventing it from being garbage-collected.- Parameters:
sample- string instance to be interned- Returns:
- strong reference to interned string instance
-
weakIntern
Interns and returns a reference to the representative instance for any of a collection of string instances that are equal to each other. Retains weak reference to the instance, and so does not prevent it from being garbage-collected.- Parameters:
sample- string instance to be interned- Returns:
- weak reference to interned string instance
-
internStringsInArray
Interns all the strings in the given array in place, returning the same array.- Parameters:
strings- strings.- Returns:
- internStringsInArray.
-