MtasDataItemDoubleBasic.java
package mtas.codec.util.collector;
import java.util.Map;
import java.util.Set;
import mtas.codec.util.CodecUtil;
/**
* The Class MtasDataItemDoubleBasic.
*/
public class MtasDataItemDoubleBasic extends MtasDataItemBasic<Double, Double> {
/** The Constant serialVersionUID. */
private static final long serialVersionUID = 1L;
/**
* Instantiates a new mtas data item double basic.
*
* @param valueSum the value sum
* @param valueN the value N
* @param sub the sub
* @param statsItems the stats items
* @param sortType the sort type
* @param sortDirection the sort direction
* @param errorNumber the error number
* @param errorList the error list
* @param sourceNumber the source number
*/
public MtasDataItemDoubleBasic(Double valueSum, long valueN,
MtasDataCollector<?, ?> sub, Set<String> statsItems, String sortType,
String sortDirection, int errorNumber, Map<String, Integer> errorList,
int sourceNumber) {
super(valueSum, valueN, sub, statsItems, sortType, sortDirection,
errorNumber, errorList, new MtasDataDoubleOperations(), sourceNumber);
}
/*
* (non-Javadoc)
*
* @see java.lang.Comparable#compareTo(java.lang.Object)
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public int compareTo(MtasDataItem<Double, Double> o) {
int compare = 0;
if (o instanceof MtasDataItemDoubleBasic) {
MtasDataItemDoubleBasic to = (MtasDataItemDoubleBasic) o;
MtasDataItemNumberComparator c1 = getComparableValue();
MtasDataItemNumberComparator c2 = to.getComparableValue();
compare = (c1 != null && c2 != null) ? c1.compareTo(c2.getValue()) : 0;
}
return sortDirection.equals(CodecUtil.SORT_DESC) ? -1 * compare : compare;
}
/*
* (non-Javadoc)
*
* @see mtas.codec.util.collector.MtasDataItem#getCompareValue()
*/
@Override
public MtasDataItemNumberComparator<Double> getCompareValue1() {
switch (sortType) {
case CodecUtil.STATS_TYPE_SUM:
return new MtasDataItemNumberComparator<Double>(valueSum, sortDirection);
default:
return null;
}
}
/*
* (non-Javadoc)
*
* @see mtas.codec.util.collector.MtasDataItem#getCompareValue2()
*/
public MtasDataItemNumberComparator<Double> getCompareValue2() {
switch (sortType) {
case CodecUtil.STATS_TYPE_MEAN:
return new MtasDataItemNumberComparator<Double>(getValue(sortType),
sortDirection);
default:
return null;
}
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
public String toString() {
return this.getClass().getSimpleName() + "[" + valueSum + "," + valueN
+ "]";
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
MtasDataItemDoubleBasic that = (MtasDataItemDoubleBasic) obj;
MtasDataItemNumberComparator<?> c1 = getComparableValue();
MtasDataItemNumberComparator<?> c2 = that.getComparableValue();
return (c1 != null && c2 != null && c1.equals(c2));
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
int h = this.getClass().getSimpleName().hashCode();
h = (h * 7) ^ getComparableValue().hashCode();
return h;
}
}