org.apache.commons.monitoring.counters
Class Unit

java.lang.Object
  extended by org.apache.commons.monitoring.counters.Unit
All Implemented Interfaces:
Comparable<Unit>
Direct Known Subclasses:
Unit.Binary, Unit.Time

public class Unit
extends Object
implements Comparable<Unit>

Units allow monitored data to have get typed. A primary unit is the finest unit for a data type. A primary unit can have derived units, that represent the same data type, but with a scale factor. A primary Unit is created with the Unit(String) constructor. A derived Unit is created with the Unit(String, Unit, long) constructor.

A primary Unit maintains a Map of it's derived units. getDerived() can be used to retrieve the complete list, and getDerived(String) to retrieve a derived unit by it's name.

Author:
Nicolas De Loof

Nested Class Summary
static class Unit.Binary
          Binary data units
static class Unit.Time
          Time based units
 
Field Summary
static Unit DECA
           
static Unit GIGA
           
static Unit HECTO
           
static Unit KILO
           
static Unit MEGA
           
 Set<Unit> primaryUnits
           
static Unit TERA
           
static Unit UNARY
          unit for basic item counters & gauges
 
Constructor Summary
Unit(String name)
          Constructor for a primary unit
Unit(String name, Unit derived, long scale)
          Constructor for a derived unit
 
Method Summary
 int compareTo(Unit o)
           
 double convert(double value, Unit unit)
          Convert value from unit to this unit (if conpatible)
 boolean equals(Object obj)
           
static Unit get(String name)
           
 List<Unit> getDerived()
           
 Unit getDerived(String name)
           
 String getName()
           
 Unit getPrimary()
           
 long getScale()
           
 int hashCode()
           
 boolean isCompatible(Unit unit)
           
 boolean isPrimary()
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

UNARY

public static final Unit UNARY
unit for basic item counters & gauges


DECA

public static final Unit DECA

HECTO

public static final Unit HECTO

KILO

public static final Unit KILO

MEGA

public static final Unit MEGA

GIGA

public static final Unit GIGA

TERA

public static final Unit TERA

primaryUnits

public Set<Unit> primaryUnits
Constructor Detail

Unit

public Unit(String name)
Constructor for a primary unit

Parameters:
name -

Unit

public Unit(String name,
            Unit derived,
            long scale)
Constructor for a derived unit

Parameters:
name -
derived - the unit this unit is derived from
scale - the scale factor to convert to derived unit
Method Detail

get

public static Unit get(String name)

getDerived

public Unit getDerived(String name)

getDerived

public List<Unit> getDerived()

getName

public String getName()

getScale

public long getScale()

convert

public double convert(double value,
                      Unit unit)
Convert value from unit to this unit (if conpatible)

Parameters:
value - value to convert
unit - unit of value
Returns:
value converted to this unit

isPrimary

public boolean isPrimary()

isCompatible

public boolean isCompatible(Unit unit)

getPrimary

public Unit getPrimary()

compareTo

public int compareTo(Unit o)
Specified by:
compareTo in interface Comparable<Unit>

toString

public String toString()
Overrides:
toString in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object
See Also:
Object.hashCode()

equals

public boolean equals(Object obj)
Overrides:
equals in class Object
See Also:
Object.equals(java.lang.Object)


Copyright © 2008–2013 The Apache Software Foundation. All rights reserved.