001    package data;
002    
003    /**
004     * Values that operate on {@link Number numbers}.
005     *
006     * <p>All the operations are implemented as you would expect, the implementation is given in concrete
007     * subclasses.</p>
008     *
009     * @author Steffen Zschaler
010     * @version 2.0 19/08/1999
011     * @since v2.0
012     */
013    public abstract class NumberValue implements Value {
014    
015        /**
016         * The actual value.
017         *
018         * @serial
019         */
020        private Number m_nbValue;
021    
022        /**
023         * Create a new NumberValue.
024         *
025         * @param nbValue the actual initial value.
026         */
027        public NumberValue(Number nbValue) {
028            super();
029    
030            setValue(nbValue);
031        }
032    
033        /**
034         * Set the actual value of the object.
035         *
036         * @override Sometimes Override if you want to impose restrictions on the class of the actual value.
037         *
038         * @param nbValue the new actual value.
039         */
040        public void setValue(Number nbValue) {
041            m_nbValue = nbValue;
042        }
043    
044        /**
045         * Get the actual value of the object.
046         *
047         * @override Never
048         */
049        public Number getValue() {
050            return m_nbValue;
051        }
052    
053        /**
054         * @override Sometimes The default implementation returns
055         * <pre>
056         * (getValue().longValue() == 0)
057         * </pre>
058         */
059        public boolean isAddZero() {
060            return (getValue().longValue() == 0);
061        }
062    
063        /**
064         * @override Sometimes The default implementation returns
065         * <pre>
066         * (getValue().longValue() > 0)
067         * </pre>
068         */
069        public boolean isGreaterZero() {
070            return getValue().longValue() > 0;
071        }
072    
073        /**
074         * @override Sometimes The default implementation returns
075         * <pre>
076         * (getValue().longValue() <= 0)
077         * </pre>
078         */
079        public boolean isLessZero() {
080            return getValue().longValue() < 0;
081        }
082    
083    
084    
085        /**
086         * @override Sometimes The default implementation returns
087         * <pre>
088         * isAddZero()
089         * </pre>
090         */
091        public boolean isMulZero() {
092            return isAddZero();
093        }
094    
095        /**
096         * @override Sometimes The default implementation returns
097         * <pre>
098         * (getValue().longValue() == 1)
099         * </pre>
100         */
101        public boolean isMulOne() {
102            return (getValue().longValue() == 1);
103        }
104    
105        /**
106         * @override Always
107         */
108        public abstract Object clone();
109    
110        /**
111         * Return a {@link String} representation of the object.
112         *
113         * @override Sometimes The default implementation returns
114         * <pre>
115         * getValue().toString()
116         * </pre>
117         */
118        public String toString() {
119            return getValue().toString();
120        }
121    }