Class Reference<T>

java.lang.Object
org.tentackle.trip.Reference<T>
Type Parameters:
T - the type of the de-duplicatable object

public final class Reference<T> extends Object
A reference to a de-duplicatable object.
  • Constructor Details

    • Reference

      public Reference(int referenceId, boolean sent, boolean isSender)
      Creates a new reference.
      Parameters:
      referenceId - the reference id, starting from 0
      sent - true if already sent, false if the object content follows in the stream
      isSender - true if this is a reference from the sender, false if from the receiver
    • Reference

      public Reference(int referenceId)
      Creates an unsent sender reference.
      Parameters:
      referenceId - the reference id, starting from 0
  • Method Details

    • getReferenceId

      public int getReferenceId()
      Gets the reference id.
      Returns:
      the reference id, starting from 0
    • isSender

      public boolean isSender()
      Checks if this is a reference from the sender.
      Returns:
      true if this is a reference from the sender, false if from the receiver
    • isSent

      public boolean isSent()
      Checks if the reference has been sent.
      Returns:
      true if already sent, false if the object content follows in the stream
    • getObject

      public T getObject()
      Gets the referenced object.
      Returns:
      the referenced object
    • setObject

      public void setObject(T object)
      Sets the referenced object.
      Parameters:
      object - the referenced object
    • send

      public void send(TripStream stream)
      Sends the reference to the given stream.
      Parameters:
      stream - the stream to write to
    • markSent

      public void markSent()
      Marks the reference as sent.
    • markReceived

      public void markReceived()
      Marks the reference as received and the object's content read.
    • isObjectFollowing

      public boolean isObjectFollowing()
      Returns whether the object content follows this reference.
      Returns:
      true if the object content follows this reference
    • read

      public static <T> Reference<T> read(TripStream stream, OpCode opCode)
      Reads a reference from the given stream.
      Parameters:
      stream - the stream to read from
      opCode - the op code (already read from the stream)
      Returns:
      the reference
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object