001: /*
002:
003: This software is OSI Certified Open Source Software.
004: OSI Certified is a certification mark of the Open Source Initiative.
005:
006: The license (Mozilla version 1.0) can be read at the MMBase site.
007: See http://www.MMBase.org/license
008:
009: */
010: package org.mmbase.storage.search.implementation;
011:
012: import org.mmbase.storage.search.*;
013:
014: /**
015: * Basic implementation.
016: *
017: * @author Rob van Maris
018: * @version $Id: BasicFieldValueBetweenConstraint.java,v 1.9 2006/10/16 12:56:57 pierre Exp $
019: * @since MMBase-1.7
020: */
021: public class BasicFieldValueBetweenConstraint extends
022: BasicFieldConstraint implements FieldValueBetweenConstraint {
023:
024: /** The lower limit. */
025: private Object lowerLimit = null;
026:
027: /** The upper limit. */
028: private Object upperLimit = null;
029:
030: /**
031: * Constructor.
032: * <p>
033: * Depending on the field type, the limit values must be of type
034: * <code>String</code> or <code>Number</code>.
035: *
036: * @param field The associated field.
037: * @param lowerLimit The lower limit.
038: * @param upperLimit The upper limit.
039: * @throws IllegalArgumentException when an invalid argument is supplied.
040: */
041: public BasicFieldValueBetweenConstraint(StepField field,
042: Object lowerLimit, Object upperLimit) {
043:
044: super (field);
045: setLowerLimit(lowerLimit);
046: setUpperLimit(upperLimit);
047: }
048:
049: /**
050: * Sets the lower limit property.
051: * <p>
052: * Depending on the field type, the value must be of type
053: * <code>String</code> or <code>Number</code>.
054: *
055: * @param lowerLimit The non-null lower limit property value.
056: * @return This <code>BasicFieldValueBetweenConstraint</code> instance.
057: * @throws IllegalArgumentException when an invalid argument is supplied.
058: */
059: public BasicFieldValueBetweenConstraint setLowerLimit(
060: Object lowerLimit) {
061: this .lowerLimit = lowerLimit;
062: return this ;
063: }
064:
065: /**
066: * Sets the upper limit property.
067: * <p>
068: * Depending on the field type, the value must be of type
069: * <code>String</code> or <code>Number</code>.
070: *
071: * @param upperLimit The non-null upper limit property value.
072: * @return This <code>BasicFieldValueBetweenConstraint</code> instance.
073: * @throws IllegalArgumentException when an invalid argument is supplied.
074: */
075: public BasicFieldValueBetweenConstraint setUpperLimit(
076: Object upperLimit) {
077: this .upperLimit = upperLimit;
078: return this ;
079: }
080:
081: // javadoc is inherited
082: public Object getLowerLimit() {
083: return lowerLimit;
084: }
085:
086: // javadoc is inherited
087: public Object getUpperLimit() {
088: return upperLimit;
089: }
090:
091: // javadoc is inherited
092: public boolean equals(Object obj) {
093: if (obj == this ) {
094: return true;
095: }
096: // Must be same class (subclasses should override this)!
097: if (obj != null && obj.getClass() == getClass()) {
098: BasicFieldValueBetweenConstraint constraint = (BasicFieldValueBetweenConstraint) obj;
099: return isInverse() == constraint.isInverse()
100: && isCaseSensitive() == constraint
101: .isCaseSensitive()
102: && getField().getFieldName().equals(
103: constraint.getField().getFieldName())
104: && BasicStepField.compareSteps(
105: getField().getStep(), constraint.getField()
106: .getStep())
107: && lowerLimit.equals(constraint.lowerLimit)
108: && upperLimit.equals(constraint.upperLimit);
109: } else {
110: return false;
111: }
112: }
113:
114: // javadoc is inherited
115: public int hashCode() {
116: return 101 * (lowerLimit.hashCode() + 97 * (upperLimit
117: .hashCode() + 89 * super .hashCode()));
118: }
119:
120: // javadoc is inherited
121: public String toString() {
122: StringBuilder sb = new StringBuilder(
123: "FieldValueBetweenConstraint(inverse:").append(
124: isInverse()).append(", field:").append(getFieldName())
125: .append(", casesensitive:").append(isCaseSensitive())
126: .append(", lower:").append(getLowerLimit()).append(
127: ", upper:").append(getUpperLimit()).append(")");
128: return sb.toString();
129: }
130: }
|