Interface ReferenceResolver

All Known Implementing Classes:
ListReferenceResolver, MapReferenceResolver

public interface ReferenceResolver
When references are enabled, this tracks objects that have already been read or written, provides an ID for objects that are written, and looks up by ID objects that have been read.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Returns a new ID for an object that is being written for the first time.
    getReadObject(Class type, int id)
    Returns the object for the specified ID.
    int
    Returns an ID for the object if it has been written previously, otherwise returns -1.
    int
    Reserves the ID for the next object that will be read.
    void
    Called by Kryo.reset().
    void
    setKryo(Kryo kryo)
    Sets the Kryo instance that this ClassResolver will be used for.
    void
    setReadObject(int id, Object object)
    Sets the ID for an object that has been read.
    boolean
    Returns true if references will be written for the specified type.
  • Method Details

    • setKryo

      void setKryo(Kryo kryo)
      Sets the Kryo instance that this ClassResolver will be used for. This is called automatically by Kryo.
    • getWrittenId

      int getWrittenId(Object object)
      Returns an ID for the object if it has been written previously, otherwise returns -1.
    • addWrittenObject

      int addWrittenObject(Object object)
      Returns a new ID for an object that is being written for the first time.
      Returns:
      The ID, which is stored more efficiently if it is positive and must not be -1 or -2.
    • nextReadId

      int nextReadId(Class type)
      Reserves the ID for the next object that will be read. This is called only the first time an object is encountered.
      Parameters:
      type - The type of object that will be read.
      Returns:
      The ID, which is stored more efficiently if it is positive and must not be -1 or -2.
    • setReadObject

      void setReadObject(int id, Object object)
      Sets the ID for an object that has been read.
      Parameters:
      id - The ID from nextReadId(Class).
    • getReadObject

      Object getReadObject(Class type, int id)
      Returns the object for the specified ID. The ID and object are guaranteed to have been previously passed in a call to setReadObject(int, Object).
    • reset

      void reset()
      Called by Kryo.reset().
    • useReferences

      boolean useReferences(Class type)
      Returns true if references will be written for the specified type.
      Parameters:
      type - Will never be a primitive type, but may be a primitive type wrapper.