Package com.esotericsoftware.kryo.util
Class ListReferenceResolver
java.lang.Object
com.esotericsoftware.kryo.util.ListReferenceResolver
- All Implemented Interfaces:
ReferenceResolver
Uses an
ArrayList
to track objects that have already been written. This is more efficient than
MapReferenceResolver
for graphs with few objects, providing an approximate 15% increase in deserialization speed. This
should not be used for graphs with many objects because it uses a linear look up to find objects that have already been
written.-
Field Summary
Fields -
Constructor Summary
Constructors -
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 false for all primitive wrappers.
-
Field Details
-
kryo
-
seenObjects
-
-
Constructor Details
-
ListReferenceResolver
public ListReferenceResolver()
-
-
Method Details
-
setKryo
Description copied from interface:ReferenceResolver
Sets the Kryo instance that this ClassResolver will be used for. This is called automatically by Kryo.- Specified by:
setKryo
in interfaceReferenceResolver
-
addWrittenObject
Description copied from interface:ReferenceResolver
Returns a new ID for an object that is being written for the first time.- Specified by:
addWrittenObject
in interfaceReferenceResolver
- Returns:
- The ID, which is stored more efficiently if it is positive and must not be -1 or -2.
-
getWrittenId
Description copied from interface:ReferenceResolver
Returns an ID for the object if it has been written previously, otherwise returns -1.- Specified by:
getWrittenId
in interfaceReferenceResolver
-
nextReadId
Description copied from interface:ReferenceResolver
Reserves the ID for the next object that will be read. This is called only the first time an object is encountered.- Specified by:
nextReadId
in interfaceReferenceResolver
- 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
Description copied from interface:ReferenceResolver
Sets the ID for an object that has been read.- Specified by:
setReadObject
in interfaceReferenceResolver
- Parameters:
id
- The ID fromReferenceResolver.nextReadId(Class)
.
-
getReadObject
Description copied from interface:ReferenceResolver
Returns the object for the specified ID. The ID and object are guaranteed to have been previously passed in a call toReferenceResolver.setReadObject(int, Object)
.- Specified by:
getReadObject
in interfaceReferenceResolver
-
reset
public void reset()Description copied from interface:ReferenceResolver
Called byKryo.reset()
.- Specified by:
reset
in interfaceReferenceResolver
-
useReferences
Returns false for all primitive wrappers.- Specified by:
useReferences
in interfaceReferenceResolver
- Parameters:
type
- Will never be a primitive type, but may be a primitive type wrapper.
-