JScience v2.0

Package org.jscience.physics.units

Provides support for programatic unit handling.

See:
          Description

Class Summary
AddConverter This class represents an add converter.
BaseUnit<Q extends Quantity> This class represents the building blocks on top of which all others units are created.
CompoundUnit<Q extends Quantity> This class represents a compound unit.
Converter This class represents a converter of numeric values.
DerivedUnit<Q extends Quantity> This abstract class identifies derived units.
Dimension This class represents an unit dimension.
LogConverter This class represents a logarithmic converter.
MultiplyConverter This class represents a multiply converter.
NonSI This class contains units that are not part of the International System of Units, that is, they are outside the SI, but are important and widely used.
ProductUnit<Q extends Quantity> This class represents a product unit.
ProductUnit.Element Inner product element represents a rational power of a single unit.
SI This class contains SI (Système International d'Unités) base units, and derived units.
Unit<Q extends Quantity> This class represents a unit of physical quantity.
UnitFormat This is the abstract base class for all unit formats.
 

Exception Summary
ConversionException Signals that a problem of some sort has occurred either when creating a converter between two units or during the conversion itself.
 

Package org.jscience.physics.units Description

Provides support for programatic unit handling.

Standart/NonStandard Units

Standard units and prefixes are provided by the SI class (Système International d'Unités) and about 80 non-standard units are available through the NonSI class.

Usage examples:

    
import static org.jscience.physics.units.SI.*;
import static org.jscience.physics.units.NonSI.*;
import static org.jscience.physics.units.Dimension.*;
import org.jscience.physics.quantities.Length;
...    
        System.out.println(KILO(METER).getConverterTo(MILE).convert(10));

        > 6.2137119223733395
        
        System.out.println(VOLT.times(AMPERE));
        
        > V·A
        
        System.out.println(VOLT.times(AMPERE).getBaseUnits());
        
        > m²·kg/s³
        
        System.out.println(WATT.isCompatible(Unit.valueOf("V·A"));
        
        > true

        System.out.println(WATT.getDimension());
        
        > [L]²·[M]/[T]³
        
        
        // Set relativistic context.
        METER.setDimension(TIME, new MultiplyConverter(1 / 299792458.0)); // 1 / c
  
        System.out.println(WATT.getDimension());
        
        > [M]/[T]
        
        // Lenth and Time are convertible.
        System.out.println(INCH.getConverterTo(MICRO(SECOND)).convert(1.0));
        
        > 8.472528018033061E-5

Unit Parameterization

Units are parameterized (<Q extends Quantity>) to enforce compile-time checks of units/quantities consistency, for example:

    Unit<Duration> MINUTE = SECONDS.times(60); // Ok.
    Unit<Duration> MINUTE = METER.times(60); // Compile error.
    
    Unit<Pressure> HECTOPASCAL = HECTO(PASCAL); // Ok.
    Unit<Pressure> HECTOPASCAL = HECTO(NEWTON); // Compile error.
    
    Length x = Quantity.valueOf(2, FOOT);// Ok FOOT instance of Unit<Length>
    Length x = Quantity.valueOf(2, POUND); // Compile error.
    
See also quantities package.

UML Diagram

UML Diagram


JScience v2.0

Copyright © 2005 JScience.