Package org.plumelib.util
Class WeakIdentityPair<V1 extends @NonNull Object,V2 extends @NonNull Object>
java.lang.Object
org.plumelib.util.WeakIdentityPair<V1,V2>
- Type Parameters:
V1
- the type of the pair's first elementV2
- the type of the pair's second element
Immutable pair class with weakly-held values.
Differs from IPair
in the following ways: cannot hold null, holds its elements with
weak pointers, clients must use getter methods rather than accessing the fields, and its
equals()
method uses object equality to compare its elements.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
@Nullable V1
getA()
Return the first element of the pair, or null if it has been garbage-collected.@Nullable V2
getB()
Return the second element of the pair, or null if it has been garbage-collected.int
hashCode()
static <T1 extends @NonNull Object,
T2 extends @NonNull Object>
WeakIdentityPair<T1,T2> of
(T1 a, T2 b) Creates a new weakly-held immutable pair.toString()
-
Constructor Details
-
WeakIdentityPair
Deprecated.useof(T1, T2)
Creates a new weakly-held immutable pair. Clients should useof(T1, T2)
.- Parameters:
a
- the first element of the pairb
- the second element of the pair
-
-
Method Details
-
of
public static <T1 extends @NonNull Object,T2 extends @NonNull Object> WeakIdentityPair<T1,T2> of(T1 a, T2 b) Creates a new weakly-held immutable pair.- Type Parameters:
T1
- type of first argumentT2
- type of second argument- Parameters:
a
- first argumentb
- second argument- Returns:
- a pair of the values (a, b)
-
getA
@SideEffectFree public @Nullable V1 getA(@GuardSatisfied WeakIdentityPair<V1 extends @NonNull Object, V2 extends @NonNull Object> this) Return the first element of the pair, or null if it has been garbage-collected.- Returns:
- the first element of the pail, or null if it has been garbage-collected
-
getB
@SideEffectFree public @Nullable V2 getB(@GuardSatisfied WeakIdentityPair<V1 extends @NonNull Object, V2 extends @NonNull Object> this) Return the second element of the pair, or null if it has been garbage-collected.- Returns:
- the second element of the pair, or null if it has been garbage-collected
-
equals
-
hashCode
-
toString
-
of(T1, T2)