KickJava   Java API By Example, From Geeks To Geeks.

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


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  * Basic implementation.
16  * The tested operation is equality, unless it is explicitly set.
17  *
18  * @author Rob van Maris
19  * @version $Id: BasicFieldValueConstraint.java,v 1.11 2005/04/25 14:56:57 pierre Exp $
20  * @since MMBase-1.7
21  */

22 public class BasicFieldValueConstraint extends BasicFieldCompareConstraint
23 implements FieldValueConstraint {
24
25     /** The value. */
26     private Object JavaDoc value = null;
27
28     /**
29      * Constructor.
30      * Depending on the field type, the value must be of type
31      * <code>String</code> or <code>Number</code>.
32      *
33      * @param field The associated field.
34      * @param value The non-null property value.
35      * @throws IllegalArgumentException when an invalid argument is supplied.
36      */

37     public BasicFieldValueConstraint(StepField field, Object JavaDoc value) {
38         super(field);
39         setValue(value);
40     }
41
42     /**
43      * Sets value property.
44      * Depending on the field type, the value must be of type
45      * <code>String</code> or <code>Number</code>.
46      *
47      * @param value The non-null property value.
48      * @return This <code>BasicFieldValueConstraint</code> instance.
49      * @throws IllegalArgumentException when an invalid argument is supplied.
50      */

51     public BasicFieldValueConstraint setValue(Object JavaDoc value) {
52         BasicStepField.testValue(value, getField());
53         this.value = value;
54         return this;
55     }
56
57     // javadoc is inherited
58
public Object JavaDoc getValue() {
59         return value;
60     }
61
62     // javadoc is inherited
63
public boolean equals(Object JavaDoc obj) {
64         // Must be same class (subclasses should override this)!
65
if (obj != null && obj.getClass() == getClass()) {
66             BasicFieldValueConstraint constraint
67                 = (BasicFieldValueConstraint) obj;
68             return isInverse() == constraint.isInverse()
69                 && isCaseSensitive() == constraint.isCaseSensitive()
70                 && getField().getFieldName().equals(constraint.getField().getFieldName())
71                 && BasicStepField.compareSteps(getField().getStep(),
72                     constraint.getField().getStep())
73                 && getOperator() == constraint.getOperator()
74                 && BasicStepField.equalFieldValues(value, constraint.value);
75         } else {
76             return false;
77         }
78     }
79
80     // javadoc is inherited
81
public int hashCode() {
82         return super.hashCode()
83         + (value == null? 0: value.hashCode());
84     }
85
86     // javadoc is inherited
87
public String JavaDoc toString() {
88         StringBuffer JavaDoc sb = new StringBuffer JavaDoc("BasicFieldValueConstraint(inverse:").
89         append(isInverse()).
90         append(", field:").append(getFieldName()).
91         append(", casesensitive:").append(isCaseSensitive()).
92         append(", operator:").append(getOperatorDescription()).
93         append(", value:").append(getValue()).
94         append(")");
95         return sb.toString();
96     }
97 }
98
Popular Tags