Class Speed

All Implemented Interfaces:
Serializable

public class Speed extends Measurement<SpeedUnit>
Contains a speed value and unit.
See Also:
  • Constructor Details

    • Speed

      public Speed(Number value, SpeedUnit unit)
      Constructor with value and unit.
      Parameters:
      value - speed value.
      unit - unit of speed.
      Throws:
      IllegalArgumentException - if either value or unit is null.
    • Speed

      Speed()
      Constructor.
  • Method Details

    • equals

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

      public static double add(double value1, SpeedUnit unit1, double value2, SpeedUnit unit2, SpeedUnit resultUnit)
      Adds two speed 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, SpeedUnit unit1, Number value2, SpeedUnit unit2, SpeedUnit resultUnit)
      Adds two speed values and unit 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(Speed arg1, Speed arg2, Speed result)
      Adds two speed instances and stores the result into provided instance.
      Parameters:
      arg1 - 1st argument.
      arg2 - 2nd argument.
      result - instance where result will be stored.
    • addAndReturnNew

      public static Speed addAndReturnNew(Speed arg1, Speed arg2, SpeedUnit unit)
      Adds two speed instances.
      Parameters:
      arg1 - 1st argument.
      arg2 - 2nd argument.
      unit - unit of returned speed.
      Returns:
      a new instance containing result.
    • addAndReturnNew

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

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

      public Speed addAndReturnNew(Speed s, SpeedUnit unit)
      Adds provided speed to current instance and returns a new speed.
      Parameters:
      s - speed to be added.
      unit - unit of returned speed.
      Returns:
      a new speed containing result.
    • add

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

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

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

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

      public static double subtract(double value1, SpeedUnit unit1, double value2, SpeedUnit unit2, SpeedUnit resultUnit)
      Subtracts two speed 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, SpeedUnit unit1, Number value2, SpeedUnit unit2, SpeedUnit resultUnit)
      Subtracts two speed 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(Speed arg1, Speed arg2, Speed result)
      Subtracts two speed instances and stores the result into provided instance.
      Parameters:
      arg1 - 1st argument.
      arg2 - 2nd argument.
      result - instance where result will be stored.
    • subtractAndReturnNew

      public static Speed subtractAndReturnNew(Speed arg1, Speed arg2, SpeedUnit unit)
      Subtracts two speed instances.
      Parameters:
      arg1 - 1st argument.
      arg2 - 2nd argument.
      unit - unit of returned speed.
      Returns:
      a new instance containing result.
    • subtractAndReturnNew

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

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

      public Speed subtractAndReturnNew(Speed s, SpeedUnit unit)
      Subtracts provided speed to current instance and returns a new speed instance.
      Parameters:
      s - speed to be subtracted.
      unit - unit of returned speed.
      Returns:
      a new speed containing result.
    • subtract

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

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

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

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