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-2018 Delft University of Technology.
* BSD-style license. See DSOL License.
* @author Peter Jacobs
* @author Alexander Verbraeck
* @see java.lang.ref.Reference
* @since 1.5
* @param null
.
* @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 the value to set
*/
protected abstract void set(final T value);
/**
* writes a serializable method to stream
* @param out 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 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());
}
}