package sale; /** * This class is an implementation of the {@link Time Time} interface. * * A Long value is used to represent the time. * * @author Sven Matznick * @version 2.0 13/06/1999 * @since v2.0 */ public class Step extends Object implements Time { // variables /** * Current time. * * @serial */ private Long m_lTime = new Long (0); /** * Default interval. * * @serial */ private Long m_lDefaultInterval = new Long (1); /** * Creates a new step with default starting time 0. */ public Step() { } // default time already set /** * Creates a new step with the given long value as the starting time. * * @param lInitTime a Long: the initial time. */ public Step(Long lInitTime) { m_lTime = lInitTime; } /** * Set the given Long as the new time value. * * @override Never * * @param oTime the new time value. * * @exception IllegalArgumentException if the given object is not convertible to a Long */ public void setTime (Object oTime) throws IllegalArgumentException { if (!(oTime instanceof Number)) throw new IllegalArgumentException("Parameter oTime has to be of class Number or a subclass."); m_lTime = new Long (((Number) oTime).longValue()); } /** * Get the current time. * * @override Never * * @return a Long representing the current time. */ public Object getTime() { return (m_lTime); } /** * Increase the time by the given interval. * * @override Never * * @param oInterval the interval to increase time by * * @exception IllegalArgumentException if the given object is not convertible to a Long */ public void goAhead (Object oInterval) throws IllegalArgumentException { if (!(oInterval instanceof Number)) throw new IllegalArgumentException ("Parameter oInterval has to be of type Number."); long lHelp = m_lTime.longValue(); long lInterval = ((Number) oInterval).longValue(); lHelp += lInterval; m_lTime = new Long (lHelp); } /** * Get the default time interval. * * @override Never * * @return a Long describing the default time interval of 1. */ public Object getDefaultInterval() { return (m_lDefaultInterval); } /** * Create and return a time stamp. * * @override Never * * @param lStampNumber the number of the stamp * * @return a fresh time stamp. */ public Comparable getTimeStamp (long lStampNumber) { String sReturn = ("000000000" + m_lTime.toString ()).substring(m_lTime.toString ().length()); sReturn = sReturn + ("000000000" + Long.toString (lStampNumber)).substring(Long.toString (lStampNumber).length()); return sReturn; } /** * Return the current time. * * @override Never * * @return a String describing the current time */ public String toString() { return m_lTime.toString(); } }