Statistics
| Revision:

svn-gvsig-desktop / tags / v1_1_Build_1003 / libraries / libGDBMS / src / main / java / com / hardcode / gdbms / engine / values / TimeValue.java @ 12271

History | View | Annotate | Download (4.15 KB)

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

    
3
import java.io.Serializable;
4
import java.sql.Time;
5
import java.sql.Types;
6
import java.text.DateFormat;
7
import java.text.SimpleDateFormat;
8

    
9
import com.hardcode.gdbms.engine.instruction.IncompatibleTypesException;
10

    
11

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

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

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

    
35
        /**
36
         * Establece el valor
37
         *
38
         * @param d valor
39
         */
40
        public void setValue(Time d) {
41
                value = d;
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 NullValue) {
49
                        return ValueFactory.createValue(false);
50
                }
51

    
52
                if (value instanceof TimeValue) {
53
                        return new BooleanValue(this.value.equals(((TimeValue) value).value));
54
                } else {
55
                        throw new IncompatibleTypesException();
56
                }
57
        }
58

    
59
        /**
60
         * @see com.hardcode.gdbms.engine.values.Operations#greater(com.hardcode.gdbms.engine.values.DateValue)
61
         */
62
        public Value greater(Value value) throws IncompatibleTypesException {
63
                if (value instanceof NullValue) {
64
                        return ValueFactory.createValue(false);
65
                }
66

    
67
                if (value instanceof TimeValue) {
68
                        return new BooleanValue(this.value.compareTo(
69
                                        ((TimeValue) value).value) > 0);
70
                } else {
71
                        throw new IncompatibleTypesException();
72
                }
73
        }
74

    
75
        /**
76
         * @see com.hardcode.gdbms.engine.values.Operations#greaterEqual(com.hardcode.gdbms.engine.values.DateValue)
77
         */
78
        public Value greaterEqual(Value value) throws IncompatibleTypesException {
79
                if (value instanceof NullValue) {
80
                        return ValueFactory.createValue(false);
81
                }
82

    
83
                if (value instanceof TimeValue) {
84
                        return new BooleanValue(this.value.compareTo(
85
                                        ((TimeValue) value).value) >= 0);
86
                } else {
87
                        throw new IncompatibleTypesException();
88
                }
89
        }
90

    
91
        /**
92
         * @see com.hardcode.gdbms.engine.values.Operations#less(com.hardcode.gdbms.engine.values.DateValue)
93
         */
94
        public Value less(Value value) throws IncompatibleTypesException {
95
                if (value instanceof NullValue) {
96
                        return ValueFactory.createValue(false);
97
                }
98

    
99
                if (value instanceof TimeValue) {
100
                        return new BooleanValue(this.value.compareTo(
101
                                        ((TimeValue) value).value) < 0);
102
                } else {
103
                        throw new IncompatibleTypesException();
104
                }
105
        }
106

    
107
        /**
108
         * @see com.hardcode.gdbms.engine.values.Operations#lessEqual(com.hardcode.gdbms.engine.values.DateValue)
109
         */
110
        public Value lessEqual(Value value) throws IncompatibleTypesException {
111
                if (value instanceof NullValue) {
112
                        return ValueFactory.createValue(false);
113
                }
114

    
115
                if (value instanceof TimeValue) {
116
                        return new BooleanValue(this.value.compareTo(
117
                                        ((TimeValue) value).value) <= 0);
118
                } else {
119
                        throw new IncompatibleTypesException();
120
                }
121
        }
122

    
123
        /**
124
         * @see com.hardcode.gdbms.engine.values.Operations#notEquals(com.hardcode.gdbms.engine.values.DateValue)
125
         */
126
        public Value notEquals(Value value) throws IncompatibleTypesException {
127
                if (value instanceof NullValue) {
128
                        return ValueFactory.createValue(false);
129
                }
130

    
131
                if (value instanceof TimeValue) {
132
                        return new BooleanValue(!this.value.equals(
133
                                        ((TimeValue) value).value));
134
                } else {
135
                        throw new IncompatibleTypesException();
136
                }
137
        }
138

    
139
        /**
140
         * DOCUMENT ME!
141
         *
142
         * @return DOCUMENT ME!
143
         */
144
        public String toString() {
145
                return DateFormat.getTimeInstance().format(value);
146
        }
147

    
148
        /**
149
         * @see com.hardcode.gdbms.engine.values.Value#doHashCode()
150
         */
151
        public int doHashCode() {
152
                return value.hashCode();
153
        }
154

    
155
    /**
156
     * @return
157
     */
158
    public Time getValue() {
159
        return value;
160
    }
161

    
162
    /**
163
     * @see com.hardcode.gdbms.engine.values.Value#getStringValue(com.hardcode.gdbms.engine.data.driver.ValueWriter)
164
     */
165
    public String getStringValue(ValueWriter writer) {
166
        return writer.getStatementString(value);
167
    }
168

    
169
    /**
170
     * @see com.hardcode.gdbms.engine.values.Value#getSQLType()
171
     */
172
    public int getSQLType() {
173
        return Types.TIME;
174
    }
175
        public int getWidth() {
176
                return this.toString().length();
177
        }    
178
}