KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > storage > search > implementation > BasicFieldValueDateConstraint


1 /*
2
3 This software is OSI Certified Open Source Software.
4 OSI Certified is a certification mark of the Open Source Initiative.
5
6 The license (Mozilla version 1.0) can be read at the MMBase site.
7 See http://www.MMBase.org/license
8
9 */

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.5 2005/07/08 12:23:45 pierre Exp $
19  * @since MMBase-1.8
20  */

21 public class BasicFieldValueDateConstraint extends BasicFieldValueConstraint implements FieldValueDateConstraint {
22
23     /** The date part. */
24     private int part = -1; // unset
25

26     /**
27      * Constructor.
28      * Depending on the field type, the value must be of type
29      * <code>String</code> or <code>Number</code>.
30      *
31      * @param field The associated field.
32      * @param value The non-null property value.
33      * @param part Which part of the date to compare
34      * @throws IllegalArgumentException when an invalid argument is supplied.
35      */

36     public BasicFieldValueDateConstraint(StepField field, Object JavaDoc value, int part) {
37         super(field, value);
38         if (field.getType() != org.mmbase.bridge.Field.TYPE_DATETIME) {
39             throw new IllegalArgumentException JavaDoc("Date value constraints can only be applied to 'DATETIME' type fields");
40         }
41         setPart(part);
42     }
43
44     public int getPart() {
45         return part;
46     }
47
48     /**
49      * Returns a description of the part
50      */

51     public String JavaDoc getPartDescription() {
52         try {
53             return FieldValueDateConstraint.PART_DESCRIPTIONS[part];
54         } catch (IndexOutOfBoundsException JavaDoc ioobe) {
55             return null;
56         }
57     }
58
59     public void setPart(int p) {
60         part = p;
61     }
62
63     // javadoc is inherited
64
public boolean equals(Object JavaDoc obj) {
65         return super.equals(obj) && ((FieldValueDateConstraint)obj).getPart() == part;
66     }
67
68     // javadoc is inherited
69
public int hashCode() {
70         return super.hashCode() + part * 117;
71     }
72
73     // javadoc is inherited
74
public String JavaDoc toString() {
75         StringBuffer JavaDoc sb = new StringBuffer JavaDoc("BasicFieldValueDateConstraint(inverse:").
76         append(isInverse()).
77         append(", field:").append(getFieldName()).
78         append(", casesensitive:").append(isCaseSensitive()).
79         append(", operator:").append(getOperatorDescription()).
80         append(", value:").append(getValue()).
81         append(", date-part:").append(getPartDescription()).
82         append(")");
83         return sb.toString();
84     }
85 }
86
Popular Tags