Package info.monitorenter.util.units
Class AUnit
- java.lang.Object
-
- info.monitorenter.util.units.AUnit
-
- All Implemented Interfaces:
java.io.Serializable
- Direct Known Subclasses:
UnitFemto,UnitGiga,UnitKilo,UnitMega,UnitMicro,UnitMilli,UnitNano,UnitPeta,UnitPico,UnitTera,UnitUnchanged
public abstract class AUnit extends java.lang.Object implements java.io.SerializableA unit.- Version:
- $Revision: 1.10 $
- Author:
- Achim Westermann
- See Also:
UnitFactory,IUnitSystem,UnitSystemSI, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected intm_decimalsDecimals for rounding.protected doublem_factorThe factor a result ofgetValue(double)had to be multiplied with if the real (unitless) value has to be calculated.protected AUnitm_nexLowerUnitThe next smaller unit to this one within this unit'sIUnitSystem.protected AUnitm_nextHigherUnitThe next greater unit to this one within this unit'sIUnitSystem.protected java.lang.Stringm_unitNameThe short unit name of this unit a result ofgetValue(double)has to be related with to know the this result is displayed in a unit.
-
Constructor Summary
Constructors Modifier Constructor Description protectedAUnit()Protected constructor to ensure package access only.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(java.lang.Object obj)intgetDecimals()Returns the number of decimals that should be be taken into account if the methodgetValue(double)is invoked (rounding).doublegetFactor()Returns the factor a result ofgetValue(double)had to be multiplied with if the real (unitless) value has to be calculated.java.lang.StringgetLabel(double value)Returns the the value divided by this unit's factor, rounded to this unit's configured decimals and suffixed by the unit name.AUnitgetNexLowerUnit()Returns the next smaller unit to this one within this unit'sIUnitSystem.AUnitgetNextHigherUnit()Returns the next greater unit to this one within this unit'sIUnitSystem.java.lang.StringgetUnitName()Retunrns the short unit name of this unit a result ofgetValue(double)has to be related with to know the this result is displayed in a unit.doublegetValue(double value)Transforms the given absolute value into the represented unit value by dividing by the specific factor.inthashCode()voidsetDecimals(int aftercomma)Define how many decimals should be taken into account if the methodgetValue(double)is invoked (rounding).java.lang.StringtoString()Returns the same asgetUnitName(), prefer calling this directly if desired.
-
-
-
Field Detail
-
m_decimals
protected int m_decimals
Decimals for rounding.
-
m_factor
protected double m_factor
The factor a result ofgetValue(double)had to be multiplied with if the real (unitless) value has to be calculated.
-
m_nexLowerUnit
protected AUnit m_nexLowerUnit
The next smaller unit to this one within this unit'sIUnitSystem.
-
m_nextHigherUnit
protected AUnit m_nextHigherUnit
The next greater unit to this one within this unit'sIUnitSystem.
-
m_unitName
protected java.lang.String m_unitName
The short unit name of this unit a result ofgetValue(double)has to be related with to know the this result is displayed in a unit.
-
-
Constructor Detail
-
AUnit
protected AUnit()
Protected constructor to ensure package access only.Use
UnitFactory.getInstance()andUnitFactory.getUnit(double, IUnitSystem)to obtain a proper unit.
-
-
Method Detail
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object- See Also:
Object.hashCode()
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object- See Also:
Object.equals(java.lang.Object)
-
getDecimals
public int getDecimals()
Returns the number of decimals that should be be taken into account if the methodgetValue(double)is invoked (rounding).- Returns:
- the number of decimals that should be be taken into account if the
method
getValue(double)is invoked (rounding).
-
getFactor
public double getFactor()
Returns the factor a result ofgetValue(double)had to be multiplied with if the real (unitless) value has to be calculated.For performance reason (fast access) factor is public. This is against "safety by desing" so do never set this value.
- Returns:
- the factor a result of
getValue(double)had to be multiplied with if the real (unitless) value has to be calculated.
-
getLabel
public java.lang.String getLabel(double value)
Returns the the value divided by this unit's factor, rounded to this unit's configured decimals and suffixed by the unit name.- Parameters:
value- the value for the label.- Returns:
- the the value divided by this unit's factor, rounded by this unit's configured decimals and suffixed by the unit name.
- See Also:
getUnitName(),getDecimals()
-
getNexLowerUnit
public AUnit getNexLowerUnit()
Returns the next smaller unit to this one within this unit'sIUnitSystem.If this is already the smallest unit, this will be returned so add
unit == unit.getLowerUnit()as the termination criteria in loops to search for the smallest unit (to avoid endless loops).- Returns:
- the next lower unit to this one within this unit's
IUnitSystem.
-
getNextHigherUnit
public AUnit getNextHigherUnit()
Returns the next greater unit to this one within this unit'sIUnitSystem.If this is already the greatest unit, this will be returned so add
unit == unit.getNextHigherUnit()as the termination criteria in loops to search for the greatest unit (to avoid endless loops).- Returns:
- the next greater unit to this one within this unit's
IUnitSystem.
-
getUnitName
public java.lang.String getUnitName()
Retunrns the short unit name of this unit a result ofgetValue(double)has to be related with to know the this result is displayed in a unit.- Returns:
- the short unit name of this unit a result of
getValue(double)has to be related with to know the this result is displayed in a unit.
-
getValue
public double getValue(double value)
Transforms the given absolute value into the represented unit value by dividing by the specific factor.The result is rounded using the actual decimal setting.
- Parameters:
value- the value to represent in this unit.- Returns:
- The value to display in this unit rounded using the internal decimals.
-
setDecimals
public void setDecimals(int aftercomma)
Define how many decimals should be taken into account if the methodgetValue(double)is invoked (rounding).- Parameters:
aftercomma- the number of decimals that should be taken into account if the methodgetValue(double)is invoked (rounding)
-
toString
public java.lang.String toString()
Returns the same asgetUnitName(), prefer calling this directly if desired.- Overrides:
toStringin classjava.lang.Object- Returns:
- the same as
getUnitName(), prefer calling this directly if desired.
-
-