Class Speed

All Implemented Interfaces:
Serializable, Comparable<Speed>, OsidPrimitive, Speed, Speed, OsidPrimitive

public final class Speed extends AbstractSpeed implements Speed
An implementation of Primitive for OSID Speeds. A speed is a distance per a single time unit. Build one directly -- valueOf(long) for meters per second, or valueOf(org.osid.mapping.Distance, org.osid.calendaring.DateTimeResolution) for a distance per a chosen unit -- or let valueOf(org.osid.mapping.Distance, org.osid.calendaring.Duration, org.osid.calendaring.DateTimeResolution) reduce an arbitrary distance over an arbitrary duration ("98 km in 1h 43m") to that per-one-unit form.
See Also:
  • Constructor Details

    • Speed

      public Speed(Distance distance, DateTimeResolution time)
      Constructs a new Speed of a distance per one time unit.
      Parameters:
      distance - the distance traveled in one unit of time
      time - the time unit
      Throws:
      NullArgumentException - distance or time is null
  • Method Details

    • makeSpeed

      protected Speed makeSpeed(Distance distance, DateTimeResolution time)
      Builds a speed of this type for a bound.
      Specified by:
      makeSpeed in class AbstractSpeed
      Parameters:
      distance - the distance
      time - the time unit
      Returns:
      a new speed
    • valueOf

      public static Speed valueOf(long metersPerSecond)
      Creates a new Speed of meters per second.
      Parameters:
      metersPerSecond - the value in meters per second
      Returns:
      a new speed
    • valueOf

      public static Speed valueOf(BigDecimal metersPerSecond)
      Creates a new Speed of meters per second.
      Parameters:
      metersPerSecond - the value in meters per second
      Returns:
      a new speed
      Throws:
      NullArgumentException - metersPerSecond is null
    • valueOf

      public static Speed valueOf(Distance distance, DateTimeResolution per)
      Creates a new Speed of a distance per one of the given time unit.
      Parameters:
      distance - the distance traveled in one time unit
      per - the time unit
      Returns:
      a new speed
      Throws:
      NullArgumentException - distance or per is null
    • valueOf

      public static Speed valueOf(Distance distance, Duration duration, DateTimeResolution per)
      Creates a new Speed from an arbitrary distance over an arbitrary duration, reduced to the distance covered in one of the given time unit. For example, 98 km over a duration of 1 hour 43 minutes, per hour, becomes a speed of about 57 km per hour -- the denominator is always one unit.
      Parameters:
      distance - the distance traveled
      duration - the time taken
      per - the time unit to express the speed in
      Returns:
      a new speed
      Throws:
      InvalidArgumentException - duration is zero, or per is INFINITY
      NullArgumentException - an argument is null
    • valueOf

      public static Speed valueOf(Distance distance, Duration duration)
      Creates a new Speed from an arbitrary distance over an arbitrary duration, reduced to meters per second.
      Parameters:
      distance - the distance traveled
      duration - the time taken
      Returns:
      a new speed
      Throws:
      InvalidArgumentException - duration is zero
      NullArgumentException - distance or duration is null
    • valueOf

      public static Speed valueOf(String text)
      Creates a new Speed from the string form produced by toString(), e.g. "90 km/h". The time symbol follows the final /.
      Parameters:
      text - the speed string
      Returns:
      a new speed
      Throws:
      InvalidArgumentException - text cannot be parsed
      NullArgumentException - text is null
    • unknown

      public static Speed unknown()
      Gets an unknown speed: an unknown distance over a second. The time unit must be finite -- a speed is a distance per one unit and INFINITY has no seconds -- so the unknown-ness is carried entirely by the distance, which has infinite resolution and infinite uncertainty.
      Returns:
      an unknown speed
    • light

      public static Speed light()
      Gets the speed of light in a vacuum: 299,792,458 meters per second. The value is exact -- since 1983 the meter has been defined from it rather than measured against it.
      Returns:
      the speed of light