package org.opentrafficsim.base;
import java.io.Serializable;
import java.util.Objects;
import org.djunits.value.vdouble.scalar.Time;
/**
* An object with a time stamp, where the object is of a specific class.
*
* Copyright (c) 2013-2021 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
* BSD-style license. See OpenTrafficSim License.
*
* $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
* initial version Jan 29, 2016
* @author Alexander Verbraeck
* @author Peter Knoppers
* @param the time stamped object class.
*/
public class TimeStampedObject implements Serializable
{
/** */
private static final long serialVersionUID = 20160129L;
/** The object. */
private final C object;
/** The time stamp. */
private final Time timestamp;
/**
* Construct a new TimeStampedObject.
* @param object C; the object.
* @param timestamp Time; the time stamp.
*/
public TimeStampedObject(final C object, final Time timestamp)
{
this.object = object;
this.timestamp = timestamp;
}
/**
* Retrieve the object.
* @return C; the object
*/
public final C getObject()
{
return this.object;
}
/**
* Retrieve the time stamp.
* @return Time; the time stamp
*/
public final Time getTimestamp()
{
return this.timestamp;
}
/** {@inheritDoc} */
@Override
public final String toString()
{
return "TimeStampedObject [object=" + this.object + ", timestamp=" + this.timestamp + "]";
}
/** {@inheritDoc} */
@Override
public int hashCode()
{
return Objects.hash(this.object, this.timestamp);
}
/** {@inheritDoc} */
@Override
@SuppressWarnings("checkstyle:needbraces")
public boolean equals(final Object obj)
{
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
TimeStampedObject> other = (TimeStampedObject>) obj;
return Objects.equals(this.object, other.object) && Objects.equals(this.timestamp, other.timestamp);
}
}