root / trunk / libraries / libAnimation / src / com / iver / cit / gvsig / animation / dateFilter / DateFilter.java @ 18138
History | View | Annotate | Download (4.66 KB)
1 |
package com.iver.cit.gvsig.animation.dateFilter; |
---|---|
2 |
|
3 |
import java.sql.Date; |
4 |
import java.text.ParseException; |
5 |
import java.text.SimpleDateFormat; |
6 |
import java.util.Calendar; |
7 |
|
8 |
//import com.hardcode.gdbms.engine.values.DateValue;
|
9 |
//import com.hardcode.gdbms.engine.values.NullValue;
|
10 |
//import com.hardcode.gdbms.engine.values.Value;
|
11 |
//import com.iver.cit.gvsig.fmap.core.IFeature;
|
12 |
import com.iver.utiles.IPersistence; |
13 |
import com.iver.utiles.XMLEntity; |
14 |
|
15 |
//public class DateFilter implements ICustomVectorialFilter, IPersistence {
|
16 |
public class DateFilter { |
17 |
//
|
18 |
// public static int FIELDTYPE_DATE = 0;
|
19 |
// public static int FIELDTYPE_DATESTRING = 1;
|
20 |
//
|
21 |
// public static int BOTH = 2 | 4;
|
22 |
// public static int BEFORE_BEGIN = 2;
|
23 |
// public static int AFTER_END = 4;
|
24 |
//
|
25 |
// private int fieldType = -1;
|
26 |
//
|
27 |
// private int filterFieldIndex = -1;
|
28 |
// private Date minDate = null;
|
29 |
// private Date maxDate = null;
|
30 |
// // derived
|
31 |
// private SimpleDateFormat localeDF = null;
|
32 |
// private SimpleDateFormat javaDF = null;
|
33 |
// private Calendar cl = null;
|
34 |
//
|
35 |
// private int filterMode = BEFORE_BEGIN;
|
36 |
//
|
37 |
// public void setFieldIndex(int index) {
|
38 |
// filterFieldIndex = index;
|
39 |
// }
|
40 |
//
|
41 |
// public void setFieldType(int type) {
|
42 |
// fieldType = type;
|
43 |
// }
|
44 |
//
|
45 |
// public void setMinDate(Date miniDate) {
|
46 |
// minDate = miniDate;
|
47 |
// }
|
48 |
//
|
49 |
// public void setMaxDate(Date maxiDate) {
|
50 |
// maxDate = maxiDate;
|
51 |
// }
|
52 |
//
|
53 |
// public int getFieldType() {
|
54 |
// return fieldType;
|
55 |
// }
|
56 |
//
|
57 |
// public Date getMinDate() {
|
58 |
// return minDate;
|
59 |
// }
|
60 |
//
|
61 |
// public Date getMaxDate() {
|
62 |
// return maxDate;
|
63 |
// }
|
64 |
//
|
65 |
// public boolean accepts(IFeature feature) {
|
66 |
//
|
67 |
// if (filterFieldIndex == -1 || minDate == null || maxDate == null)
|
68 |
// return false;
|
69 |
//
|
70 |
// Value val = feature.getAttribute(filterFieldIndex);
|
71 |
// if (val instanceof NullValue)
|
72 |
// return false;
|
73 |
//
|
74 |
// Date dateVal = null;
|
75 |
// if (fieldType == FIELDTYPE_DATE) {
|
76 |
// try {
|
77 |
// dateVal = ((DateValue) val).getValue();
|
78 |
// } catch (RuntimeException e) {
|
79 |
// return false;
|
80 |
// }
|
81 |
// } else if (fieldType == FIELDTYPE_DATESTRING) {
|
82 |
// if (localeDF == null)
|
83 |
// localeDF = new SimpleDateFormat("dd/MM/yyyy");
|
84 |
// if (javaDF == null)
|
85 |
// javaDF = new SimpleDateFormat("yyyy-MM-dd");
|
86 |
//
|
87 |
// String valStr = val.toString();
|
88 |
//
|
89 |
// try {
|
90 |
// java.util.Date utDate = localeDF.parse(valStr); // reads locale
|
91 |
// // dd/MM/yyyy
|
92 |
// // strings
|
93 |
// String utDateStr = javaDF.format(utDate); // outputs
|
94 |
// // yyyy-MM-dd
|
95 |
// dateVal = Date.valueOf(utDateStr); // creates Date for
|
96 |
// // comparison
|
97 |
// } catch (ParseException e) {
|
98 |
// return false;
|
99 |
// }
|
100 |
// }
|
101 |
//
|
102 |
// try {
|
103 |
// String dateValStr = dateVal.toString();
|
104 |
// String minDateStr = minDate.toString();
|
105 |
// String maxDateStr = maxDate.toString();
|
106 |
//
|
107 |
// if (((this.filterMode & BEFORE_BEGIN) != BEFORE_BEGIN))
|
108 |
// if (dateVal.compareTo(minDate) < 0)
|
109 |
// return false;
|
110 |
//
|
111 |
// if (((this.filterMode & AFTER_END) != AFTER_END))
|
112 |
// if (dateVal.compareTo(maxDate) > 0)
|
113 |
// return false;
|
114 |
//
|
115 |
// } catch (Exception e) {
|
116 |
// return false;
|
117 |
// }
|
118 |
// return true;
|
119 |
// }
|
120 |
//
|
121 |
// public String getClassName() {
|
122 |
// return this.getClass().getName();
|
123 |
// }
|
124 |
//
|
125 |
// public XMLEntity getXMLEntity() {
|
126 |
// XMLEntity xml = new XMLEntity();
|
127 |
//
|
128 |
// xml.putProperty("fieldType", fieldType);
|
129 |
// xml.putProperty("fieldIndex", filterFieldIndex);
|
130 |
// xml.putProperty("minDate", minDate.toString());
|
131 |
// xml.putProperty("maxDate", maxDate.toString());
|
132 |
//
|
133 |
// return xml;
|
134 |
// }
|
135 |
//
|
136 |
// public void setXMLEntity(XMLEntity xml) {
|
137 |
// if (xml.contains("fieldType"))
|
138 |
// fieldType = xml.getIntProperty("fieldType");
|
139 |
//
|
140 |
// if (xml.contains("fieldIndex"))
|
141 |
// filterFieldIndex = xml.getIntProperty("fieldIndex");
|
142 |
//
|
143 |
// if (xml.contains("minDate"))
|
144 |
// minDate = Date.valueOf(xml.getStringProperty("minDate"));
|
145 |
//
|
146 |
// if (xml.contains("maxDate"))
|
147 |
// maxDate = Date.valueOf(xml.getStringProperty("maxDate"));
|
148 |
// }
|
149 |
//
|
150 |
// public String toString() {
|
151 |
// String result = "";
|
152 |
//
|
153 |
// result += minDate.toString() + "\n" + maxDate.toString();
|
154 |
//
|
155 |
// return result;
|
156 |
// }
|
157 |
//
|
158 |
// public boolean compareTo(ICustomVectorialFilter filter) {
|
159 |
// DateFilter filterAux = (DateFilter) filter;
|
160 |
// boolean type = this.getFieldType() == filterAux.getFieldType();
|
161 |
// boolean min = this.getMinDate().toString().equals(
|
162 |
// filterAux.getMinDate().toString());
|
163 |
// boolean max = this.getMaxDate().toString().equals(
|
164 |
// filterAux.getMaxDate().toString());
|
165 |
//
|
166 |
// return (type && min && max);
|
167 |
// }
|
168 |
//
|
169 |
// public int getFilterMode() {
|
170 |
// return filterMode;
|
171 |
// }
|
172 |
//
|
173 |
// public void setFilterMode(int filterMode) {
|
174 |
// this.filterMode = filterMode;
|
175 |
// }
|
176 |
} |