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        /**
015             * ID for serialization.
016             */
017            private static final long serialVersionUID = -2380533186623780185L;
018    
019            // variables
020        /**
021         * Current time.
022         *
023         * @serial
024         */
025        private Long m_lTime = new Long(0);
026    
027        /**
028         * Default interval.
029         *
030         * @serial
031         */
032        private Long m_lDefaultInterval = new Long(1);
033    
034        /**
035         * Creates a new step with default starting time 0.
036         */
037        public Step() {
038        } // default time already set
039    
040        /**
041         * Creates a new step with the given long value as the starting time.
042         *
043         * @param lInitTime a Long: the initial time.
044         */
045        public Step(Long lInitTime) {
046            m_lTime = lInitTime;
047        }
048    
049        /**
050         * Set the given Long as the new time value.
051         *
052         * @override Never
053         *
054         * @param oTime the new time value.
055         *
056         * @exception IllegalArgumentException if the given object is not convertible to a Long
057         */
058        public void setTime(Object oTime) throws IllegalArgumentException {
059            if (!(oTime instanceof Number)) {
060                throw new IllegalArgumentException("Parameter oTime has to be of class Number or a subclass.");
061            }
062            m_lTime = new Long(((Number)oTime).longValue());
063        }
064    
065        /**
066         * Get the current time.
067         *
068         * @override Never
069         *
070         * @return a Long representing the current time.
071         */
072        public Object getTime() {
073            return (m_lTime);
074        }
075    
076        /**
077         * Increase the time by the given interval.
078         *
079         * @override Never
080         *
081         * @param oInterval the interval to increase time by
082         *
083         * @exception IllegalArgumentException if the given object is not convertible to a Long
084         */
085        public void goAhead(Object oInterval) throws IllegalArgumentException {
086            if (!(oInterval instanceof Number)) {
087                throw new IllegalArgumentException("Parameter oInterval has to be of type Number.");
088            }
089            long lHelp = m_lTime.longValue();
090            long lInterval = ((Number)oInterval).longValue();
091            lHelp += lInterval;
092            m_lTime = new Long(lHelp);
093        }
094    
095        /**
096         * Get the default time interval.
097         *
098         * @override Never
099         *
100         * @return a Long describing the default time interval of 1.
101         */
102        public Object getDefaultInterval() {
103            return (m_lDefaultInterval);
104        }
105    
106        /**
107         * Create and return a time stamp.
108         *
109         * @override Never
110         *
111         * @param lStampNumber the number of the stamp
112         *
113         * @return a fresh time stamp.
114         */
115        public Comparable<String> getTimeStamp(long lStampNumber) {
116            String sReturn = ("000000000" + m_lTime.toString()).substring(m_lTime.toString().length());
117            sReturn = sReturn + ("000000000" +
118                    Long.toString(lStampNumber)).substring(Long.toString(lStampNumber).length());
119    
120            return sReturn;
121        }
122    
123        /**
124         * Return the current time.
125         *
126         * @override Never
127         *
128         * @return a String describing the current time
129         */
130        public String toString() {
131            return m_lTime.toString();
132        }
133    }