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: * The tested operation is equality, unless it is explicitly set.
017: *
018: * @author Rob van Maris
019: * @version $Id: BasicCompareFieldsConstraint.java,v 1.7 2006/10/16 12:56:57 pierre Exp $
020: * @since MMBase-1.7
021: */
022: public class BasicCompareFieldsConstraint extends
023: BasicFieldCompareConstraint implements CompareFieldsConstraint {
024:
025: /** The second associated field. */
026: private StepField field2 = null;
027:
028: /**
029: * Constructor.
030: *
031: * @param field1 The associated field.
032: * @param field2 The second associated field.
033: * @throws IllegalArgumentException when an invalid argument is supplied.
034: */
035: public BasicCompareFieldsConstraint(StepField field1,
036: StepField field2) {
037: super (field1);
038:
039: // Test for non-null value.
040: if (field2 == null) {
041: throw new IllegalArgumentException("Invalid field2 value: "
042: + field2);
043: }
044:
045: // Test for matching fieldtype.
046: if (field1.getType() != field2.getType()) {
047: throw new IllegalArgumentException(
048: "Fieldtypes do not match: " + field1.getType()
049: + " and " + field2.getType());
050: }
051: this .field2 = field2;
052: }
053:
054: // javadoc is inherited
055: public StepField getField2() {
056: return field2;
057: }
058:
059: // javadoc is inherited
060: public boolean equals(Object obj) {
061: // Must be same class (subclasses should override this)!
062: if (obj != null && obj.getClass() == getClass()) {
063: BasicCompareFieldsConstraint constraint = (BasicCompareFieldsConstraint) obj;
064: return isInverse() == constraint.isInverse()
065: && isCaseSensitive() == constraint
066: .isCaseSensitive()
067: && getField().getFieldName().equals(
068: constraint.getField().getFieldName())
069: && BasicStepField.compareSteps(
070: getField().getStep(), constraint.getField()
071: .getStep())
072: && getOperator() == constraint.getOperator()
073: && field2.getFieldName().equals(
074: constraint.getField2().getFieldName())
075: && BasicStepField.compareSteps(field2.getStep(),
076: constraint.getField2().getStep());
077: } else {
078: return false;
079: }
080: }
081:
082: // javadoc is inherited
083: public int hashCode() {
084: return super .hashCode()
085: + 93
086: * field2.getFieldName().hashCode()
087: + (field2.getStep().getAlias() == null ? 101 * field2
088: .getStep().getTableName().hashCode()
089: : 97 * field2.getStep().getAlias().hashCode());
090: }
091:
092: // javadoc is inherited
093: public String toString() {
094: StringBuilder sb = new StringBuilder(
095: "CompareFieldsConstraint(inverse:").append(isInverse())
096: .append(", field:").append(getFieldName()).append(
097: ", casesensitive:").append(isCaseSensitive())
098: .append(", operator:").append(getOperatorDescription())
099: .append(", field2:").append(
100: BasicStepField.getFieldName(getField2()))
101: .append(")");
102: return sb.toString();
103: }
104: }
|