MtasDataItemLongBasic.java

  1. package mtas.codec.util.collector;

  2. import java.util.Map;
  3. import java.util.Set;
  4. import mtas.codec.util.CodecUtil;

  5. /**
  6.  * The Class MtasDataItemLongBasic.
  7.  */
  8. class MtasDataItemLongBasic extends MtasDataItemBasic<Long, Double> {

  9.   /** The Constant serialVersionUID. */
  10.   private static final long serialVersionUID = 1L;

  11.   /**
  12.    * Instantiates a new mtas data item long basic.
  13.    *
  14.    * @param valueSum the value sum
  15.    * @param valueN the value N
  16.    * @param sub the sub
  17.    * @param statsItems the stats items
  18.    * @param sortType the sort type
  19.    * @param sortDirection the sort direction
  20.    * @param errorNumber the error number
  21.    * @param errorList the error list
  22.    * @param sourceNumber the source number
  23.    */
  24.   public MtasDataItemLongBasic(Long valueSum, long valueN,
  25.       MtasDataCollector<?, ?> sub, Set<String> statsItems, String sortType,
  26.       String sortDirection, int errorNumber, Map<String, Integer> errorList,
  27.       int sourceNumber) {
  28.     super(valueSum, valueN, sub, statsItems, sortType, sortDirection,
  29.         errorNumber, errorList, new MtasDataLongOperations(), sourceNumber);
  30.   }

  31.   /*
  32.    * (non-Javadoc)
  33.    *
  34.    * @see java.lang.Comparable#compareTo(java.lang.Object)
  35.    */
  36.   @SuppressWarnings({ "rawtypes", "unchecked" })
  37.   @Override
  38.   public int compareTo(MtasDataItem<Long, Double> o) {
  39.     int compare = 0;
  40.     if (o instanceof MtasDataItemLongBasic) {
  41.       MtasDataItemLongBasic to = (MtasDataItemLongBasic) o;
  42.       MtasDataItemNumberComparator c1 = getComparableValue();
  43.       MtasDataItemNumberComparator c2 = to.getComparableValue();
  44.       compare = (c1 != null && c2 != null) ? c1.compareTo(c2.getValue()) : 0;
  45.     }
  46.     return sortDirection.equals(CodecUtil.SORT_DESC) ? -1 * compare : compare;
  47.   }

  48.   /*
  49.    * (non-Javadoc)
  50.    *
  51.    * @see mtas.codec.util.collector.MtasDataItem#getCompareValue()
  52.    */
  53.   @Override
  54.   public MtasDataItemNumberComparator<Long> getCompareValue1() {
  55.     switch (sortType) {
  56.     case CodecUtil.STATS_TYPE_N:
  57.       return new MtasDataItemNumberComparator<Long>(valueN, sortDirection);
  58.     case CodecUtil.STATS_TYPE_SUM:
  59.       return new MtasDataItemNumberComparator<Long>(valueSum, sortDirection);
  60.     default:
  61.       return null;
  62.     }
  63.   }

  64.   /*
  65.    * (non-Javadoc)
  66.    *
  67.    * @see mtas.codec.util.collector.MtasDataItem#getCompareValue2()
  68.    */
  69.   @Override
  70.   public MtasDataItemNumberComparator<Double> getCompareValue2() {
  71.     switch (sortType) {
  72.     case CodecUtil.STATS_TYPE_MEAN:
  73.       return new MtasDataItemNumberComparator<Double>(getValue(sortType),
  74.           sortDirection);
  75.     default:
  76.       return null;
  77.     }
  78.   }

  79.   /*
  80.    * (non-Javadoc)
  81.    *
  82.    * @see java.lang.Object#toString()
  83.    */
  84.   public String toString() {
  85.     return this.getClass().getSimpleName() + "[" + valueSum + "," + valueN
  86.         + "]";
  87.   }

  88.   /*
  89.    * (non-Javadoc)
  90.    *
  91.    * @see java.lang.Object#equals(java.lang.Object)
  92.    */
  93.   @Override
  94.   public boolean equals(Object obj) {
  95.     if (this == obj)
  96.       return true;
  97.     if (obj == null)
  98.       return false;
  99.     if (getClass() != obj.getClass())
  100.       return false;
  101.     MtasDataItemLongBasic that = (MtasDataItemLongBasic) obj;
  102.     MtasDataItemNumberComparator<?> c1 = getComparableValue();
  103.     MtasDataItemNumberComparator<?> c2 = that.getComparableValue();
  104.     return (c1 != null && c2 != null && c1.equals(c2));
  105.   }

  106.   /*
  107.    * (non-Javadoc)
  108.    *
  109.    * @see java.lang.Object#hashCode()
  110.    */
  111.   @Override
  112.   public int hashCode() {
  113.     int h = this.getClass().getSimpleName().hashCode();
  114.     h = (h * 7) ^ getComparableValue().hashCode();
  115.     return h;
  116.   }

  117. }