Package com.esotericsoftware.kryo
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 TypeMethodDescriptionint
addWrittenObject
(Object object) 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
getWrittenId
(Object object) Returns an ID for the object if it has been written previously, otherwise returns -1.int
nextReadId
(Class type) Reserves the ID for the next object that will be read.void
reset()
Called byKryo.reset()
.void
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
useReferences
(Class type) Returns true if references will be written for the specified type.
-
Method Details
-
setKryo
Sets the Kryo instance that this ClassResolver will be used for. This is called automatically by Kryo. -
getWrittenId
Returns an ID for the object if it has been written previously, otherwise returns -1. -
addWrittenObject
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
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
Sets the ID for an object that has been read.- Parameters:
id
- The ID fromnextReadId(Class)
.
-
getReadObject
Returns the object for the specified ID. The ID and object are guaranteed to have been previously passed in a call tosetReadObject(int, Object)
. -
reset
void reset()Called byKryo.reset()
. -
useReferences
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.
-