01: /*
02: * DateEqualsComparator.java
03: *
04: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
05: *
06: * Copyright 2002-2008, Thomas Kellerer
07: * No part of this code maybe reused without the permission of the author
08: *
09: * To contact the author please send an email to: support@sql-workbench.net
10: *
11: */
12: package workbench.storage.filter;
13:
14: import workbench.util.ValueConverter;
15:
16: /**
17: * @author support@sql-workbench.net
18: */
19: public class DateEqualsComparator implements ColumnComparator {
20: private int sqlType;
21:
22: public DateEqualsComparator() {
23: this .sqlType = java.sql.Types.TIMESTAMP;
24: }
25:
26: public DateEqualsComparator(int type) {
27: this .sqlType = type;
28: }
29:
30: public boolean supportsIgnoreCase() {
31: return false;
32: }
33:
34: public String getValueExpression(Object value) {
35: return (value == null ? "" : value.toString());
36: }
37:
38: public String getOperator() {
39: return "=";
40: }
41:
42: public boolean needsValue() {
43: return true;
44: }
45:
46: public boolean comparesEquality() {
47: return true;
48: }
49:
50: public boolean evaluate(Object reference, Object value,
51: boolean ignoreCase) {
52: if (reference == null || value == null)
53: return false;
54: try {
55: return reference.equals(value);
56: } catch (Exception e) {
57: return false;
58: }
59: }
60:
61: public boolean supportsType(Class valueClass) {
62: return (java.util.Date.class.isAssignableFrom(valueClass));
63: }
64:
65: public boolean equals(Object other) {
66: return (other instanceof DateEqualsComparator);
67: }
68:
69: public boolean validateInput(Object value) {
70: if (value == null)
71: return false;
72:
73: if (value instanceof java.util.Date)
74: return true;
75:
76: ValueConverter converter = new ValueConverter();
77: try {
78: converter.convertValue(value, this .sqlType);
79: return true;
80: } catch (Exception e) {
81: return false;
82: }
83: }
84:
85: }
|