Package megamek.common.util
Enum Class RoundWeight
- All Implemented Interfaces:
Serializable,Comparable<RoundWeight>,Constable
A series of rounding methods that account for floating point precision issues. These can used through static methods
but are implemented as an enum to make an easy way for the method itself to be stored in a field.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>> -
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionRound up to next half tonRound to the nearest kgRound to the nearest tonRound up to next half tonRound up to the nearest kg (used for small SV engine and structure)Round up to the nearest tonRound kg standard to next kg, ton-standard to next half tonRound kg standard to nearest kg, ton-standard to nearest half ton (used for SV engine weight per TM p.133) -
Method Summary
Modifier and TypeMethodDescriptionstatic doublenearestHalfTon(double weight) Deprecated, for removal: This API element is subject to removal in a future version.static doublenearestKg(double weight) Rounds normally to nearest kgstatic doublenearestTon(double weight) Rounds normally to nearest tonstatic doublenextHalfTon(double weight) Rounds up to the next half ton.static doublenextKg(double weight) Rounds up to the next kilogramstatic doublenextTon(double weight) Rounds up to the next full tondoubleApplies the rounding operation to a weightstatic doubleRounds using the standard method for theEntity.static doubletruncate(double weight) Chops off trailing float irregularities by rounding to the gram.static booleanusesKilogramStandard(Entity entity) Convenience method for checking whether anEntityuses the kilogram standard in its construction rules rather than tons.static RoundWeightReturns the enum constant of this class with the specified name.static RoundWeight[]values()Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
NONE
-
NEAREST_HALF_TON
Round up to next half ton -
NEAREST_KG
Round to the nearest kg -
NEAREST_TON
Round to the nearest ton -
NEXT_HALF_TON
Round up to next half ton -
NEXT_KG
Round up to the nearest kg (used for small SV engine and structure) -
NEXT_TON
Round up to the nearest ton -
STANDARD
Round kg standard to next kg, ton-standard to next half ton -
SV_ENGINE
Round kg standard to nearest kg, ton-standard to nearest half ton (used for SV engine weight per TM p.133)
-
-
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
-
usesKilogramStandard
Convenience method for checking whether anEntityuses the kilogram standard in its construction rules rather than tons.- Parameters:
entity- The unit to check- Returns:
- Whether the construction weight is measured in kilograms
-
round
Applies the rounding operation to a weight- Parameters:
weight- The weight to be rounded, in metric tons.entity- The unit the equipment is mounted on. This is needed for operations that depend on whether the unit uses the ton or kg standard. Ifnull, the unit is assumed to use the ton standard.- Returns:
- The result of the rounding operation.
-
truncate
public static double truncate(double weight) Chops off trailing float irregularities by rounding to the gram. Used as the first step in rounding operations that round up.- Parameters:
weight- The weight to round.- Returns:
- The weight rounded to the gram.
-
nearestHalfTon
Deprecated, for removal: This API element is subject to removal in a future version.Rounds normally to nearest half ton- Parameters:
weight- The weight in tons- Returns:
- The weight in tons, rounded to the closest half ton.
-
nearestTon
public static double nearestTon(double weight) Rounds normally to nearest ton- Parameters:
weight- The weight in tons- Returns:
- The weight in tons, rounded to the closest ton.
-
nearestKg
public static double nearestKg(double weight) Rounds normally to nearest kg- Parameters:
weight- The weight in tons- Returns:
- The weight in tons, rounded to the closest kilogram.
-
nextHalfTon
public static double nextHalfTon(double weight) Rounds up to the next half ton.- Parameters:
weight- The weight in tons- Returns:
- The weight in tons rounded up to the half ton
-
nextKg
public static double nextKg(double weight) Rounds up to the next kilogram- Parameters:
weight- The weight in tons- Returns:
- The weight in tons rounded up to the kilogram
-
nextTon
public static double nextTon(double weight) Rounds up to the next full ton- Parameters:
weight- The weight to round in tons- Returns:
- The weight in tons rounded up to the full ton
-
standard
Rounds using the standard method for theEntity. For kg-standard units this rounds to the closest kg. For all others this rounds up to the half ton.- Parameters:
weight- The weight to round, in tonsentity- The unit the equipment is mounted on. Ifnull, ton-standard is assumed- Returns:
- The weight in tons, rounded as appropriate for the construction rules of the unit.
-