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: * 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.12 2006/10/16 12:56:57 pierre Exp $
20: * @since MMBase-1.7
21: */
22: public class BasicFieldValueConstraint extends
23: BasicFieldCompareConstraint implements FieldValueConstraint {
24:
25: /** The value. */
26: private Object 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 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 value) {
52: BasicStepField.testValue(value, getField());
53: this .value = value;
54: return this ;
55: }
56:
57: // javadoc is inherited
58: public Object getValue() {
59: return value;
60: }
61:
62: // javadoc is inherited
63: public boolean equals(Object obj) {
64: // Must be same class (subclasses should override this)!
65: if (obj != null && obj.getClass() == getClass()) {
66: BasicFieldValueConstraint constraint = (BasicFieldValueConstraint) obj;
67: return isInverse() == constraint.isInverse()
68: && isCaseSensitive() == constraint
69: .isCaseSensitive()
70: && getField().getFieldName().equals(
71: constraint.getField().getFieldName())
72: && BasicStepField.compareSteps(
73: getField().getStep(), constraint.getField()
74: .getStep())
75: && getOperator() == constraint.getOperator()
76: && BasicStepField.equalFieldValues(value,
77: constraint.value);
78: } else {
79: return false;
80: }
81: }
82:
83: // javadoc is inherited
84: public int hashCode() {
85: return super .hashCode()
86: + (value == null ? 0 : value.hashCode());
87: }
88:
89: // javadoc is inherited
90: public String toString() {
91: StringBuilder sb = new StringBuilder(
92: "BasicFieldValueConstraint(inverse:").append(
93: isInverse()).append(", field:").append(getFieldName())
94: .append(", casesensitive:").append(isCaseSensitive())
95: .append(", operator:").append(getOperatorDescription())
96: .append(", value:").append(getValue()).append(")");
97: return sb.toString();
98: }
99: }
|