📄 aggregationaverage.java
字号:
/* * @(#)$Id: AggregationAverage.java,v 1.9 2005/04/13 20:17:44 huebsch Exp $ * * Copyright (c) 2001-2004 Regents of the University of California. * All rights reserved. * * This file is distributed under the terms in the attached BERKELEY-LICENSE * file. If you do not find these files, copies can be found by writing to: * Computer Science Division, Database Group, Universite of California, * 617 Soda Hall #1776, Berkeley, CA 94720-1776. Attention: Berkeley License * * Copyright (c) 2003-2004 Intel Corporation. All rights reserved. * * This file is distributed under the terms in the attached INTEL-LICENSE file. * If you do not find these files, copies can be found by writing to: * Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, * Berkeley, CA, 94704. Attention: Intel License Inquiry. */package pier.helpers.aggregation;import pier.data.DataTypes;import services.network.Payload;import util.network.serialization.GenericByteBuffer;import util.network.serialization.SerializationManager;/** * Class AggregationAverage * */public class AggregationAverage implements AggregationOperator { public static long serialVersionUID = SerializationManager.getSerialUID( "pier.helpers.aggregation.AggregationAverage"); private long count; private Object sum; /** * DeSerialize the object from the provided GenericByteBuffer. * * @param inputBuffer */ /** * Constructor AggregationAverage * * @param inputBuffer */ public AggregationAverage(GenericByteBuffer inputBuffer) { this.count = inputBuffer.getLong(); this.sum = SerializationManager.deSerializeExtended(inputBuffer); } /** * Serialize the object into the provided GenericByteBuffer. * * @param outputBuffer * @return */ /** * Method serialize * * @param outputBuffer * @return */ public long serialize( util.network.serialization.GenericByteBuffer outputBuffer) { outputBuffer.putLong(count); SerializationManager.serializeExtended(outputBuffer, sum); return serialVersionUID; } /** * Constructor AggregationAverage */ public AggregationAverage() { count = 0; sum = null; } /** * Method addBaseValue * * @param data * @return */ public boolean addBaseValue(Object data) { count++; if (sum == null) { sum = DataTypes.getClone(data); } else { sum = DataTypes.add(sum, data); } return true; } /** * Method addPartialResult * * @param data * @return */ public boolean addPartialResult(AggregationOperator data) { count += ((AggregationAverage) data).count; if (sum == null) { sum = ((AggregationAverage) data).sum; } else { sum = DataTypes.add(sum, ((AggregationAverage) data).sum); } return true; } /** * Method result * @return */ public Object result() { if (count > 0) { return DataTypes.divide(sum, count); } else { return null; } } /** * Method getSize * @return */ public int getSize() { return Payload.LONG_SIZE + DataTypes.getSize(sum); } /** * Method hashCode * @return */ public int hashCode() { return sum.hashCode(); } /** * Method equals * * @param other * @return */ public boolean equals(Object other) { return ((sum.equals(((AggregationAverage) other).sum)) && (count == ((AggregationAverage) other).count)); } /** * Method compareTo * * @param o * @return */ public int compareTo(Object o) { return DataTypes.compareTo(sum, ((AggregationAverage) o).sum); } /** * Method getClone * @return */ public Object getClone() { AggregationAverage newObject = new AggregationAverage(); newObject.sum = DataTypes.getClone(sum); newObject.count = count; return newObject; } /** * Method add * * @param other * @return */ public Object add(Object other) { throw new RuntimeException( "DataTypes: Unsupported data type for adding: " + this.getClass() + " and " + other.getClass()); } /** * Method divide * * @param denominator * @return */ public Object divide(long denominator) { throw new RuntimeException( "DataTypes: Unsupported data type for division: " + this.getClass()); } /** * Method toString * @return */ public String toString() { return new String("AGG-AVG:" + sum + "/" + count); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -