001    package org.nakedobjects.applib.value;
002    
003    import org.nakedobjects.applib.annotation.Value;
004    import org.nakedobjects.applib.clock.Clock;
005    
006    
007    /**
008     * Value object representing a date/time value marking a point in time This is a user facing date/time value,
009     * more a marker used to indicate the temporal relationship between two objects.
010     * 
011     * @see DateTime
012     */
013    @Value(semanticsProviderName = "org.nakedobjects.metamodel.value.TimeStampValueSemanticsProvider")
014    public class TimeStamp extends Magnitude {
015        private static final long serialVersionUID = 1L;
016        private final long time;
017    
018        /**
019         * Create a TimeStamp object for storing a timeStamp set to the current time.
020         */
021        public TimeStamp() {
022            time = Clock.getTime();
023        }
024    
025        public TimeStamp(final long time) {
026            this.time = time;
027        }
028    
029        /**
030         * returns true if the time stamp of this object has the same value as the specified timeStamp
031         */
032        @Override
033        public boolean isEqualTo(final Magnitude timeStamp) {
034            if (timeStamp instanceof TimeStamp) {
035                return this.time == ((TimeStamp) timeStamp).time;
036            } else {
037                throw new IllegalArgumentException("Parameter must be of type Time");
038            }
039        }
040    
041        /**
042         * returns true if the timeStamp of this object is earlier than the specified timeStamp
043         */
044        @Override
045        public boolean isLessThan(final Magnitude timeStamp) {
046            if (timeStamp instanceof TimeStamp) {
047                return time < ((TimeStamp) timeStamp).time;
048            } else {
049                throw new IllegalArgumentException("Parameter must be of type Time");
050            }
051        }
052    
053        public long longValue() {
054            return time;
055        }
056    
057        @Override
058        public String toString() {
059            return "Time Stamp " + longValue();
060        }
061    }
062    // Copyright (c) Naked Objects Group Ltd.