- All Implemented Interfaces:
Serializable
,Comparable<DataSize>
,Constable
,Dimension
,DimensionWithLinearConversion
@ClassVersion(sourceVersion="$Id: DataSize.java 1072 2023-09-30 20:44:38Z tquadrat $")
@API(status=STABLE,
since="0.1.0")
public enum DataSize
extends Enum<DataSize>
implements DimensionWithLinearConversion
The various instances of data sizes (for files or free disk space or
capacities of memory sticks …).
- Author:
- Thomas Thrien (thomas.thrien@tquadrat.org)
- Version:
- $Id: DataSize.java 1072 2023-09-30 20:44:38Z tquadrat $
- Since:
- 0.1.0
- UML Diagram
-
UML Diagram for "org.tquadrat.foundation.value.DataSize"
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>>
-
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionA single byte.A gigabyte in the binary form.A gigabyte (the decimal form).A Kilobyte with 1024 bytes.A Kilobyte (with 1000 bytes).A megabyte in the binary form.A megabyte (the decimal form).A terabyte in the binary form.A terabyte (the decimal form). -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final BigDecimal
The factor.private final int
The default precision.private final String
The unit string.Fields inherited from interface org.tquadrat.foundation.value.api.DimensionWithLinearConversion
MSG_UnknownUnit
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
DataSize
(BigDecimal factor, String unitSymbol) Creates a newDataSize
instance, with a default precision of zero mantissa digits.private
DataSize
(BigDecimal factor, String unitSymbol, int precision) Creates a newDataSize
instance. -
Method Summary
Modifier and TypeMethodDescriptionfinal DataSize
baseUnit()
Returns the base unit.final BigDecimal
factor()
Returns the factor that is used to convert a value from this unit to the base unit.static final DataSize
Returns theDataSize
instance for the given unit.final int
Returns the default precision for this unit that is used when the respective value is converted to a String.final String
Returns the unit symbol for the dimension as a single line string.static DataSize
Returns the enum constant of this class with the specified name.static DataSize[]
values()
Returns an array containing the constants of this enum class, in the order they are declared.Methods inherited from class java.lang.Enum
clone, compareTo, describeConstable, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
Methods inherited from interface org.tquadrat.foundation.value.api.Dimension
equals, name, toString, unitSymbolForPrinting
Methods inherited from interface org.tquadrat.foundation.value.api.DimensionWithLinearConversion
fromBase, toBase
-
Enum Constant Details
-
BYTE
A single byte. -
KILOBYTE
A Kilobyte (with 1000 bytes). -
KIBIBYTE
A Kilobyte with 1024 bytes. -
MEGABYTE
A megabyte (the decimal form). -
MEBIBYTE
A megabyte in the binary form. -
GIGABYTE
A gigabyte (the decimal form). -
GIBIBYTE
A gigabyte in the binary form. -
TERABYTE
A terabyte (the decimal form). -
TEBIBYTE
A terabyte in the binary form.
-
-
Field Details
-
m_Factor
The factor. -
m_Precision
The default precision. -
m_UnitSymbol
The unit string.
-
-
Constructor Details
-
DataSize
Creates a newDataSize
instance.- Parameters:
factor
- The factor.unitSymbol
- The unit string.precision
- The default precision.
-
DataSize
Creates a newDataSize
instance, with a default precision of zero mantissa digits.- Parameters:
factor
- The factor.unitSymbol
- The unit string.
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException
- if this enum class has no constant with the specified nameNullPointerException
- if the argument is null
-
baseUnit
Returns the base unit.
E.g. for length, the base unit would be Meter (m), for mass, it is Kilogram (kg), and so on.
-
factor
Returns the factor that is used to convert a value from this unit to the base unit.
For length, if you have to convert a Centimeter value to Meter, you will divide that by 100 or multiply it with a factor of 0.01.
For the base unit, the factor is 1.0.
- Specified by:
factor
in interfaceDimensionWithLinearConversion
- Returns:
- The factor.
- See Also:
-
forUnit
Returns theDataSize
instance for the given unit.- Parameters:
unit
- The unit.- Returns:
- The respective instance.
- Throws:
IllegalArgumentException
- The given unit is unknown.
-
getPrecision
Returns the default precision for this unit that is used when the respective value is converted to a String.- Specified by:
getPrecision
in interfaceDimension
- Returns:
- The mantissa length for a value with this unit.
-
unitSymbol
Returns the unit symbol for the dimension as a single line string.
For a length, this would be "m", for a speed "km/h", and for an acceleration, it could be "m/(s^2)".
- Specified by:
unitSymbol
in interfaceDimension
- Returns:
- The unit.
-