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 final 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.

  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    equals(@GuardSatisfied @Nullable Object obj)
     
    @Nullable V1
    Returns the first element of the pair, or null if it has been garbage-collected.
    @Nullable V2
    Returns 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
  • 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)
      Returns the first element of the pair, or null if it has been garbage-collected.
      Returns:
      the first element of the pair, 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)
      Returns 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