Java Object Statistic Value

Problem this snippet solves:

This Java class is a helper class for the Java Objects CodeShare entries.

The StatisticValue class provides some assitance with the iControl Common__ULong64 class.

Code :

package iControl.Objects;

public class StatisticValue extends iControl.CommonULong64
{
  static final long serialVersionUID = 1;
  
  public StatisticValue()
  {
  }
  
  public StatisticValue(iControl.CommonULong64 val)
  {
    setHigh(val.getHigh());
    setLow(val.getLow());
  }
  
  public StatisticValue(long high, long low)
  {
    setHigh(high);
    setLow(low);
  }
  
  public Double doubleValue()
  {
    long high = getHigh();
    long low = getLow();
    
    Double dVal = 0.0;
    Double rollOver = new Double((double)0x7fffffff);
    rollOver = new Double(rollOver.doubleValue() + 1.0);
    if ( high >= 0 )
    {
      dVal = new Double((high << 32) & 0xffff0000);
    }
    else
    {
      dVal = new Double((high & 0x7fffffff) << 32) + (0x80000000 << 32);
    }
    if ( low >= 0 )
    {
      dVal = new Double(dVal.doubleValue() + (double)low);
    }
    else
    {
      dVal = new Double(dVal.doubleValue() + (double)(low & 0x7fffffff) + rollOver.doubleValue());
    }
    return dVal;
  }
  
  public String toString()
  {
    String dString = null;
    String size = "";
    Double value = this.doubleValue();
    Double dVal = value.doubleValue();
    if ((dVal / 1024) >= 1.0)
    {
      size = "K";
      dVal = dVal / 1024;
    }
    if ((dVal / 1024) >= 1.0)
    {
      size = "M";
      dVal = dVal / 1024;
    }
    if ((dVal / 1024) >= 1.0)
    {
      size = "G";
      dVal = dVal / 1024;
    }
    
    dString = new Double(dVal).toString();
    dString = dString.substring(0, dString.indexOf(".") + 2) + size;
    return dString;
  }
}
Published Mar 08, 2015
Version 1.0
No CommentsBe the first to comment