KickJava   Java API By Example, From Geeks To Geeks.

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


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.core.CoreField;
13 import org.mmbase.storage.search.*;
14
15 /**
16  * Basic implementation.
17  * The step alias is equal to the field name, unless it is explicitly set.
18  *
19  * @author Rob van Maris
20  * @version $Id: BasicAggregatedField.java,v 1.8 2005/05/10 22:58:58 michiel Exp $
21  * @since MMBase-1.7
22  */

23 public class BasicAggregatedField extends BasicStepField implements AggregatedField {
24
25     /** he aggregation type. */
26     private int aggregationType = 0;
27
28     /**
29      * Constructor.
30      *
31      * @param step The associated step.
32      * @param fieldDefs The associated fieldDefs.
33      * @param aggregationType The aggregation type.
34      * @throws IllegalArgumentException when an invalid argument is supplied.
35      */

36     public BasicAggregatedField(Step step, CoreField fieldDefs, int aggregationType) {
37         super(step, fieldDefs);
38         setAggregationType(aggregationType);
39     }
40
41     /**
42      * Sets the aggregation type.
43      *
44      * @param aggregationType The aggregation type.
45      * @return This <code>BasicAggregatedField</code> instance.
46      * @throws IllegalArgumentException when an invalid argument is supplied.
47      */

48     public BasicAggregatedField setAggregationType(int aggregationType) {
49         if (aggregationType < AggregatedField.AGGREGATION_TYPE_GROUP_BY
50         || aggregationType > AggregatedField.AGGREGATION_TYPE_MAX) {
51             throw new IllegalArgumentException JavaDoc(
52             "Invalid aggregationType value: " + aggregationType);
53         }
54         this.aggregationType = aggregationType;
55         return this;
56     }
57
58     /**
59      * Gets the aggregation type.
60      */

61     public int getAggregationType() {
62         return aggregationType;
63     }
64
65     /**
66      * Gets the aggregation type.
67      */

68     public String JavaDoc getAggregationTypeDescription() {
69         try {
70             return AggregatedField.AGGREGATION_TYPE_DESCRIPTIONS[aggregationType];
71         } catch (IndexOutOfBoundsException JavaDoc ioobe) {
72             return null;
73         }
74     }
75
76     // javadoc is inherited
77
public boolean equals(Object JavaDoc obj) {
78         if (obj instanceof AggregatedField) {
79             AggregatedField field = (AggregatedField) obj;
80             return BasicStepField.compareSteps(getStep(), field.getStep())
81                 && getFieldName().equals(field.getFieldName())
82                 && (getAlias() == null? true: getAlias().equals(field.getAlias()))
83                 && aggregationType == field.getAggregationType();
84         } else {
85             return false;
86         }
87     }
88
89     // javadoc is inherited
90
public int hashCode() {
91         return super.hashCode()
92         + 149 * aggregationType;
93     }
94
95     // javadoc is inherited
96
public String JavaDoc toString() {
97         StringBuffer JavaDoc sb = new StringBuffer JavaDoc("AggregatedField(step:");
98         if (getStep() == null) {
99             sb.append("null");
100         } else {
101             if (getStep().getAlias() == null) {
102                 sb.append(getStep().getTableName());
103             } else {
104                 sb.append(getStep().getAlias());
105             }
106         }
107         sb.append(", fieldname:").append(getFieldName()).
108         append(", alias:").append(getAlias()).
109         append(", aggregationtype:").append(getAggregationTypeDescription()).
110         append(")");
111         return sb.toString();
112     }
113
114 }
115
Popular Tags