net.sf.doolin.util.unit
Class ValueUnit

java.lang.Object
  extended by net.sf.doolin.util.unit.ValueUnit

public class ValueUnit
extends Object

Numeric value associated with a unit.

Author:
Damien Coraboeuf

Constructor Summary
ValueUnit()
          Constructor with no predefined value or unit.
ValueUnit(Number value, Unit unit)
          Constructor with a predefined value and unit.
 
Method Summary
 ValueUnit convert(Unit targetUnit, Number reference)
          Converts this value to another unit.
 boolean equals(Object obj)
           
 Unit getUnit()
           
 Number getValue()
           
 int hashCode()
           
 void setUnit(Unit unit)
           
 void setValue(Number value)
           
 String toString()
           
static ValueUnit valueOf(String string)
          Converts a formatted string to a numeric value and a unit.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ValueUnit

public ValueUnit()
Constructor with no predefined value or unit.


ValueUnit

public ValueUnit(Number value,
                 Unit unit)
Constructor with a predefined value and unit.

Parameters:
value - Numeric value
unit - Unit
Method Detail

valueOf

public static ValueUnit valueOf(String string)
Converts a formatted string to a numeric value and a unit.

Parameters:
string - Formatted string.
Returns:
Value + unit or null if the string is empty
Throws:
IllegalArgumentException - If the provided string cannot be parsed

convert

public ValueUnit convert(Unit targetUnit,
                         Number reference)
Converts this value to another unit.

Parameters:
targetUnit - Target unit
reference - Reference value for the percentage unit
Returns:
New value

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

getUnit

public Unit getUnit()
Returns:
Associated unit

getValue

public Number getValue()
Returns:
Associated value

hashCode

public int hashCode()
Overrides:
hashCode in class Object

setUnit

public void setUnit(Unit unit)
Parameters:
unit - Associated unit

setValue

public void setValue(Number value)
Parameters:
value - Associated value

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2011. All Rights Reserved.