Class IdentityWrapper<T>

java.lang.Object
fr.inria.rules.integraal.model.util.wrapper.IdentityWrapper<T>
Type Parameters:
T - the type of the wrapped value

public final class IdentityWrapper<T> extends Object
A utility wrapper that enforces the default identity‑based hashCode and equals semantics for the wrapped object. Use this class when you need to place objects in hash‑based collections without being affected by any custom overrides on the object’s class.

Equality checks are performed with == and the hash code is the one returned by System.identityHashCode(Object), exactly mirroring java.lang.Object's original contract.

  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates an identity wrapper around the provided value.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Identity‑based equality.
    int
    Identity‑based hash code.
    static <T> IdentityWrapper<T>
    of(T value)
    Factory method creating a new IdentityWrapper instance.
    Returns a string representation of this wrapper.
    Returns the originally wrapped object.

    Methods inherited from class Object

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

    • IdentityWrapper

      public IdentityWrapper(T value)
      Creates an identity wrapper around the provided value.
      Parameters:
      value - the value to wrap
  • Method Details

    • of

      public static <T> IdentityWrapper<T> of(T value)
      Factory method creating a new IdentityWrapper instance.
      Type Parameters:
      T - the value type
      Parameters:
      value - the object to wrap, may be null
      Returns:
      an IdentityWrapper wrapping value
    • unwrap

      public T unwrap()
      Returns the originally wrapped object.
      Returns:
      the wrapped value, possibly null
    • hashCode

      public int hashCode()
      Identity‑based hash code.
      Overrides:
      hashCode in class Object
      Returns:
      identityHashCode of the wrapped value
    • equals

      public boolean equals(Object obj)
      Identity‑based equality.
      Overrides:
      equals in class Object
      Parameters:
      obj - the reference object with which to compare
      Returns:
      true if obj is an IdentityWrapper wrapping the same reference as this wrapper; false otherwise
    • toString

      public String toString()
      Returns a string representation of this wrapper.
      Overrides:
      toString in class Object