JADE v6.1

com.dautelle.physics
Class Quantity.Factory

java.lang.Object
  extended bycom.dautelle.realtime.ObjectFactory
      extended bycom.dautelle.math.numbers.RealtimeNumber.Factory
          extended bycom.dautelle.physics.Quantity.Factory
Enclosing class:
Quantity

public static class Quantity.Factory
extends RealtimeNumber.Factory

This inner-class represents the ObjectFactory producing Quantity instances.


Field Summary
 
Fields inherited from class com.dautelle.realtime.ObjectFactory
MAX
 
Constructor Summary
protected Quantity.Factory(Unit systemUnit)
          Creates a new factory producing quantities whose nature is identified by the specified system unit.
 
Method Summary
 java.lang.Object create()
          Returns a new quantity product of this factory.
static Quantity.Factory getInstance(Unit unit)
          Returns the Quantity.Factory producing quantities identified by the specified unit.
 Unit getUnit()
          Returns the system unit for the Quantity instances created by this Quantity.Factory.
protected  Quantity newQuantity()
          This method should be overriden by sub-classes to return a new instance allocated on the heap.
 Quantity quantity(Quantity quantity)
          Returns an instance of this factory equivalent to the specified quantity.
 Quantity rangeApprox(double min, double max)
          Returns the quantity corresponding to the specified approximate range.
 Quantity rangeExact(double min, double max)
          Returns the quantity corresponding to the specified exact range.
 void showInstancesAs(Unit outputUnit)
          Shows instances of this factory in the specified output unit (context-local).
 Quantity.Factory useFor(Unit unit)
          Maps the specified unit to this Quantity.Factory.
 
Methods inherited from class com.dautelle.math.numbers.RealtimeNumber.Factory
newPool, object
 
Methods inherited from class com.dautelle.realtime.ObjectFactory
cleanup, currentPool, heapPool
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Quantity.Factory

protected Quantity.Factory(Unit systemUnit)
Creates a new factory producing quantities whose nature is identified by the specified system unit.

Parameters:
systemUnit - the system unit for the quantities produced by this factory.
Throws:
java.lang.IllegalArgumentException - if the specified unit is not a system unit.
java.lang.IllegalArgumentException - if another factory already produces the same quantities.
Method Detail

getInstance

public static Quantity.Factory getInstance(Unit unit)
Returns the Quantity.Factory producing quantities identified by the specified unit.

Parameters:
unit - the unit identifying the factory to return.
Returns:
an existing factory or a new one.

getUnit

public final Unit getUnit()
Returns the system unit for the Quantity instances created by this Quantity.Factory.

Returns:
the system unit for this factory.

useFor

public Quantity.Factory useFor(Unit unit)
Maps the specified unit to this Quantity.Factory. This method allows for additional units to be mapped to this Quantity.Factory. For example:
     Factory.getInstance(Unit.valueOf("1/s")).useFor(SI.HERTZ);
Typically, such additional mapping is the responsibility of the physical models (e.g. StandardModel for the mapping of SI derived units).

Parameters:
unit - the unit being mapped to this Quantity.Factory.
Returns:
this;
Throws:
java.lang.IllegalArgumentException - if this factory's unit and the specified unit are not compatible.

showInstancesAs

public void showInstancesAs(Unit outputUnit)
Shows instances of this factory in the specified output unit (context-local). This method overrides the default output unit specified by the current model.

Parameters:
outputUnit - the output unit for instances of this Quantity.Factory.
See Also:
PhysicalModel.current(), LocalContext

newQuantity

protected Quantity newQuantity()
This method should be overriden by sub-classes to return a new instance allocated on the heap.

Note: This method should never be called directly. Allocation of a new quantity amounting to nothing should be performed using create().

Returns:
a new instance (not initialized).

create

public final java.lang.Object create()
Returns a new quantity product of this factory.

Specified by:
create in class ObjectFactory
Returns:
a new quantity allocated from the heap.

quantity

public final Quantity quantity(Quantity quantity)
Returns an instance of this factory equivalent to the specified quantity.

Parameters:
quantity - the quantity reference.
Returns:
the specified quantity instance or a quantity from this factory equivalent to the specified quantity.
Throws:
ConversionException - if the current model does not allow the specified quantity to be stated in this factory's system unit.

rangeExact

public final Quantity rangeExact(double min,
                                 double max)
Returns the quantity corresponding to the specified exact range.

Parameters:
min - the minimum amount stated in this factory system unit.
max - the maximum amount stated in this factory system unit.
Returns:
the corresponding quantity instance of this factory.

rangeApprox

public final Quantity rangeApprox(double min,
                                  double max)
Returns the quantity corresponding to the specified approximate range.

Parameters:
min - the minimum amount stated in this factory system unit.
max - the maximum amount stated in this factory system unit.
Returns:
the corresponding quantity instance of this factory.

JADE v6.1

Copyright © 2004 Jean-Marie Dautelle.