package nl.tudelft.simulation.event.ref; import java.io.IOException; import java.io.ObjectOutputStream; import java.io.Serializable; /** * A Reference interface defining the indirect pointer access to an object. *
* Copyright (c) 2002-2019 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See * for project information https://simulation.tudelft.nl. The DSOL * project is distributed under a three-clause BSD-style license, which can be found at * * https://simulation.tudelft.nl/dsol/3.0/license.html. *
* @author Peter Jacobs * @author Alexander Verbraeck * @see java.lang.ref.Reference * @since 1.5 * @paramnull
.
* @return The object to which this reference refers, or null
if this reference object has been cleared.
*/
public abstract T get();
/**
* sets the value of the reference
* @param value T; the value to set
*/
protected abstract void set(final T value);
/**
* writes a serializable method to stream
* @param out ObjectOutputStream; the output stream
* @throws IOException on IOException
*/
private synchronized void writeObject(final ObjectOutputStream out) throws IOException
{
out.writeObject(this.get());
}
/**
* reads a serializable method from stream
* @param in java.io.ObjectInputStream; the input stream
* @throws IOException on IOException
* @throws ClassNotFoundException on ClassNotFoundException
*/
@SuppressWarnings("unchecked")
private void readObject(final java.io.ObjectInputStream in) throws IOException, ClassNotFoundException
{
this.set((T) in.readObject());
}
}