001    package sale;
002    
003    /**
004     * This class is an implementation of the {@link Time Time} interface.
005     *
006     * A Long value is used to represent the time.
007     *
008     * @author Sven Matznick
009     * @version 2.0 13/06/1999
010     * @since v2.0
011     */
012    public class Step extends Object implements Time {
013    
014        // variables
015        /**
016         * Current time.
017         *
018         * @serial
019         */
020        private Long m_lTime = new Long(0);
021    
022        /**
023         * Default interval.
024         *
025         * @serial
026         */
027        private Long m_lDefaultInterval = new Long(1);
028    
029        /**
030         * Creates a new step with default starting time 0.
031         */
032        public Step() {
033        } // default time already set
034    
035        /**
036         * Creates a new step with the given long value as the starting time.
037         *
038         * @param lInitTime a Long: the initial time.
039         */
040        public Step(Long lInitTime) {
041            m_lTime = lInitTime;
042        }
043    
044        /**
045         * Set the given Long as the new time value.
046         *
047         * @override Never
048         *
049         * @param oTime the new time value.
050         *
051         * @exception IllegalArgumentException if the given object is not convertible to a Long
052         */
053        public void setTime(Object oTime) throws IllegalArgumentException {
054            if (!(oTime instanceof Number)) {
055                throw new IllegalArgumentException("Parameter oTime has to be of class Number or a subclass.");
056            }
057            m_lTime = new Long(((Number)oTime).longValue());
058        }
059    
060        /**
061         * Get the current time.
062         *
063         * @override Never
064         *
065         * @return a Long representing the current time.
066         */
067        public Object getTime() {
068            return (m_lTime);
069        }
070    
071        /**
072         * Increase the time by the given interval.
073         *
074         * @override Never
075         *
076         * @param oInterval the interval to increase time by
077         *
078         * @exception IllegalArgumentException if the given object is not convertible to a Long
079         */
080        public void goAhead(Object oInterval) throws IllegalArgumentException {
081            if (!(oInterval instanceof Number)) {
082                throw new IllegalArgumentException("Parameter oInterval has to be of type Number.");
083            }
084            long lHelp = m_lTime.longValue();
085            long lInterval = ((Number)oInterval).longValue();
086            lHelp += lInterval;
087            m_lTime = new Long(lHelp);
088        }
089    
090        /**
091         * Get the default time interval.
092         *
093         * @override Never
094         *
095         * @return a Long describing the default time interval of 1.
096         */
097        public Object getDefaultInterval() {
098            return (m_lDefaultInterval);
099        }
100    
101        /**
102         * Create and return a time stamp.
103         *
104         * @override Never
105         *
106         * @param lStampNumber the number of the stamp
107         *
108         * @return a fresh time stamp.
109         */
110        public Comparable getTimeStamp(long lStampNumber) {
111            String sReturn = ("000000000" + m_lTime.toString()).substring(m_lTime.toString().length());
112            sReturn = sReturn + ("000000000" +
113                    Long.toString(lStampNumber)).substring(Long.toString(lStampNumber).length());
114    
115            return sReturn;
116        }
117    
118        /**
119         * Return the current time.
120         *
121         * @override Never
122         *
123         * @return a String describing the current time
124         */
125        public String toString() {
126            return m_lTime.toString();
127        }
128    }