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 java.util.*;
13: import org.mmbase.storage.search.*;
14:
15: /**
16: * Basic implementation.
17: *
18: * @author Rob van Maris
19: * @version $Id: BasicFieldValueInConstraint.java,v 1.15 2007/02/11 19:21:12 nklasens Exp $
20: * @since MMBase-1.7
21: */
22: public class BasicFieldValueInConstraint extends BasicFieldConstraint
23: implements FieldValueInConstraint {
24:
25: /** The values. */
26: private SortedSet<Object> values = new TreeSet<Object>();
27:
28: /**
29: * Constructor.
30: *
31: * @param field The associated field.
32: */
33: public BasicFieldValueInConstraint(StepField field) {
34: super (field);
35: }
36:
37: /**
38: * Adds value.
39: *
40: * @param value The value.
41: * @return This <code>BasicFieldValueInConstraint</code> instance.
42: * @throws IllegalArgumentException when an invalid argument is supplied.
43: * @see org.mmbase.storage.search.FieldValueInConstraint#getValues
44: */
45: public BasicFieldValueInConstraint addValue(Object value) {
46: BasicStepField.testValue(value, getField());
47: values.add(value);
48: return this ;
49: }
50:
51: // javadoc is inherited
52: public SortedSet<Object> getValues() {
53: return Collections.unmodifiableSortedSet(values);
54: }
55:
56: // javadoc is inherited
57: public boolean equals(Object obj) {
58: if (obj == this ) {
59: return true;
60: }
61: // Must be same class (subclasses should override this)!
62: if (obj != null && obj.getClass() == getClass()) {
63: BasicFieldValueInConstraint constraint = (BasicFieldValueInConstraint) obj;
64: return isInverse() == constraint.isInverse()
65: && isCaseSensitive() == constraint
66: .isCaseSensitive()
67: && getField().getFieldName().equals(
68: constraint.getField().getFieldName())
69: && BasicStepField.compareSteps(
70: getField().getStep(), constraint.getField()
71: .getStep())
72: && values.equals(constraint.values);
73: } else {
74: return false;
75: }
76: }
77:
78: // javadoc is inherited
79: public int hashCode() {
80: return super .hashCode() + 89 * values.hashCode();
81: }
82:
83: // javadoc is inherited
84: public String toString() {
85: StringBuilder sb = new StringBuilder(
86: "FieldValueInConstraint(inverse:").append(isInverse())
87: .append(", field:").append(getFieldName()).append(
88: ", casesensitive:").append(isCaseSensitive())
89: .append(", values:").append(getValues()).append(")");
90: return sb.toString();
91: }
92:
93: }
|