Top Description Fields Constructors Methods
tech.units.indriya.quantity

public Class DefaultQuantityFactory<Q extends Quantity<Q>>

extends Object
implements QuantityFactory<Q extends Quantity<Q>>
Class Inheritance
All Implemented Interfaces
javax.measure.spi.QuantityFactory
Type Parameters
<Q>
The type of the quantity.
Static Imports
tech.units.indriya.unit.Units.AMPERE, .Units.BECQUEREL, .Units.CANDELA, .Units.COULOMB, .Units.CUBIC_METRE, .Units.FARAD, .Units.GRAY, .Units.HENRY, .Units.HERTZ, .Units.JOULE, .Units.KATAL, .Units.KELVIN, .Units.KILOGRAM, .Units.LUMEN, .Units.LUX, .Units.METRE, .Units.METRE_PER_SECOND, .Units.METRE_PER_SQUARE_SECOND, .Units.MOLE, .Units.NEWTON, .Units.OHM, .Units.PASCAL, .Units.RADIAN, .Units.SECOND, .Units.SIEMENS, .Units.SIEVERT, .Units.SQUARE_METRE, .Units.STERADIAN, .Units.TESLA, .Units.VOLT, .Units.WATT, .Units.WEBER

A factory producing simple quantities instances (tuples Number/ Unit).
For example:
Mass m = DefaultQuantityFactory.getInstance(Mass.class).create(23.0, KILOGRAM); // 23.0 kg
Time m = DefaultQuantityFactory.getInstance(Time.class).create(124, MILLI(SECOND)); // 124 ms
Authors
Martin Desruisseaux, Werner Keil, Jean-Marie Dautelle, Otavio Santana
Since
1.0
Version
1.5, $Date: 2022-05-21 $

Field Summary

Modifier and TypeField and Description
private static final Map<Class<T>, Unit<Q extends Quantity<Q>>>
pack-priv static final java.util.logging.Level
pack-priv static final Map<Class<T>, QuantityFactory<Q extends Quantity<Q>>>
pack-priv static final java.util.logging.Logger
private final Unit<Q>
systemUnit

The system unit for quantities created by this factory.

private final Class<Q>
type

The type of the quantities created by this factory.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public Quantity<Q>
create(Number
the numeric value stated in the specified unit
value
,
Unit<Q>
the unit
unit
)

Implements javax.measure.spi.QuantityFactory.create.

Returns the quantity for the specified number stated in the specified unit.

public Quantity<Q>
create(Number
the numeric value stated in the specified unit
value
,
Unit<Q>
the unit
unit
,
Quantity.Scale
The ABSOLUTE / RELATIVE scale of this quantity
sc
)

Implements javax.measure.spi.QuantityFactory.create.

Returns the quantity for the specified number stated in the specified unit and scale.

private static <Q extends Quantity<Q>> QuantityFactory<Q>
public boolean
equals(Object
the reference object with which to compare.
obj
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public static <
The type of the quantity
Q extends Quantity<Q>
>
QuantityFactory<Q>

Returns:

the quantity factory for the specified type
getInstance
(final Class<Q>
the quantity type
type
)

Returns the default instance for the specified quantity type.

public Unit<Q>
getSystemUnit()

Implements javax.measure.spi.QuantityFactory.getSystemUnit.

Returns the system unit for quantities produced by this factory or null if unknown.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

CLASS_TO_SYSTEM_UNITback to summary
private static final Map<Class<T>, Unit<Q extends Quantity<Q>>> CLASS_TO_SYSTEM_UNIT
Annotations
@SuppressWarnings:rawtypes
DEFAULT_LOG_LEVELback to summary
pack-priv static final java.util.logging.Level DEFAULT_LOG_LEVEL
INSTANCESback to summary
pack-priv static final Map<Class<T>, QuantityFactory<Q extends Quantity<Q>>> INSTANCES
Annotations
@SuppressWarnings:rawtypes
LOGGERback to summary
pack-priv static final java.util.logging.Logger LOGGER
systemUnitback to summary
private final Unit<Q> systemUnit

The system unit for quantities created by this factory.

typeback to summary
private final Class<Q> type

The type of the quantities created by this factory.

Constructor Detail

DefaultQuantityFactoryback to summary
private DefaultQuantityFactory(Class<Q> quantity)
Annotations
@SuppressWarnings:unchecked

Method Detail

createback to summary
public Quantity<Q> create(Number value, Unit<Q> unit)

Implements javax.measure.spi.QuantityFactory.create.

Doc from javax.measure.spi.QuantityFactory.create.

Returns the quantity for the specified number stated in the specified unit.

Parameters
value:Number

the numeric value stated in the specified unit

unit:Unit<Q>

the unit

Returns:Quantity<Q>

the corresponding quantity

createback to summary
public Quantity<Q> create(Number value, Unit<Q> unit, Quantity.Scale sc)

Implements javax.measure.spi.QuantityFactory.create.

Doc from javax.measure.spi.QuantityFactory.create.

Returns the quantity for the specified number stated in the specified unit and scale.

Parameters
value:Number

the numeric value stated in the specified unit

unit:Unit<Q>

the unit

sc:Quantity.Scale

The ABSOLUTE / RELATIVE scale of this quantity

Returns:Quantity<Q>

the corresponding quantity

Annotations
@Override
createNewFactoryInstanceback to summary
private static <Q extends Quantity<Q>> QuantityFactory<Q> createNewFactoryInstance(final Class<Q> type)
equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
obj:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

getInstanceback to summary
public static <Q extends Quantity<Q>> QuantityFactory<Q> getInstance(final Class<Q> type)

Returns the default instance for the specified quantity type.

Parameters
<Q>
The type of the quantity
type:Class<Q>

the quantity type

Returns:QuantityFactory<Q>

the quantity factory for the specified type

Annotations
@SuppressWarnings:unchecked
getSystemUnitback to summary
public Unit<Q> getSystemUnit()

Implements javax.measure.spi.QuantityFactory.getSystemUnit.

Doc from javax.measure.spi.QuantityFactory.getSystemUnit.

Returns the system unit for quantities produced by this factory or null if unknown.

Because the system unit is unique by quantity type, it can be be used to identify the quantity given the unit. For example:

    static boolean isAngularSpeed(Unit<?> unit) {
        return unit.getSystemUnit().equals(RADIAN.divide(SECOND));
    }
    assert isAngularSpeed(REVOLUTION.divide(MINUTE)); // Returns true.
Returns:Unit<Q>

the system unit for this factory.

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object