KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.*;
13 import org.mmbase.module.core.MMObjectBuilder;
14 import org.mmbase.storage.search.*;
15
16 /**
17  * Basic implementation.
18  * The step alias is not set on default.
19  *
20  * @author Rob van Maris
21  * @version $Id: BasicStep.java,v 1.8 2005/10/30 19:08:56 michiel Exp $
22  * @since MMBase-1.7
23  */

24 public class BasicStep implements Step {
25
26     /** Associated builder. */
27     protected MMObjectBuilder builder = null;
28     /** Alias property. */
29     protected String JavaDoc alias = null;
30     /**
31      * Nodenumber set for nodes to be included (ordered
32      * using integer comparison).
33      */

34     protected SortedSet nodes = new TreeSet();
35     /**
36      * Constructor.
37      *
38      * @param builder The builder.
39      * @throws IllegalArgumentException when an invalid argument is supplied.
40      */

41     // package visibility!
42
BasicStep(MMObjectBuilder builder) {
43         if (builder == null) {
44             throw new IllegalArgumentException JavaDoc("Invalid builder value: " + builder);
45         }
46         this.builder = builder;
47     }
48
49     /**
50      * Sets alias property.
51      *
52      * @param alias The alias property.
53      * @return This <code>BasicStep</code> instance.
54      * @throws IllegalArgumentException when an invalid argument is supplied.
55      */

56     public BasicStep setAlias(String JavaDoc alias) {
57         if (alias != null && alias.trim().length() == 0) {
58             throw new IllegalArgumentException JavaDoc(
59             "Invalid alias value: " + alias);
60         }
61         this.alias = alias;
62         return this;
63     }
64
65     /**
66      * Adds node to nodes.
67      *
68      * @param nodeNumber The nodenumber of the node.
69      * @return This <code>BasicStep</code> instance.
70      * @throws IllegalArgumentException when an invalid argument is supplied.
71      */

72     public BasicStep addNode(int nodeNumber) {
73         if (nodeNumber < 0) {
74             throw new IllegalArgumentException JavaDoc("Invalid nodeNumber value: " + nodeNumber);
75         }
76         nodes.add(new Integer JavaDoc(nodeNumber));
77         return this;
78     }
79
80     /**
81      * Gets the associated builder.
82      *
83      * @return The builder.
84      */

85     public MMObjectBuilder getBuilder() {
86         return builder;
87     }
88
89     // javadoc is inherited
90
public String JavaDoc getTableName() {
91         return builder.getTableName();
92     }
93
94     // javadoc is inherited
95
public String JavaDoc getAlias() {
96         return alias;
97     }
98
99     // javadoc is inherited
100
public SortedSet getNodes() {
101         return Collections.unmodifiableSortedSet(nodes);
102     }
103
104     // javadoc is inherited
105
public boolean equals(Object JavaDoc obj) {
106         if (obj == this) {
107             return true;
108         }
109         if (obj instanceof Step && !(obj instanceof RelationStep)) {
110             Step step = (Step) obj;
111             return getTableName().equals(step.getTableName())
112                 && (alias == null ? step.getAlias() == null : alias.equals(step.getAlias()))
113                 && nodes.equals(step.getNodes());
114         } else {
115             return false;
116         }
117     }
118
119     // javadoc is inherited
120
public int hashCode() {
121         return 41 * builder.getTableName().hashCode()
122         + (alias == null? 0: 43 * alias.hashCode()) + 47 * nodes.hashCode();
123     }
124
125     // javadoc is inherited
126
public String JavaDoc toString() {
127         StringBuffer JavaDoc sb = new StringBuffer JavaDoc("Step(tablename:").
128         append(getTableName()).
129         append(", alias:").append(alias).
130         append(", nodes:").append(nodes).
131         append(")");
132         return sb.toString();
133     }
134
135 }
136
Popular Tags