Class DoubleScalar<U extends Unit<U>,S extends DoubleScalar<U,S>>
java.lang.Object
java.lang.Number
org.djunits.value.base.Scalar<U,S>
org.djunits.value.vdouble.scalar.base.DoubleScalar<U,S>
- Type Parameters:
U
- the unitS
- the type
- All Implemented Interfaces:
Serializable
,Cloneable
,Comparable<S>
,Value<U,
S>
- Direct Known Subclasses:
DoubleScalarAbs
,DoubleScalarRel
public abstract class DoubleScalar<U extends Unit<U>,S extends DoubleScalar<U,S>>
extends Scalar<U,S>
The most basic abstract class for the DoubleScalar.
Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See DJUNITS License.
- Author:
- Alexander Verbraeck, Peter Knoppers
- See Also:
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal int
static SIScalar
divide
(DoubleScalarRel<?, ?> left, DoubleScalarRel<?, ?> right) Divide two values; the result is a new instance with a different (existing or generated) SI unit.double
final boolean
Test if this DoubleScalar is equal to another DoubleScalar.final boolean
eq0()
Test if this DoubleScalar is equal to 0.0.boolean
float
final boolean
Test if this DoubleScalar is greater than or equal to another DoubleScalar.final boolean
ge0()
Test if this DoubleScalar is greater than or equal to 0.0.final double
Retrieve the value in the original unit.final double
Retrieve the value converted into some specified unit.final double
getSI()
Retrieve the value in the underlying SI unit.final boolean
Test if this DoubleScalar is greater than another DoubleScalar.final boolean
gt0()
Test if this DoubleScalar is greater than 0.0.int
hashCode()
static <U extends Unit<U>,
S extends DoubleScalar<U, S>>
Sinstantiate
(double value, U unit) Instantiate the DoubleScalar based on its unit.static <S extends DoubleScalar<?,
S>>
SinstantiateAnonymous
(double value, Unit<?> unit) Instantiate the DoubleScalar based on its unit.static <U extends Unit<U>,
S extends DoubleScalar<U, S>>
SinstantiateSI
(double valueSI, U displayUnit) Instantiate the DoubleScalar with an SI value and add the displayUnit later.static <AU extends AbsoluteLinearUnit<AU,
RU>, RU extends Unit<RU>, R extends DoubleScalarRelWithAbs<AU, A, RU, R>, A extends DoubleScalarAbs<AU, A, RU, R>>
Ainterpolate
(A zero, A one, double ratio) Interpolate between two values.static <U extends Unit<U>,
R extends DoubleScalarRel<U, R>>
Rinterpolate
(R zero, R one, double ratio) Interpolate between two values.int
intValue()
final boolean
Test if this DoubleScalar is less than or equal to another DoubleScalar.final boolean
le0()
Test if this DoubleScalar is less than or equal to 0.0.long
final boolean
Test if this DoubleScalar is less than another DoubleScalar.final boolean
lt0()
Test if this DoubleScalar is less than 0.0.static <U extends Unit<U>,
T extends DoubleScalar<U, T>>
Tmax
(T r1, T r2) Return the maximum value of two relative scalars.static <U extends Unit<U>,
T extends DoubleScalar<U, T>>
Tmax
(T r1, T r2, T... rn) Return the maximum value of more than two relative scalars.static <U extends Unit<U>,
T extends DoubleScalar<U, T>>
Tmin
(T r1, T r2) Return the minimum value of two relative scalars.static <U extends Unit<U>,
T extends DoubleScalar<U, T>>
Tmin
(T r1, T r2, T... rn) Return the minimum value of more than two relative scalars.static <AU extends AbsoluteLinearUnit<AU,
RU>, RU extends Unit<RU>, R extends DoubleScalarRelWithAbs<AU, A, RU, R>, A extends DoubleScalarAbs<AU, A, RU, R>>
Rminus
(A left, A right) Subtract two absolute values.static <AU extends AbsoluteLinearUnit<AU,
RU>, RU extends Unit<RU>, R extends DoubleScalarRelWithAbs<AU, A, RU, R>, A extends DoubleScalarAbs<AU, A, RU, R>>
Aminus
(A left, R right) Subtract a Relative value from an absolute value.static <U extends Unit<U>,
R extends DoubleScalarRel<U, R>>
Rminus
(R left, R right) Subtract a relative value from a relative value.static SIScalar
multiply
(DoubleScalarRel<?, ?> left, DoubleScalarRel<?, ?> right) Multiply two values; the result is a new instance with a different (existing or generated) SI unit.final boolean
Test if this DoubleScalar is not equal to another DoubleScalar.final boolean
ne0()
Test if this DoubleScalar is not equal to 0.0.static <AU extends AbsoluteLinearUnit<AU,
RU>, RU extends Unit<RU>, R extends DoubleScalarRelWithAbs<AU, A, RU, R>, A extends DoubleScalarAbs<AU, A, RU, R>>
Aplus
(A left, R right) Add a Relative value to an Absolute value.static <AU extends AbsoluteLinearUnit<AU,
RU>, RU extends Unit<RU>, R extends DoubleScalarRelWithAbs<AU, A, RU, R>, A extends DoubleScalarAbs<AU, A, RU, R>>
Aplus
(R left, A right) Add an Absolute value to a Relative value.static <U extends Unit<U>,
R extends DoubleScalarRel<U, R>>
Rplus
(R left, R right) Add a Relative value to a Relative value.Concise display description of this value, without the engineering formatting, so without trailing zeroes.toDisplayString
(U displayUnit) Concise display description of this value, without the engineering formatting, so without trailing zeroes.toString()
Concise description of this value.toString
(boolean verbose, boolean withUnit) Somewhat verbose description of this value with optional type and unit information.Somewhat verbose description of this value with the values expressed in the specified unit.Somewhat verbose description of this value with the values expressed in the specified unit.Format this DoubleScalar in SI unit using prefixes when possible.toStringSIPrefixed
(int smallestPower, int biggestPower) Format this DoubleScalar in SI unit using prefixes when possible and within the specified size range.Concise textual representation of this value, without the engineering formatting, so without trailing zeroes.toTextualString
(U displayUnit) Concise textual representation of this value, without the engineering formatting, so without trailing zeroes.Methods inherited from class org.djunits.value.base.Scalar
format, format, getDisplayUnit, setDisplayUnit
Methods inherited from class java.lang.Number
byteValue, shortValue
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.djunits.value.Value
abs, ceil, floor, isAbsolute, isRelative, neg, rint
-
Field Details
-
si
public final double siThe value, stored in the standard SI unit.
-
-
Constructor Details
-
DoubleScalar
Construct a new DoubleScalar.- Parameters:
unit
- U; the unitsi
- double; the si value to store
-
-
Method Details
-
getSI
public final double getSI()Retrieve the value in the underlying SI unit.- Returns:
- double
-
getInUnit
public final double getInUnit()Retrieve the value in the original unit.- Returns:
- double
-
getInUnit
Retrieve the value converted into some specified unit.- Parameters:
targetUnit
- U; the unit to convert the value into- Returns:
- double
-
lt
Description copied from class:Scalar
Test if this DoubleScalar is less than another DoubleScalar. -
le
Description copied from class:Scalar
Test if this DoubleScalar is less than or equal to another DoubleScalar. -
gt
Description copied from class:Scalar
Test if this DoubleScalar is greater than another DoubleScalar. -
ge
Description copied from class:Scalar
Test if this DoubleScalar is greater than or equal to another DoubleScalar. -
eq
Description copied from class:Scalar
Test if this DoubleScalar is equal to another DoubleScalar. -
ne
Description copied from class:Scalar
Test if this DoubleScalar is not equal to another DoubleScalar. -
lt0
public final boolean lt0()Description copied from class:Scalar
Test if this DoubleScalar is less than 0.0. -
le0
public final boolean le0()Description copied from class:Scalar
Test if this DoubleScalar is less than or equal to 0.0. -
gt0
public final boolean gt0()Description copied from class:Scalar
Test if this DoubleScalar is greater than 0.0. -
ge0
public final boolean ge0()Description copied from class:Scalar
Test if this DoubleScalar is greater than or equal to 0.0. -
eq0
public final boolean eq0()Description copied from class:Scalar
Test if this DoubleScalar is equal to 0.0. -
ne0
public final boolean ne0()Description copied from class:Scalar
Test if this DoubleScalar is not equal to 0.0. -
compareTo
-
intValue
public int intValue() -
longValue
public long longValue() -
floatValue
public float floatValue()- Specified by:
floatValue
in classNumber
-
doubleValue
public double doubleValue()- Specified by:
doubleValue
in classNumber
-
toString
Description copied from interface:Value
Concise description of this value. -
toString
Description copied from interface:Value
Somewhat verbose description of this value with the values expressed in the specified unit.- Parameters:
displayUnit
- U; the unit into which the values are converted for display- Returns:
- String; printable string with the value contents expressed in the specified unit
-
toString
Description copied from interface:Value
Somewhat verbose description of this value with optional type and unit information.- Parameters:
verbose
- boolean; if true; include type info; if false; exclude type infowithUnit
- boolean; if true; include the unit; of false; exclude the unit- Returns:
- String; printable string with the value contents
-
toString
Description copied from interface:Value
Somewhat verbose description of this value with the values expressed in the specified unit.- Parameters:
displayUnit
- U; the unit into which the values are converted for displayverbose
- boolean; if true; include type info; if false; exclude type infowithUnit
- boolean; if true; include the unit; of false; exclude the unit- Returns:
- String; printable string with the value contents
-
toStringSIPrefixed
Format this DoubleScalar in SI unit using prefixes when possible. If the value is too small or too large, e-notation and the plain SI unit are used.- Returns:
- String; formatted value of this DoubleScalar
-
toStringSIPrefixed
Format this DoubleScalar in SI unit using prefixes when possible and within the specified size range. If the value is too small or too large, e-notation and the plain SI unit are used.- Parameters:
smallestPower
- int; the smallest exponent value that will be written using an SI prefixbiggestPower
- int; the largest exponent value that will be written using an SI prefix- Returns:
- String; formatted value of this DoubleScalar
-
toTextualString
Description copied from class:Scalar
Concise textual representation of this value, without the engineering formatting, so without trailing zeroes. A space is added between the number and the unit.- Specified by:
toTextualString
in classScalar<U extends Unit<U>,
S extends DoubleScalar<U, S>> - Returns:
- a String with the value with the default textual representation of the unit attached.
-
toTextualString
Description copied from class:Scalar
Concise textual representation of this value, without the engineering formatting, so without trailing zeroes. A space is added between the number and the unit.- Specified by:
toTextualString
in classScalar<U extends Unit<U>,
S extends DoubleScalar<U, S>> - Parameters:
displayUnit
- U; the display unit for the value- Returns:
- a String with the value with the default textual representation of the provided unit attached.
-
toDisplayString
Description copied from class:Scalar
Concise display description of this value, without the engineering formatting, so without trailing zeroes. A space is added between the number and the unit.- Specified by:
toDisplayString
in classScalar<U extends Unit<U>,
S extends DoubleScalar<U, S>> - Returns:
- a String with the value with the default display representation of the unit attached.
-
toDisplayString
Description copied from class:Scalar
Concise display description of this value, without the engineering formatting, so without trailing zeroes. A space is added between the number and the unit.- Specified by:
toDisplayString
in classScalar<U extends Unit<U>,
S extends DoubleScalar<U, S>> - Parameters:
displayUnit
- U; the display unit for the value- Returns:
- a String with the value with the default display representation of the provided unit attached.
-
hashCode
public int hashCode() -
equals
-
instantiate
Instantiate the DoubleScalar based on its unit. Rigid check on types by the compiler.- Type Parameters:
U
- the unitS
- the return type- Parameters:
value
- double; the valueunit
- U; the unit in which the value is expressed- Returns:
- S; an instantiated DoubleScalar with the value expressed in the unit
-
instantiateSI
public static <U extends Unit<U>,S extends DoubleScalar<U, S instantiateSIS>> (double valueSI, U displayUnit) Instantiate the DoubleScalar with an SI value and add the displayUnit later. Rigid check on types by the compiler.- Type Parameters:
U
- the unitS
- the return type- Parameters:
valueSI
- double; the SIvaluedisplayUnit
- U; the unit in which the value will be displayed- Returns:
- S; an instantiated DoubleScalar with the SI value and the display unit
-
instantiateAnonymous
Instantiate the DoubleScalar based on its unit. Loose check for types on the compiler. This allows the unit to be specified as a Unit<?> type.
Note that it is possible to make mistakes with anonymous units.- Type Parameters:
S
- the return type- Parameters:
value
- double; the valueunit
- Unit<?>; the unit in which the value is expressed- Returns:
- S; an instantiated DoubleScalar with the value expressed in the unit
-
plus
public static <AU extends AbsoluteLinearUnit<AU,RU>, A plusRU extends Unit<RU>, R extends DoubleScalarRelWithAbs<AU, A, RU, R>, A extends DoubleScalarAbs<AU, A, RU, R>> (A left, R right) Add a Relative value to an Absolute value. Return a new instance of the value. The unit of the return value will be the unit of the left argument.- Type Parameters:
AU
- Unit; the absolute unit of the parameters and the resultRU
- Unit; the relative unit of the parameters and the resultR
- the relative typeA
- the corresponding absolute type- Parameters:
left
- A, an absolute typed DoubleScalar; the left argumentright
- R, a relative typed DoubleScalar; the right argument- Returns:
- A; an absolute typed DoubleScalar; the sum of the values as an Absolute value
-
plus
public static <AU extends AbsoluteLinearUnit<AU,RU>, A plusRU extends Unit<RU>, R extends DoubleScalarRelWithAbs<AU, A, RU, R>, A extends DoubleScalarAbs<AU, A, RU, R>> (R left, A right) Add an Absolute value to a Relative value. Return a new instance of the value. The unit of the return value will be the unit of the left argument.- Type Parameters:
AU
- Unit; the absolute unit of the parameters and the resultRU
- Unit; the relative unit of the parameters and the resultR
- the relative typeA
- the corresponding absolute type- Parameters:
left
- A, an absolute typed DoubleScalar; the left argumentright
- R, a relative typed DoubleScalar; the right argument- Returns:
- A; an absolute typed DoubleScalar; the sum of the values as an Absolute value
-
plus
Add a Relative value to a Relative value. Return a new instance of the value. The unit of the return value will be the unit of the left argument.- Type Parameters:
U
- Unit; the unit of the parameters and the resultR
- the relative type- Parameters:
left
- R, a relative typed DoubleScalar; the left argumentright
- R, a relative typed DoubleScalar; the right argument- Returns:
- R; a relative typed DoubleScalar; the sum of the values as a Relative value
-
minus
public static <AU extends AbsoluteLinearUnit<AU,RU>, A minusRU extends Unit<RU>, R extends DoubleScalarRelWithAbs<AU, A, RU, R>, A extends DoubleScalarAbs<AU, A, RU, R>> (A left, R right) Subtract a Relative value from an absolute value. Return a new instance of the value. The unit of the return value will be the unit of the left argument.- Type Parameters:
AU
- Unit; the absolute unit of the parameters and the resultRU
- Unit; the relative unit of the parameters and the resultR
- the relative typeA
- the corresponding absolute type- Parameters:
left
- A, an absolute typed DoubleScalar; the left valueright
- R, a relative typed DoubleScalar; the right value- Returns:
- A; an absolute typed DoubleScalar; the resulting value as an absolute value
-
minus
Subtract a relative value from a relative value. Return a new instance of the value. The unit of the value will be the unit of the first argument.- Type Parameters:
U
- Unit; the unit of the parameters and the resultR
- the relative type- Parameters:
left
- R, a relative typed DoubleScalar; the left valueright
- R, a relative typed DoubleScalar; the right value- Returns:
- R; a relative typed DoubleScalar; the resulting value as a relative value
-
minus
public static <AU extends AbsoluteLinearUnit<AU,RU>, R minusRU extends Unit<RU>, R extends DoubleScalarRelWithAbs<AU, A, RU, R>, A extends DoubleScalarAbs<AU, A, RU, R>> (A left, A right) Subtract two absolute values. Return a new instance of a relative value of the difference. The unit of the value will be the unit of the first argument.- Type Parameters:
AU
- Unit; the absolute unit of the parameters and the resultRU
- Unit; the relative unit of the parameters and the resultR
- the relative typeA
- the corresponding absolute type- Parameters:
left
- A, an absolute typed DoubleScalar; value 1right
- A, an absolute typed DoubleScalar; value 2- Returns:
- R; a relative typed DoubleScalar; the difference of the two absolute values as a relative value
-
multiply
Multiply two values; the result is a new instance with a different (existing or generated) SI unit.- Parameters:
left
- DoubleScalarRel<?, ?>; the left operandright
- DoubleScalarRel<?, ?>; the right operand- Returns:
- DoubleScalarRel<SIUnit>; the product of the two values
-
divide
Divide two values; the result is a new instance with a different (existing or generated) SI unit.- Parameters:
left
- DoubleScalarRel<?, ?>; the left operandright
- DoubleScalarRel<?, ?>; the right operand- Returns:
- DoubleScalarRel<SIUnit>; the ratio of the two values
-
interpolate
public static <U extends Unit<U>,R extends DoubleScalarRel<U, R interpolateR>> (R zero, R one, double ratio) Interpolate between two values. Made to be able to call e.g., Area a = DoubleScalar.interpolate(a1, a2, 0.4);- Type Parameters:
U
- Unit; the unit of the parameters and the resultR
- the relative type- Parameters:
zero
- R; the low valueone
- R; the high valueratio
- double; the ratio between 0 and 1, inclusive- Returns:
- R; an Absolute Scalar at the
ratio
betweenzero
andone
-
interpolate
public static <AU extends AbsoluteLinearUnit<AU,RU>, A interpolateRU extends Unit<RU>, R extends DoubleScalarRelWithAbs<AU, A, RU, R>, A extends DoubleScalarAbs<AU, A, RU, R>> (A zero, A one, double ratio) Interpolate between two values. Made to be able to call e.g., Time t = DoubleScalar.interpolate(t1, t2, 0.4);- Type Parameters:
AU
- Unit; the absolute unit of the parameters and the resultRU
- Unit; the relative unit of the parameters and the resultR
- the relative typeA
- the corresponding absolute type- Parameters:
zero
- A; the low valueone
- A; the high valueratio
- double; the ratio between 0 and 1, inclusive- Returns:
- R; a Relative Scalar at the
ratio
betweenzero
andone
-
max
Return the maximum value of two relative scalars.- Type Parameters:
U
- Unit; the unit of the parameters and the resultT
- the argument and result type- Parameters:
r1
- T; the first scalarr2
- T; the second scalar- Returns:
- T; the maximum value of two relative scalars
-
max
@SafeVarargs public static <U extends Unit<U>,T extends DoubleScalar<U, T maxT>> (T r1, T r2, T... rn) Return the maximum value of more than two relative scalars.- Type Parameters:
U
- Unit; the unit of the parameters and the resultT
- the argument and result type- Parameters:
r1
- T; the first scalarr2
- T; the second scalarrn
- T...; the other scalars- Returns:
- T; the maximum value of more than two relative scalars
-
min
Return the minimum value of two relative scalars.- Type Parameters:
U
- Unit; the unit of the parameters and the resultT
- the argument and result type- Parameters:
r1
- T; the first scalarr2
- T; the second scalar- Returns:
- T; the minimum value of two relative scalars
-
min
@SafeVarargs public static <U extends Unit<U>,T extends DoubleScalar<U, T minT>> (T r1, T r2, T... rn) Return the minimum value of more than two relative scalars.- Type Parameters:
U
- Unit; the unit of the parameters and the resultT
- the argument and result type- Parameters:
r1
- T; the first scalarr2
- T; the second scalarrn
- T...; the other scalars- Returns:
- T; the minimum value of more than two relative scalars
-