1 10 package org.mmbase.storage.search.implementation; 11 12 import org.mmbase.core.CoreField; 13 import org.mmbase.storage.search.*; 14 15 23 public class BasicAggregatedField extends BasicStepField implements AggregatedField { 24 25 26 private int aggregationType = 0; 27 28 36 public BasicAggregatedField(Step step, CoreField fieldDefs, int aggregationType) { 37 super(step, fieldDefs); 38 setAggregationType(aggregationType); 39 } 40 41 48 public BasicAggregatedField setAggregationType(int aggregationType) { 49 if (aggregationType < AggregatedField.AGGREGATION_TYPE_GROUP_BY 50 || aggregationType > AggregatedField.AGGREGATION_TYPE_MAX) { 51 throw new IllegalArgumentException ( 52 "Invalid aggregationType value: " + aggregationType); 53 } 54 this.aggregationType = aggregationType; 55 return this; 56 } 57 58 61 public int getAggregationType() { 62 return aggregationType; 63 } 64 65 68 public String getAggregationTypeDescription() { 69 try { 70 return AggregatedField.AGGREGATION_TYPE_DESCRIPTIONS[aggregationType]; 71 } catch (IndexOutOfBoundsException ioobe) { 72 return null; 73 } 74 } 75 76 public boolean equals(Object 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 public int hashCode() { 91 return super.hashCode() 92 + 149 * aggregationType; 93 } 94 95 public String toString() { 97 StringBuffer sb = new StringBuffer ("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 |