public final class Intern
extends java.lang.Object
Object.equals(java.lang.Object)
the object, and the client
discards the argument and uses the result instead. Since only one object exists for every set of
equal objects, space usage is reduced. Time may also be reduced, since it is possible to use
==
instead of .equals()
for comparisons.
Java builds in interning for Strings, but not for other objects. The methods in this class extend interning to all Java objects.
Modifier and Type | Method and Description |
---|---|
static double |
intern(double d)
Interns a double A no-op.
|
static @Interned java.lang.Double |
intern(java.lang.Double a)
Intern (canonicalize) a Double.
|
static double[] |
intern(double[] a)
Intern (canonicalize) a double[].
|
static int[] |
intern(int[] a)
Intern (canonicalize) an int[].
|
static @Interned java.lang.Integer |
intern(java.lang.Integer a)
Intern (canonicalize) an Integer.
|
static long |
intern(long l)
Interns a long.
|
static @Interned java.lang.Long |
intern(java.lang.Long a)
Intern (canonicalize) a Long.
|
static long[] |
intern(long[] a)
Intern (canonicalize) a long[].
|
static @Interned @PolyNull java.lang.Object |
intern(@PolyNull java.lang.Object a)
Convenience method to intern an Object when we don't know its run-time type.
|
static @PolyNull @Interned java.lang.Object[] |
intern(@PolyNull @Interned @PolyValue java.lang.Object[] a)
Intern (canonicalize) an Object[].
|
static @Interned @PolyNull @PolyValue @SameLen(value="#1") java.lang.String |
intern(@PolyNull @PolyValue java.lang.String a)
Interns a String.
|
static @PolyNull @Interned java.lang.String[] |
intern(@PolyNull @Interned java.lang.String[] a)
Intern (canonicalize) a String[].
|
static @Interned java.lang.Double |
internedDouble(double d)
Returns an interned Double with value i.
|
static @Interned java.lang.Double |
internedDouble(java.lang.String s)
Returns an interned Double with value parsed from the string.
|
static @Interned java.lang.Integer |
internedInteger(int i)
Returns an interned Integer with value i.
|
static @Interned java.lang.Integer |
internedInteger(java.lang.String s)
Returns an interned Integer with value parsed from the string.
|
static @Interned java.lang.Long |
internedLong(long i)
Returns an interned Long with value i.
|
static @Interned java.lang.Long |
internedLong(java.lang.String s)
Returns an interned Long with value parsed from the string.
|
static @Interned java.lang.String[] |
internStrings(java.lang.String[] a)
Replace each element of the array by its interned version.
|
static double[] |
internSubsequence(double[] seq,
@IndexFor(value="#1") @LessThan(value="#3") int start,
@NonNegative @LTLengthOf(value="#1",offset="#2 - 1") int end)
Returns a subsequence of seq from start to end that is interned.
|
static int[] |
internSubsequence(int[] seq,
@IndexFor(value="#1") @LessThan(value="#3") int start,
@NonNegative @LTLengthOf(value="#1",offset="#2 - 1") int end)
Return an interned subsequence of seq from start (inclusive) to end (exclusive).
|
static long[] |
internSubsequence(long[] seq,
@IndexFor(value="#1") @LessThan(value="#3") int start,
@NonNegative @LTLengthOf(value="#1",offset="#2 - 1") int end)
Returns a subsequence of seq from start to end that is interned.
|
static @PolyNull @Interned java.lang.Object[] |
internSubsequence(@PolyNull @Interned java.lang.Object[] seq,
@IndexFor(value="#1") @LessThan(value="#3") int start,
@NonNegative @LTLengthOf(value="#1",offset="#2 - 1") int end)
Returns a subsequence of seq from start to end that is interned.
|
static @PolyNull @Interned java.lang.String[] |
internSubsequence(@PolyNull @Interned java.lang.String[] seq,
@IndexFor(value="#1") @LessThan(value="#3") int start,
@NonNegative @LTLengthOf(value="#1",offset="#2 - 1") int end)
Returns a subsequence of seq from start to end that is interned.
|
static boolean |
isInterned(@Nullable java.lang.Object value)
Return true if the argument is interned (is canonical among all objects equal to itself).
|
public static @Interned java.lang.String[] internStrings(java.lang.String[] a)
a
- the array whose elements to intern in placeString.intern()
@Pure public static boolean isInterned(@Nullable java.lang.Object value)
value
- the value to test for interning@Pure public static @Interned @PolyNull @PolyValue @SameLen(value="#1") java.lang.String intern(@PolyNull @PolyValue java.lang.String a)
null
.a
- the string to intern; may be null@Pure public static long intern(long l)
l
- the long to intern@Pure public static double intern(double d)
d
- the double to intern@Pure public static @Interned java.lang.Integer intern(java.lang.Integer a)
a
- an Integer to canonicalizepublic static @Interned java.lang.Integer internedInteger(int i)
i
- the value to internpublic static @Interned java.lang.Integer internedInteger(java.lang.String s)
s
- the string to parse@Pure public static @Interned java.lang.Long intern(java.lang.Long a)
a
- the value to internpublic static @Interned java.lang.Long internedLong(long i)
i
- the value to internpublic static @Interned java.lang.Long internedLong(java.lang.String s)
s
- the string to parse@Pure public static int[] intern(int[] a)
a
- the array to canonicalize@Pure public static long[] intern(long[] a)
a
- the array to canonicalize@Pure public static @Interned java.lang.Double intern(java.lang.Double a)
a
- the Double to canonicalizepublic static @Interned java.lang.Double internedDouble(double d)
d
- the value to internpublic static @Interned java.lang.Double internedDouble(java.lang.String s)
s
- the string to parse@Pure public static double[] intern(double[] a)
a
- the array to canonicalize@Pure public static @PolyNull @Interned java.lang.String[] intern(@PolyNull @Interned java.lang.String[] a)
a
- the array to canonicalize. Its elements should already be interned.@Pure public static @PolyNull @Interned java.lang.Object[] intern(@PolyNull @Interned @PolyValue java.lang.Object[] a)
a
- the array to canonicalize@Pure public static @Interned @PolyNull java.lang.Object intern(@PolyNull java.lang.Object a)
a
- an Object to canonicalizepublic static int[] internSubsequence(int[] seq, @IndexFor(value="#1") @LessThan(value="#3") int start, @NonNegative @LTLengthOf(value="#1",offset="#2 - 1") int end)
The result is the same as computing the subsequence and then interning it, but this method is more efficient: if the subsequence is already interned, it avoids computing the subsequence.
For example, since derived variables in Daikon compute the subsequence many times, this shortcut saves quite a bit of computation. It saves even more when there may be many derived variables that are non-canonical, since they are guaranteed to be ==.
seq
- the interned sequence whose subsequence should be computed and internedstart
- the index of the start of the subsequence to compute and internend
- the index of the end of the subsequence to compute and intern@Pure public static long[] internSubsequence(long[] seq, @IndexFor(value="#1") @LessThan(value="#3") int start, @NonNegative @LTLengthOf(value="#1",offset="#2 - 1") int end)
seq
- the interned sequence whose subsequence should be computed and internedstart
- the index of the start of the subsequence to compute and internend
- the index of the end of the subsequence to compute and interninternSubsequence(int[], int, int)
@Pure public static double[] internSubsequence(double[] seq, @IndexFor(value="#1") @LessThan(value="#3") int start, @NonNegative @LTLengthOf(value="#1",offset="#2 - 1") int end)
seq
- the interned sequence whose subsequence should be computed and internedstart
- the index of the start of the subsequence to compute and internend
- the index of the end of the subsequence to compute and interninternSubsequence(int[], int, int)
@Pure public static @PolyNull @Interned java.lang.Object[] internSubsequence(@PolyNull @Interned java.lang.Object[] seq, @IndexFor(value="#1") @LessThan(value="#3") int start, @NonNegative @LTLengthOf(value="#1",offset="#2 - 1") int end)
seq
- the interned sequence whose subsequence should be computed and internedstart
- the index of the start of the subsequence to compute and internend
- the index of the end of the subsequence to compute and interninternSubsequence(int[], int, int)
@Pure public static @PolyNull @Interned java.lang.String[] internSubsequence(@PolyNull @Interned java.lang.String[] seq, @IndexFor(value="#1") @LessThan(value="#3") int start, @NonNegative @LTLengthOf(value="#1",offset="#2 - 1") int end)
seq
- the interned sequence whose subsequence should be computed and internedstart
- the index of the start of the subsequence to compute and internend
- the index of the end of the subsequence to compute and interninternSubsequence(int[], int, int)