01: /*
02:
03: This software is OSI Certified Open Source Software.
04: OSI Certified is a certification mark of the Open Source Initiative.
05:
06: The license (Mozilla version 1.0) can be read at the MMBase site.
07: See http://www.MMBase.org/license
08:
09: */
10: package org.mmbase.storage.search.implementation;
11:
12: import org.mmbase.storage.search.*;
13:
14: /**
15: * A constraint on a 'part' of a DateTime field. E.g. where extract(YEAR, lastmodified) = 2004.
16: *
17: * @author Michiel Meeuwissen
18: * @version $Id: BasicFieldValueDateConstraint.java,v 1.6 2006/10/16 12:56:57 pierre Exp $
19: * @since MMBase-1.8
20: */
21: public class BasicFieldValueDateConstraint extends
22: BasicFieldValueConstraint implements FieldValueDateConstraint {
23:
24: /** The date part. */
25: private int part = -1; // unset
26:
27: /**
28: * Constructor.
29: * Depending on the field type, the value must be of type
30: * <code>String</code> or <code>Number</code>.
31: *
32: * @param field The associated field.
33: * @param value The non-null property value.
34: * @param part Which part of the date to compare
35: * @throws IllegalArgumentException when an invalid argument is supplied.
36: */
37: public BasicFieldValueDateConstraint(StepField field, Object value,
38: int part) {
39: super (field, value);
40: if (field.getType() != org.mmbase.bridge.Field.TYPE_DATETIME) {
41: throw new IllegalArgumentException(
42: "Date value constraints can only be applied to 'DATETIME' type fields");
43: }
44: setPart(part);
45: }
46:
47: public int getPart() {
48: return part;
49: }
50:
51: /**
52: * Returns a description of the part
53: */
54: public String getPartDescription() {
55: try {
56: return FieldValueDateConstraint.PART_DESCRIPTIONS[part];
57: } catch (IndexOutOfBoundsException ioobe) {
58: return null;
59: }
60: }
61:
62: public void setPart(int p) {
63: part = p;
64: }
65:
66: // javadoc is inherited
67: public boolean equals(Object obj) {
68: return super .equals(obj)
69: && ((FieldValueDateConstraint) obj).getPart() == part;
70: }
71:
72: // javadoc is inherited
73: public int hashCode() {
74: return super .hashCode() + part * 117;
75: }
76:
77: // javadoc is inherited
78: public String toString() {
79: StringBuilder sb = new StringBuilder(
80: "BasicFieldValueDateConstraint(inverse:").append(
81: isInverse()).append(", field:").append(getFieldName())
82: .append(", casesensitive:").append(isCaseSensitive())
83: .append(", operator:").append(getOperatorDescription())
84: .append(", value:").append(getValue()).append(
85: ", date-part:").append(getPartDescription())
86: .append(")");
87: return sb.toString();
88: }
89: }
|