Enum Class Unit
- All Implemented Interfaces:
Serializable
,Comparable<Unit>
,Constable
Specifies the unit on a counter variable.
- Author:
- Brandon Arp (brandon dot arp at inscopemetrics dot io), Ville Koskela (ville dot koskela at inscopemetrics dot io)
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>>
-
Enum Constant Summary
Enum ConstantDescriptionBits.Bytes.Celcius.Days.Fahrenheit.Gigabits.Gigabytes.Hours.Kelvin.Kilobits.Kilobytes.Megabits.Megabytes.Microseconds.Milliseconds.Minutes.Nanoseconds.Petabits.Petabytes.Seconds.Terabits.Terabytes.Weeks. -
Method Summary
Modifier and TypeMethodDescriptiondouble
Converts a value in one unit to another.getSmallerUnit
(Unit otherUnit) Gets the smaller unit of two.getSmallerUnit
(Optional<Unit> unitA, Optional<Unit> unitB) Return the smaller of twoOptional
units or absent if neither is present.Gets the smallest unit for this unit's type.getType()
boolean
isSmallerThan
(Unit otherUnit) Determines if the current unit is smaller than another.static Unit
Returns the enum constant of this class with the specified name.static Unit[]
values()
Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
NANOSECOND
Nanoseconds. -
MICROSECOND
Microseconds. -
MILLISECOND
Milliseconds. -
SECOND
Seconds. -
MINUTE
Minutes. -
HOUR
Hours. -
DAY
Days. -
WEEK
Weeks. -
BIT
Bits. -
BYTE
Bytes. -
KILOBIT
Kilobits. -
MEGABIT
Megabits. -
GIGABIT
Gigabits. -
TERABIT
Terabits. -
PETABIT
Petabits. -
KILOBYTE
Kilobytes. -
MEGABYTE
Megabytes. -
GIGABYTE
Gigabytes. -
TERABYTE
Terabytes. -
PETABYTE
Petabytes. -
KELVIN
Kelvin. -
CELCIUS
Celcius. -
FAHRENHEIT
Fahrenheit.
-
-
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
-
getType
-
convert
Converts a value in one unit to another.- Parameters:
sourceValue
- the value to be convertedsourceUnit
- the unit of the source value- Returns:
- the value after conversion
-
getSmallestUnit
Gets the smallest unit for this unit's type.- Returns:
- the smallest unit
-
getSmallerUnit
Gets the smaller unit of two.- Parameters:
otherUnit
- the unit to compare this against- Returns:
- the smaller unit
-
isSmallerThan
Determines if the current unit is smaller than another.- Parameters:
otherUnit
- The other unit.- Returns:
- true if the current unit is smaller than otherUnit, otherwise false.
-
getSmallerUnit
Return the smaller of twoOptional
units or absent if neither is present. If only one is present this throws anIllegalArgumentException
.
-