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 element
V2 - the type of the pair's second element

public class WeakIdentityPair<V1 extends @NonNull Object,V2 extends @NonNull Object> extends Object
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.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final WeakReference<V1>
    The first element of the pair.
    private final WeakReference<V2>
    The second element of the pair.
    private final int
    The hash code of this.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Deprecated.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    equals(@GuardSatisfied @Nullable Object obj)
     
    @Nullable V1
    Return the first element of the pair, or null if it has been garbage-collected.
    @Nullable V2
    Return the second element of the pair, or null if it has been garbage-collected.
    int
     
    static <T1 extends @NonNull Object, T2 extends @NonNull Object>
    WeakIdentityPair<T1,T2>
    of(T1 a, T2 b)
    Creates a new weakly-held immutable pair.
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • a

      private final WeakReference<V1 extends @NonNull Object> a
      The first element of the pair.
    • b

      private final WeakReference<V2 extends @NonNull Object> b
      The second element of the pair.
    • hashCode

      private final int hashCode
      The hash code of this.
  • Constructor Details

    • WeakIdentityPair

      @Deprecated public WeakIdentityPair(V1 a, V2 b)
      Deprecated.
      Creates a new weakly-held immutable pair. Clients should use of(T1, T2).
      Parameters:
      a - the first element of the pair
      b - 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 argument
      T2 - type of second argument
      Parameters:
      a - first argument
      b - 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

      @SideEffectFree public boolean equals(@GuardSatisfied WeakIdentityPair<V1 extends @NonNull Object,V2 extends @NonNull Object> this, @GuardSatisfied @Nullable Object obj)
      Overrides:
      equals in class Object
    • hashCode

      @Pure public int hashCode(@GuardSatisfied WeakIdentityPair<V1 extends @NonNull Object,V2 extends @NonNull Object> this)
      Overrides:
      hashCode in class Object
    • toString

      @SideEffectFree public String toString(@GuardSatisfied WeakIdentityPair<V1 extends @NonNull Object,V2 extends @NonNull Object> this)
      Overrides:
      toString in class Object