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 java.util.*;
013: import org.mmbase.module.core.MMObjectBuilder;
014: import org.mmbase.storage.search.*;
015:
016: /**
017: * Basic implementation.
018: * The step alias is not set on default.
019: *
020: * @author Rob van Maris
021: * @version $Id: BasicStep.java,v 1.12 2007/02/11 19:21:12 nklasens Exp $
022: * @since MMBase-1.7
023: */
024: public class BasicStep implements Step {
025:
026: /** Associated builder. */
027: protected MMObjectBuilder builder = null;
028: /** Alias property. */
029: protected String alias = null;
030: /**
031: * Nodenumber set for nodes to be included (ordered
032: * using integer comparison).
033: */
034: protected SortedSet<Integer> nodes = new TreeSet<Integer>();
035:
036: /**
037: * Constructor.
038: *
039: * @param builder The builder.
040: * @throws IllegalArgumentException when an invalid argument is supplied.
041: */
042: // package visibility!
043: BasicStep(MMObjectBuilder builder) {
044: if (builder == null) {
045: throw new IllegalArgumentException(
046: "Invalid builder value: " + builder);
047: }
048: this .builder = builder;
049: }
050:
051: /**
052: * Sets alias property.
053: *
054: * @param alias The alias property.
055: * @return This <code>BasicStep</code> instance.
056: * @throws IllegalArgumentException when an invalid argument is supplied.
057: */
058: public BasicStep setAlias(String alias) {
059: if (alias != null && alias.trim().length() == 0) {
060: throw new IllegalArgumentException("Invalid alias value: "
061: + alias);
062: }
063: this .alias = alias;
064: return this ;
065: }
066:
067: /**
068: * Adds node to nodes.
069: *
070: * @param nodeNumber The nodenumber of the node.
071: * @return This <code>BasicStep</code> instance.
072: * @throws IllegalArgumentException when an invalid argument is supplied.
073: */
074: public Step addNode(int nodeNumber) {
075: if (nodeNumber < 0) {
076: throw new IllegalArgumentException(
077: "Invalid nodeNumber value: " + nodeNumber);
078: }
079: nodes.add(nodeNumber);
080: return this ;
081: }
082:
083: /**
084: * Gets the associated builder.
085: *
086: * @return The builder.
087: */
088: public MMObjectBuilder getBuilder() {
089: return builder;
090: }
091:
092: // javadoc is inherited
093: public String getTableName() {
094: return builder.getTableName();
095: }
096:
097: // javadoc is inherited
098: public String getAlias() {
099: return alias;
100: }
101:
102: // javadoc is inherited
103: public SortedSet<Integer> getNodes() {
104: return Collections.unmodifiableSortedSet(nodes);
105: }
106:
107: // javadoc is inherited
108: public boolean equals(Object obj) {
109: if (obj == this ) {
110: return true;
111: }
112: if (obj instanceof Step && !(obj instanceof RelationStep)) {
113: Step step = (Step) obj;
114: return getTableName().equals(step.getTableName())
115: && (alias == null ? step.getAlias() == null : alias
116: .equals(step.getAlias()))
117: && nodes.equals(step.getNodes());
118: } else {
119: return false;
120: }
121: }
122:
123: // javadoc is inherited
124: public int hashCode() {
125: return 41 * builder.getTableName().hashCode()
126: + (alias == null ? 0 : 43 * alias.hashCode()) + 47
127: * nodes.hashCode();
128: }
129:
130: // javadoc is inherited
131: public String toString() {
132: StringBuilder sb = new StringBuilder("Step(tablename:").append(
133: getTableName()).append(", alias:").append(alias)
134: .append(", nodes:").append(nodes).append(")");
135: return sb.toString();
136: }
137:
138: }
|