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 org.mmbase.core.CoreField;
013: import org.mmbase.storage.search.*;
014:
015: /**
016: * Basic implementation.
017: * The step alias is equal to the field name, unless it is explicitly set.
018: *
019: * @author Rob van Maris
020: * @version $Id: BasicAggregatedField.java,v 1.9 2006/10/16 12:56:57 pierre Exp $
021: * @since MMBase-1.7
022: */
023: public class BasicAggregatedField extends BasicStepField implements
024: AggregatedField {
025:
026: /** he aggregation type. */
027: private int aggregationType = 0;
028:
029: /**
030: * Constructor.
031: *
032: * @param step The associated step.
033: * @param fieldDefs The associated fieldDefs.
034: * @param aggregationType The aggregation type.
035: * @throws IllegalArgumentException when an invalid argument is supplied.
036: */
037: public BasicAggregatedField(Step step, CoreField fieldDefs,
038: int aggregationType) {
039: super (step, fieldDefs);
040: setAggregationType(aggregationType);
041: }
042:
043: /**
044: * Sets the aggregation type.
045: *
046: * @param aggregationType The aggregation type.
047: * @return This <code>BasicAggregatedField</code> instance.
048: * @throws IllegalArgumentException when an invalid argument is supplied.
049: */
050: public BasicAggregatedField setAggregationType(int aggregationType) {
051: if (aggregationType < AggregatedField.AGGREGATION_TYPE_GROUP_BY
052: || aggregationType > AggregatedField.AGGREGATION_TYPE_MAX) {
053: throw new IllegalArgumentException(
054: "Invalid aggregationType value: " + aggregationType);
055: }
056: this .aggregationType = aggregationType;
057: return this ;
058: }
059:
060: /**
061: * Gets the aggregation type.
062: */
063: public int getAggregationType() {
064: return aggregationType;
065: }
066:
067: /**
068: * Gets the aggregation type.
069: */
070: public String getAggregationTypeDescription() {
071: try {
072: return AggregatedField.AGGREGATION_TYPE_DESCRIPTIONS[aggregationType];
073: } catch (IndexOutOfBoundsException ioobe) {
074: return null;
075: }
076: }
077:
078: // javadoc is inherited
079: public boolean equals(Object obj) {
080: if (obj instanceof AggregatedField) {
081: AggregatedField field = (AggregatedField) obj;
082: return BasicStepField.compareSteps(getStep(), field
083: .getStep())
084: && getFieldName().equals(field.getFieldName())
085: && (getAlias() == null ? true : getAlias().equals(
086: field.getAlias()))
087: && aggregationType == field.getAggregationType();
088: } else {
089: return false;
090: }
091: }
092:
093: // javadoc is inherited
094: public int hashCode() {
095: return super .hashCode() + 149 * aggregationType;
096: }
097:
098: // javadoc is inherited
099: public String toString() {
100: StringBuilder sb = new StringBuilder("AggregatedField(step:");
101: if (getStep() == null) {
102: sb.append("null");
103: } else {
104: if (getStep().getAlias() == null) {
105: sb.append(getStep().getTableName());
106: } else {
107: sb.append(getStep().getAlias());
108: }
109: }
110: sb.append(", fieldname:").append(getFieldName()).append(
111: ", alias:").append(getAlias()).append(
112: ", aggregationtype:").append(
113: getAggregationTypeDescription()).append(")");
114: return sb.toString();
115: }
116:
117: }
|