KickJava   Java API By Example, From Geeks To Geeks.

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


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 caseSensitive property defaults to <code>true</code>.
17  *
18  * @author Rob van Maris
19  * @version $Id: BasicFieldConstraint.java,v 1.7 2005/05/02 13:03:30 michiel Exp $
20  * @since MMBase-1.7
21  */

22
23 // this class would logically be abstract, but test-cases are instantiating it.
24
public class BasicFieldConstraint extends BasicConstraint implements FieldConstraint {
25
26     /** The associated field. */
27     private StepField field;
28
29     /** The caseSensitive property. */
30     private boolean caseSensitive = true;
31
32     /**
33      * Constructor.
34      * Protected, so only subclasses can be instantiated.
35      *
36      * @param field The associated field.
37      * @throws IllegalArgumentException when an invalid argument is supplied.
38      */

39     protected BasicFieldConstraint(StepField field) {
40         // Test for non-null value.
41
if (field == null) {
42             throw new IllegalArgumentException JavaDoc("Invalid field value: " + field);
43         }
44         this.field = field;
45     }
46     
47     /**
48      * Sets caseSensitive property.
49      * This has only effect when the associated field is of string type.
50      *
51      * @return This <code>BasicFieldConstraint</code> instance.
52      * @param caseSensitive The caseSensitive property value.
53      */

54     public BasicFieldConstraint setCaseSensitive(boolean caseSensitive) {
55         this.caseSensitive = caseSensitive;
56         return this;
57     }
58
59     // javadoc is inherited
60
public StepField getField() {
61         return field;
62     }
63
64     // javadoc is inheritied
65
public boolean isCaseSensitive() {
66         return caseSensitive;
67     }
68
69     // javadoc is inherited
70
public boolean equals(Object JavaDoc obj) {
71         // Must be same class (subclasses should override this)!
72
if (obj != null && obj.getClass() == getClass()) {
73             BasicFieldConstraint constraint = (BasicFieldConstraint) obj;
74             return isInverse() == constraint.isInverse()
75                 && caseSensitive == constraint.isCaseSensitive()
76                 && field.getFieldName().equals(constraint.getField().getFieldName())
77                 && BasicStepField.compareSteps(getField().getStep(),
78                     constraint.getField().getStep());
79         } else {
80             return false;
81         }
82     }
83
84     // javadoc is inherited
85
public int hashCode() {
86         return super.hashCode()
87         + (isCaseSensitive()? 0: 73)
88         + 79 * field.getFieldName().hashCode()
89         + (field.getStep().getAlias() == null?
90             87 * field.getStep().getTableName().hashCode():
91             83 * field.getStep().getAlias().hashCode());
92     }
93
94     /**
95      * Returns the main field's fieldname, possibly extended with the step'sname if known.
96      * May return null or partial fieldnames if not all data is available (for use in debugging).
97      */

98     public String JavaDoc getFieldName() {
99         return BasicStepField.getFieldName(getField());
100     }
101
102     // javadoc is inherited
103
public String JavaDoc toString() {
104         StringBuffer JavaDoc sb = new StringBuffer JavaDoc("BasicFieldConstraint(inverse:").
105         append(isInverse()).
106         append("field:").append(getFieldName()).
107         append(", casesensitive:").append(isCaseSensitive()).
108         append(")");
109         return sb.toString();
110     }
111
112 }
113
Popular Tags