Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /* Copyright (c) 2008, Nathan Sweet
  * All rights reserved.
  * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following
  * conditions are met:
  * - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  * - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
  * disclaimer in the documentation and/or other materials provided with the distribution.
 * - Neither the name of Esoteric Software nor the names of its contributors may be used to endorse or promote products derived
 * from this software without specific prior written permission.
package com.esotericsoftware.kryo.util;
Uses an java.util.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.

Nathan Sweet <>
public class ListReferenceResolver implements ReferenceResolver {
	protected Kryo kryo;
	protected final ArrayList seenObjects = new ArrayList();
	public void setKryo (Kryo kryo) {
		this. = kryo;
	public int addWrittenObject (Object object) {
		int id = .size();
		return id;
	public int getWrittenId (Object object) {
		for (int i = 0, n = .size(); i < ni++)
			if (.get(i) == objectreturn i;
		return -1;
	public int nextReadId (Class type) {
		int id = .size();
		return id;
	public void setReadObject (int idObject object) {
	public Object getReadObject (Class typeint id) {
		return .get(id);
	public void reset () {

Returns false for Boolean, Byte, Character, and Short.
	public boolean useReferences (Class type) {
		return !Util.isWrapperClass(type);
New to GrepCode? Check out our FAQ X