Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libGDBMS / src / com / hardcode / gdbms / engine / values / DateValue.java @ 1956

History | View | Annotate | Download (3.14 KB)

1
package com.hardcode.gdbms.engine.values;
2

    
3
import com.hardcode.gdbms.engine.instruction.IncompatibleTypesException;
4

    
5
import java.io.Serializable;
6

    
7
import java.sql.Date;
8

    
9
import java.text.SimpleDateFormat;
10

    
11

    
12
/**
13
 * Wrapper sobre el tipo Date
14
 *
15
 * @author Fernando Gonz?lez Cort?s
16
 */
17
public class DateValue extends AbstractValue implements Serializable {
18
        private Date value;
19

    
20
        /**
21
         * Creates a new DateValue object.
22
         *
23
         * @param d DOCUMENT ME!
24
         */
25
        DateValue(Date d) {
26
                value = d;
27
        }
28

    
29
        /**
30
         * Creates a new DateValue object.
31
         */
32
        DateValue() {
33
        }
34

    
35
        /**
36
         * Establece el valor
37
         *
38
         * @param d valor
39
         */
40
        public void setValue(java.util.Date d) {
41
                value = new Date(d.getTime());
42
        }
43

    
44
        /**
45
         * @see com.hardcode.gdbms.engine.values.Operations#equals(com.hardcode.gdbms.engine.values.DateValue)
46
         */
47
        public Value equals(Value value) throws IncompatibleTypesException {
48
                if (value instanceof DateValue) {
49
                        return new BooleanValue(this.value.equals(((DateValue) value).value));
50
                } else {
51
                        throw new IncompatibleTypesException();
52
                }
53
        }
54

    
55
        /**
56
         * @see com.hardcode.gdbms.engine.values.Operations#greater(com.hardcode.gdbms.engine.values.DateValue)
57
         */
58
        public Value greater(Value value) throws IncompatibleTypesException {
59
                if (value instanceof DateValue) {
60
                        return new BooleanValue(this.value.compareTo(
61
                                        ((DateValue) value).value) > 0);
62
                } else {
63
                        throw new IncompatibleTypesException();
64
                }
65
        }
66

    
67
        /**
68
         * @see com.hardcode.gdbms.engine.values.Operations#greaterEqual(com.hardcode.gdbms.engine.values.DateValue)
69
         */
70
        public Value greaterEqual(Value value) throws IncompatibleTypesException {
71
                if (value instanceof DateValue) {
72
                        return new BooleanValue(this.value.compareTo(
73
                                        ((DateValue) value).value) >= 0);
74
                } else {
75
                        throw new IncompatibleTypesException();
76
                }
77
        }
78

    
79
        /**
80
         * @see com.hardcode.gdbms.engine.values.Operations#less(com.hardcode.gdbms.engine.values.DateValue)
81
         */
82
        public Value less(Value value) throws IncompatibleTypesException {
83
                if (value instanceof DateValue) {
84
                        return new BooleanValue(this.value.compareTo(
85
                                        ((DateValue) value).value) < 0);
86
                } else {
87
                        throw new IncompatibleTypesException();
88
                }
89
        }
90

    
91
        /**
92
         * @see com.hardcode.gdbms.engine.values.Operations#lessEqual(com.hardcode.gdbms.engine.values.DateValue)
93
         */
94
        public Value lessEqual(Value value) throws IncompatibleTypesException {
95
                if (value instanceof DateValue) {
96
                        return new BooleanValue(this.value.compareTo(
97
                                        ((DateValue) value).value) <= 0);
98
                } else {
99
                        throw new IncompatibleTypesException();
100
                }
101
        }
102

    
103
        /**
104
         * @see com.hardcode.gdbms.engine.values.Operations#notEquals(com.hardcode.gdbms.engine.values.DateValue)
105
         */
106
        public Value notEquals(Value value) throws IncompatibleTypesException {
107
                if (value instanceof DateValue) {
108
                        return new BooleanValue(!this.value.equals(
109
                                        ((DateValue) value).value));
110
                } else {
111
                        throw new IncompatibleTypesException();
112
                }
113
        }
114

    
115
        /**
116
         * DOCUMENT ME!
117
         *
118
         * @return DOCUMENT ME!
119
         */
120
        public String toString() {
121
                SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
122

    
123
                return sdf.format(value);
124
        }
125

    
126
        /**
127
         * @see com.hardcode.gdbms.engine.values.Value#doHashCode()
128
         */
129
        public int doHashCode() {
130
                return value.hashCode();
131
        }
132
}