Enum Class RoundWeight

java.lang.Object
java.lang.Enum<RoundWeight>
megamek.common.util.RoundWeight
All Implemented Interfaces:
Serializable, Comparable<RoundWeight>, Constable

public enum RoundWeight extends Enum<RoundWeight>
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 Constants
    Enum Constant
    Description
    Round up to next half ton
    Round to the nearest kg
    Round to the nearest ton
    Round up to next half ton
    Round up to the nearest kg (used for small SV engine and structure)
    Round up to the nearest ton
     
    Round kg standard to next kg, ton-standard to next half ton
    Round kg standard to nearest kg, ton-standard to nearest half ton (used for SV engine weight per TM p.133)
  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    nearestHalfTon(double weight)
    Deprecated, for removal: This API element is subject to removal in a future version.
    static double
    nearestKg(double weight)
    Rounds normally to nearest kg
    static double
    nearestTon(double weight)
    Rounds normally to nearest ton
    static double
    nextHalfTon(double weight)
    Rounds up to the next half ton.
    static double
    nextKg(double weight)
    Rounds up to the next kilogram
    static double
    nextTon(double weight)
    Rounds up to the next full ton
    double
    round(double weight, Entity entity)
    Applies the rounding operation to a weight
    static double
    standard(double weight, Entity entity)
    Rounds using the standard method for the Entity.
    static double
    truncate(double weight)
    Chops off trailing float irregularities by rounding to the gram.
    static boolean
    Convenience method for checking whether an Entity uses the kilogram standard in its construction rules rather than tons.
    Returns the enum constant of this class with the specified name.
    static RoundWeight[]
    Returns an array containing the constants of this enum class, in the order they are declared.

    Methods inherited from class java.lang.Object

    getClass, notify, notifyAll, wait, wait, wait
  • Enum Constant Details

    • NONE

      public static final RoundWeight NONE
    • NEAREST_HALF_TON

      public static final RoundWeight NEAREST_HALF_TON
      Round up to next half ton
    • NEAREST_KG

      public static final RoundWeight NEAREST_KG
      Round to the nearest kg
    • NEAREST_TON

      public static final RoundWeight NEAREST_TON
      Round to the nearest ton
    • NEXT_HALF_TON

      public static final RoundWeight NEXT_HALF_TON
      Round up to next half ton
    • NEXT_KG

      public static final RoundWeight NEXT_KG
      Round up to the nearest kg (used for small SV engine and structure)
    • NEXT_TON

      public static final RoundWeight NEXT_TON
      Round up to the nearest ton
    • STANDARD

      public static final RoundWeight STANDARD
      Round kg standard to next kg, ton-standard to next half ton
    • SV_ENGINE

      public static final RoundWeight 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

      public static RoundWeight[] 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

      public static RoundWeight valueOf(String name)
      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 name
      NullPointerException - if the argument is null
    • usesKilogramStandard

      public static boolean usesKilogramStandard(Entity entity)
      Convenience method for checking whether an Entity uses 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

      public double round(double weight, Entity entity)
      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. If null, 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(since="0.51.0", forRemoval=true) public static double nearestHalfTon(double weight)
      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

      public static double standard(double weight, Entity entity)
      Rounds using the standard method for the Entity. 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 tons
      entity - The unit the equipment is mounted on. If null, ton-standard is assumed
      Returns:
      The weight in tons, rounded as appropriate for the construction rules of the unit.