Holger's
Java API

com.antelmann.math
Class BaseUnit

java.lang.Object
  extended by com.antelmann.math.DefaultUnit
      extended by com.antelmann.math.BaseUnit
All Implemented Interfaces:
Unit, Localizable, Serializable
Direct Known Subclasses:
LengthUnit, Temperature, Weight

public class BaseUnit
extends DefaultUnit

base class for providing unit implementations that facilitate conversions based on a standard unit

Since:
09.10.2014, 00:17:37
Author:
holger
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface com.antelmann.util.Localizable
Localizable.Adapter
 
Field Summary
static UnitConverter CONVERTER
          supports BaseUnits provided they have the same base unit.
 
Fields inherited from class com.antelmann.math.DefaultUnit
name, symbol
 
Constructor Summary
BaseUnit(String symbol, String name, Unit base, Converter<Number,Number> thisToBaseConverter)
          constructs a unit that allows conversions to other units based on the same base unit
BaseUnit(String symbol, String name, Unit base, Number factor)
           
 
Method Summary
 Measurable convert(Measurable m)
          uses the converter
static Number convert(Number n, BaseUnit source, BaseUnit target)
           
 Number fromBaseUnit(Number n)
          converts the given number from the base unit to this unit
 Unit getBase()
           
 Measurable toBaseUnit(Measurable m)
          uses the converter
 Number toBaseUnit(Number n)
          converts the given number from this unit to the base unit
 
Methods inherited from class com.antelmann.math.DefaultUnit
equals, getLocale, getUnitName, getUnitSymbol, hashCode, setLocale, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

CONVERTER

public static final UnitConverter CONVERTER
supports BaseUnits provided they have the same base unit. This converter relies on the two conversion methods of the BaseUnit.

See Also:
fromBaseUnit(Number), toBaseUnit(Number)
Constructor Detail

BaseUnit

public BaseUnit(String symbol,
                String name,
                Unit base,
                Number factor)
Parameters:
factor - the factor you have to multiply with to convert to the base unit
See Also:
BaseUnit(String, String, Unit, Converter)

BaseUnit

public BaseUnit(String symbol,
                String name,
                Unit base,
                Converter<Number,Number> thisToBaseConverter)
constructs a unit that allows conversions to other units based on the same base unit

Parameters:
symbol - the symbol of the unit
name - the name of the unit
base - the base unit that is the standard for this kind of unit
thisToBaseConverter - a converter that allows to convert numbers to the base unit and back
Method Detail

getBase

public Unit getBase()

toBaseUnit

public Number toBaseUnit(Number n)
converts the given number from this unit to the base unit


fromBaseUnit

public Number fromBaseUnit(Number n)
converts the given number from the base unit to this unit


convert

public Measurable convert(Measurable m)
                   throws IllegalArgumentException
uses the converter

Throws:
IllegalArgumentException

toBaseUnit

public Measurable toBaseUnit(Measurable m)
                      throws IllegalArgumentException
uses the converter

Throws:
IllegalArgumentException

convert

public static Number convert(Number n,
                             BaseUnit source,
                             BaseUnit target)


(c) Holger Antelmann since 2001- all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads