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 caseSensitive property defaults to <code>true</code>.
017: *
018: * @author Rob van Maris
019: * @version $Id: BasicFieldConstraint.java,v 1.8 2006/10/16 12:56:57 pierre Exp $
020: * @since MMBase-1.7
021: */
022:
023: // this class would logically be abstract, but test-cases are instantiating it.
024: public class BasicFieldConstraint extends BasicConstraint implements
025: FieldConstraint {
026:
027: /** The associated field. */
028: private StepField field;
029:
030: /** The caseSensitive property. */
031: private boolean caseSensitive = true;
032:
033: /**
034: * Constructor.
035: * Protected, so only subclasses can be instantiated.
036: *
037: * @param field The associated field.
038: * @throws IllegalArgumentException when an invalid argument is supplied.
039: */
040: protected BasicFieldConstraint(StepField field) {
041: // Test for non-null value.
042: if (field == null) {
043: throw new IllegalArgumentException("Invalid field value: "
044: + field);
045: }
046: this .field = field;
047: }
048:
049: /**
050: * Sets caseSensitive property.
051: * This has only effect when the associated field is of string type.
052: *
053: * @return This <code>BasicFieldConstraint</code> instance.
054: * @param caseSensitive The caseSensitive property value.
055: */
056: public BasicFieldConstraint setCaseSensitive(boolean caseSensitive) {
057: this .caseSensitive = caseSensitive;
058: return this ;
059: }
060:
061: // javadoc is inherited
062: public StepField getField() {
063: return field;
064: }
065:
066: // javadoc is inheritied
067: public boolean isCaseSensitive() {
068: return caseSensitive;
069: }
070:
071: // javadoc is inherited
072: public boolean equals(Object obj) {
073: // Must be same class (subclasses should override this)!
074: if (obj != null && obj.getClass() == getClass()) {
075: BasicFieldConstraint constraint = (BasicFieldConstraint) obj;
076: return isInverse() == constraint.isInverse()
077: && caseSensitive == constraint.isCaseSensitive()
078: && field.getFieldName().equals(
079: constraint.getField().getFieldName())
080: && BasicStepField.compareSteps(
081: getField().getStep(), constraint.getField()
082: .getStep());
083: } else {
084: return false;
085: }
086: }
087:
088: // javadoc is inherited
089: public int hashCode() {
090: return super .hashCode()
091: + (isCaseSensitive() ? 0 : 73)
092: + 79
093: * field.getFieldName().hashCode()
094: + (field.getStep().getAlias() == null ? 87 * field
095: .getStep().getTableName().hashCode()
096: : 83 * field.getStep().getAlias().hashCode());
097: }
098:
099: /**
100: * Returns the main field's fieldname, possibly extended with the step'sname if known.
101: * May return null or partial fieldnames if not all data is available (for use in debugging).
102: */
103: public String getFieldName() {
104: return BasicStepField.getFieldName(getField());
105: }
106:
107: // javadoc is inherited
108: public String toString() {
109: StringBuilder sb = new StringBuilder(
110: "BasicFieldConstraint(inverse:").append(isInverse())
111: .append("field:").append(getFieldName()).append(
112: ", casesensitive:").append(isCaseSensitive())
113: .append(")");
114: return sb.toString();
115: }
116:
117: }
|