Class Weight

All Implemented Interfaces:
Serializable

public class Weight extends Measurement<WeightUnit>
Contains a weight value and unit.
See Also:
  • Constructor Details

    • Weight

      public Weight(Number value, WeightUnit unit)
      Constructor with value and unit.
      Parameters:
      value - weight value.
      unit - unit of weight.
      Throws:
      IllegalArgumentException - if either value or unit is null.
    • Weight

      Weight()
      Constructor.
  • Method Details

    • equals

      public boolean equals(Measurement<WeightUnit> other, double tolerance)
      Determines if two weights are equal up to a certain tolerance. If needed, this method attempts unit conversion to compare both objects.
      Overrides:
      equals in class Measurement<WeightUnit>
      Parameters:
      other - another measurement to compare.
      tolerance - amount of tolerance to determine whether two measurements are equal or not.
      Returns:
      true if provided weight is assumed to be equal to this instance, false otherwise.
    • add

      public static double add(double value1, WeightUnit unit1, double value2, WeightUnit unit2, WeightUnit resultUnit)
      Adds two weight values and units and returns the result.
      Parameters:
      value1 - 1st argument value.
      unit1 - 1st argument unit.
      value2 - 2nd argument value.
      unit2 - 2nd argument unit.
      resultUnit - unit of result to be returned.
      Returns:
      result of addition.
    • add

      public static Number add(Number value1, WeightUnit unit1, Number value2, WeightUnit unit2, WeightUnit resultUnit)
      Adds two weight values and units and returns the result.
      Parameters:
      value1 - 1st argument value.
      unit1 - 1st argument unit.
      value2 - 2nd argument value.
      unit2 - 2nd argument unit.
      resultUnit - unit of result to be returned.
      Returns:
      result of addition.
    • add

      public static void add(Weight arg1, Weight arg2, Weight result)
      Adds two weights and stores the result into provided instance.
      Parameters:
      arg1 - 1st argument.
      arg2 - 2nd argument.
      result - instance where result will be stored.
    • addAndReturnNew

      public static Weight addAndReturnNew(Weight arg1, Weight arg2, WeightUnit unit)
      Adds two weights.
      Parameters:
      arg1 - 1st argument.
      arg2 - 2nd argument.
      unit - unit of returned weight.
      Returns:
      a new instance containing result.
    • addAndReturnNew

      public Weight addAndReturnNew(double value, WeightUnit unit, WeightUnit resultUnit)
      Adds provided weight value and unit and returns a new weight instance using provided unit.
      Parameters:
      value - value to be added.
      unit - unit of value to be added.
      resultUnit - unit of returned weight.
      Returns:
      a new weight containing result.
    • addAndReturnNew

      public Weight addAndReturnNew(Number value, WeightUnit unit, WeightUnit resultUnit)
      Adds provided weight value and unit and returns a new weight instance using provided unit.
      Parameters:
      value - value to be added.
      unit - unit of value to be added.
      resultUnit - unit of returned weight.
      Returns:
      a new weight containing result.
    • addAndReturnNew

      public Weight addAndReturnNew(Weight w, WeightUnit unit)
      Adds provided weight to current instance and returns a new weight.
      Parameters:
      w - weight to be added.
      unit - unit of returned weight.
      Returns:
      a new weight containing result.
    • add

      public void add(double value, WeightUnit unit)
      Adds provided weight value and unit and updates current weight instance.
      Parameters:
      value - weight value to be added.
      unit - unit of weight value.
    • add

      public void add(Number value, WeightUnit unit)
      Adds provided weight value and unit and updates current weight instance.
      Parameters:
      value - weight value to be added.
      unit - unit of weight value.
    • add

      public void add(Weight weight)
      Adds provided weight and updates current weight.
      Parameters:
      weight - weight to be added.
    • add

      public void add(Weight w, Weight result)
      Adds provided weight and stores the result into provided weight.
      Parameters:
      w - weight to be added.
      result - instance where result will be stored.
    • subtract

      public static double subtract(double value1, WeightUnit unit1, double value2, WeightUnit unit2, WeightUnit resultUnit)
      Subtracts two weight values and units and returns the result.
      Parameters:
      value1 - 1st argument value.
      unit1 - 1st argument unit.
      value2 - 2nd argument value.
      unit2 - 2nd argument unit.
      resultUnit - unit of result to be returned.
      Returns:
      result of subtraction.
    • subtract

      public static Number subtract(Number value1, WeightUnit unit1, Number value2, WeightUnit unit2, WeightUnit resultUnit)
      Subtracts two weight values and units and returns the result.
      Parameters:
      value1 - 1st argument value.
      unit1 - 1st argument unit.
      value2 - 2nd argument value.
      unit2 - 2nd argument unit.
      resultUnit - unit of result to be returned.
      Returns:
      result of subtraction.
    • subtract

      public static void subtract(Weight arg1, Weight arg2, Weight result)
      Subtracts two weights and stores the result into provided instance.
      Parameters:
      arg1 - 1st argument.
      arg2 - 2nd argument.
      result - instance where result will be stored.
    • subtractAndReturnNew

      public static Weight subtractAndReturnNew(Weight arg1, Weight arg2, WeightUnit unit)
      Subtracts two weights.
      Parameters:
      arg1 - 1st argument.
      arg2 - 2nd argument.
      unit - unit of returned weight.
      Returns:
      a new instance containing result.
    • subtractAndReturnNew

      public Weight subtractAndReturnNew(double value, WeightUnit unit, WeightUnit resultUnit)
      Subtracts provided weight value and unit and returns a new weight instance using provided unit.
      Parameters:
      value - value to be subtracted.
      unit - unit of value to be subtracted.
      resultUnit - unit of returned weight.
      Returns:
      a new weight containing result.
    • subtractAndReturnNew

      public Weight subtractAndReturnNew(Number value, WeightUnit unit, WeightUnit resultUnit)
      Subtracts provided weight value and unit and returns a new weight instance using provided unit.
      Parameters:
      value - value to be subtracted.
      unit - unit of value to be subtracted.
      resultUnit - unit of returned weight.
      Returns:
      a new weight containing result.
    • subtractAndReturnNew

      public Weight subtractAndReturnNew(Weight w, WeightUnit unit)
      Subtracts provided weight from current instance and returns a new weight.
      Parameters:
      w - weight to be subtracted.
      unit - unit of returned weight.
      Returns:
      a new weight containing result.
    • subtract

      public void subtract(double value, WeightUnit unit)
      Subtracts provided weight value and unit and updates current weight instance.
      Parameters:
      value - weight value to be subtracted.
      unit - unit of weight value.
    • subtract

      public void subtract(Number value, WeightUnit unit)
      Subtracts provided weight value and unit and updates current weight instance.
      Parameters:
      value - weight value to be subtracted.
      unit - unit of weight value.
    • subtract

      public void subtract(Weight weight)
      Subtracts provided weight and updates current weight.
      Parameters:
      weight - weight to be subtracted.
    • subtract

      public void subtract(Weight w, Weight result)
      Subtracts provided weight and stores the result into provided weight.
      Parameters:
      w - weight to be subtracted.
      result - instance where result will be stored.