Class FloatScalar<U extends Unit<U>,S extends FloatScalar<U,S>>
java.lang.Object
java.lang.Number
org.djunits.value.base.Scalar<U,S>
org.djunits.value.vfloat.scalar.base.FloatScalar<U,S>
- Type Parameters:
U
- the unitS
- the type
- All Implemented Interfaces:
Serializable
,Cloneable
,Comparable<S>
,Value<U,
S>
- Direct Known Subclasses:
FloatScalarAbs
,FloatScalarRel
Static methods to create and operate on FloatScalars.
Copyright (c) 2015-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 FloatSIScalar
divide
(FloatScalarRel<?, ?> left, FloatScalarRel<?, ?> 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 float
Retrieve the value in the original unit.final float
Retrieve the value converted into some specified unit.final float
getSI()
Return 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 FloatScalar<U, S>>
Sinstantiate
(float value, U unit) Instantiate the FloatScalar based on its unit.static <S extends FloatScalar<?,
S>>
SinstantiateAnonymous
(float value, Unit<?> unit) Instantiate the FloatScalar based on its unit.static <U extends Unit<U>,
S extends FloatScalar<U, S>>
SinstantiateSI
(float valueSI, U displayUnit) Instantiate the FloatScalar with an SI value and add the displayUnit later.static <AU extends AbsoluteLinearUnit<AU,
RU>, RU extends Unit<RU>, R extends FloatScalarRelWithAbs<AU, A, RU, R>, A extends FloatScalarAbs<AU, A, RU, R>>
Ainterpolate
(A zero, A one, float ratio) Interpolate between two values.static <U extends Unit<U>,
R extends FloatScalarRel<U, R>>
Rinterpolate
(R zero, R one, float 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 FloatScalar<U, T>>
Tmax
(T r1, T r2) Return the maximum value of two relative scalars.static <U extends Unit<U>,
T extends FloatScalar<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 FloatScalar<U, T>>
Tmin
(T r1, T r2) Return the minimum value of two relative scalars.static <U extends Unit<U>,
T extends FloatScalar<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 FloatScalarRelWithAbs<AU, A, RU, R>, A extends FloatScalarAbs<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 FloatScalarRelWithAbs<AU, A, RU, R>, A extends FloatScalarAbs<AU, A, RU, R>>
Aminus
(A left, R right) Subtract a Relative value from an absolute value.static <U extends Unit<U>,
R extends FloatScalarRel<U, R>>
Rminus
(R left, R right) Subtract a relative value from a relative value.static FloatSIScalar
multiply
(FloatScalarRel<?, ?> left, FloatScalarRel<?, ?> 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 FloatScalarRelWithAbs<AU, A, RU, R>, A extends FloatScalarAbs<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 FloatScalarRelWithAbs<AU, A, RU, R>, A extends FloatScalarAbs<AU, A, RU, R>>
Aplus
(R left, A right) Add an Absolute value to a Relative value.static <U extends Unit<U>,
R extends FloatScalarRel<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 float siThe value, stored in the standard SI unit.
-
-
Constructor Details
-
FloatScalar
Construct a new FloatScalar.- Parameters:
unit
- U; the unitsi
- float; the si value to store
-
-
Method Details
-
getSI
public final float getSI()Return the value in the underlying SI unit.- Returns:
- float; the value in the underlying SI unit
-
getInUnit
public final float getInUnit()Retrieve the value in the original unit.- Returns:
- float
-
getInUnit
Retrieve the value converted into some specified unit.- Parameters:
targetUnit
- U; the unit to convert the value into- Returns:
- float
-
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 FloatScalar<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 FloatScalar<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 FloatScalar<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 FloatScalar<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 FloatScalar based on its unit. Rigid check on types by the compiler.- Type Parameters:
U
- the unitS
- the return type- Parameters:
value
- float; the valueunit
- U; the unit in which the value is expressed- Returns:
- S; an instantiated FloatScalar with the value expressed in the unit
-
instantiateSI
public static <U extends Unit<U>,S extends FloatScalar<U, S instantiateSIS>> (float valueSI, U displayUnit) Instantiate the FloatScalar 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
- float; the SIvaluedisplayUnit
- U; the unit in which the value will be displayed- Returns:
- S; an instantiated FloatScalar with the SI value and the display unit
-
instantiateAnonymous
Instantiate the FloatScalar 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
- float; the valueunit
- Unit<?>; the unit in which the value is expressed- Returns:
- S; an instantiated FloatScalar with the value expressed in the unit
-
plus
public static <AU extends AbsoluteLinearUnit<AU,RU>, A plusRU extends Unit<RU>, R extends FloatScalarRelWithAbs<AU, A, RU, R>, A extends FloatScalarAbs<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 FloatScalar; the left argumentright
- R, a relative typed FloatScalar; the right argument- Returns:
- A; an absolute typed FloatScalar; the sum of the values as an Absolute value
-
plus
public static <AU extends AbsoluteLinearUnit<AU,RU>, A plusRU extends Unit<RU>, R extends FloatScalarRelWithAbs<AU, A, RU, R>, A extends FloatScalarAbs<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 FloatScalar; the left argumentright
- R, a relative typed FloatScalar; the right argument- Returns:
- A; an absolute typed FloatScalar; 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 FloatScalar; the left argumentright
- R, a relative typed FloatScalar; the right argument- Returns:
- R; a relative typed FloatScalar; the sum of the values as a Relative value
-
minus
public static <AU extends AbsoluteLinearUnit<AU,RU>, A minusRU extends Unit<RU>, R extends FloatScalarRelWithAbs<AU, A, RU, R>, A extends FloatScalarAbs<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 FloatScalar; the left valueright
- R, a relative typed FloatScalar; the right value- Returns:
- A; an absolute typed FloatScalar; 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 FloatScalar; the left valueright
- R, a relative typed FloatScalar; the right value- Returns:
- R; a relative typed FloatScalar; the resulting value as a relative value
-
minus
public static <AU extends AbsoluteLinearUnit<AU,RU>, R minusRU extends Unit<RU>, R extends FloatScalarRelWithAbs<AU, A, RU, R>, A extends FloatScalarAbs<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 FloatScalar; value 1right
- A, an absolute typed FloatScalar; value 2- Returns:
- R; a relative typed FloatScalar; 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
- FloatScalarRel<?, ?>; the left operandright
- FloatScalarRel<?, ?>; the right operand- Returns:
- FloatScalarRel<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
- FloatScalarRel<?, ?>; the left operandright
- FloatScalarRel<?, ?>; the right operand- Returns:
- FloatScalarRel<SIUnit>; the ratio of the two values
-
interpolate
public static <U extends Unit<U>,R extends FloatScalarRel<U, R interpolateR>> (R zero, R one, float ratio) Interpolate between two values. Made to be able to call e.g., Area a = FloatScalarinterpolate(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
- float; 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 FloatScalarRelWithAbs<AU, A, RU, R>, A extends FloatScalarAbs<AU, A, RU, R>> (A zero, A one, float ratio) Interpolate between two values. Made to be able to call e.g., Time t = FloatScalarinterpolate(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
- float; 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 FloatScalar<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 FloatScalar<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
-