Class Speed
java.lang.Object
rgu.transport.geospatial.Speed
- All Implemented Interfaces:
Comparable<Speed>
A (non-negative) scalar travel speed.
- Author:
- Lee A. Christie
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptiondoubleReturns the speed in kilometers per hour.doubleReturns the speed in meters per second.doubleReturns the speed in miles per hour.intCompares this speed to another speed.booleanChecks if the other object represents the same speed.inthashCode()Returns a hash code for this object.booleanReturns true if the speed is positive, false otherwise.booleanisZero()Returns true if the speed is zero, false otherwise.static SpeedofKilometersPerHour(double kilometersPerHour) Returns an instance of Speed for the specified kilometers per hour.static SpeedofMetersPerSecond(double metersPerSecond) Returns an instance of Speed for the specified meters per second.static SpeedofMilesPerHour(double milesPerHour) Returns an instance of Speed for the specified miles peer hour.static SpeedReads the speed value from the specified input stream.Returns the total time taken to travel a given distance as this constant velocity, using double precision rounded to the nearest nanosecond.timeRoundedToSeconds(Distance distance) Returns the total time taken to travel a given distance as this constant velocity, rounded to the nearest whole number of seconds.timeTruncatedToSeconds(Distance distance) Returns the total time taken to travel a given distance as this constant velocity, rounded down to a whole number of seconds.toString()Returns a string representation of the speed (shown in meters per second).voidwrite(ObjectOutputStream out) Writes the speed value to the specified output stream.
-
Field Details
-
ZERO
A speed of zero (stationary).
-
-
Method Details
-
ofMetersPerSecond
Returns an instance of Speed for the specified meters per second.- Parameters:
metersPerSecond- the speed, in the range [0, inf)- Returns:
- an instance of Speed
-
ofKilometersPerHour
Returns an instance of Speed for the specified kilometers per hour.- Parameters:
kilometersPerHour- the speed, in the range [0, inf)- Returns:
- an instance of Speed
-
ofMilesPerHour
Returns an instance of Speed for the specified miles peer hour.- Parameters:
milesPerHour- the speed, in the range [0, inf)- Returns:
- an instance of Speed
-
asMetersPerSecond
public double asMetersPerSecond()Returns the speed in meters per second.- Returns:
- the speed
-
asKilometersPerHour
public double asKilometersPerHour()Returns the speed in kilometers per hour.- Returns:
- the speed
-
asMilesPerHour
public double asMilesPerHour()Returns the speed in miles per hour.- Returns:
- the speed
-
toString
-
compareTo
Compares this speed to another speed.- Specified by:
compareToin interfaceComparable<Speed>- Parameters:
other- the other speed, not null- Returns:
- 0, -1, or 1 based on Comparable definition
-
hashCode
-
equals
-
write
Writes the speed value to the specified output stream.- Parameters:
out- the output stream, not null- Throws:
IOException- if an exception occurred in writing
-
read
Reads the speed value from the specified input stream. There is a special case where if the read value is the NaN, the value null will be returned.- Parameters:
in- the input stream, not null- Returns:
- the speed or null
- Throws:
IOException- if an exception occurred in reading
-
timeTruncatedToSeconds
-
timeRoundedToSeconds
-
time
-
isPositive
public boolean isPositive()Returns true if the speed is positive, false otherwise. If the speed is not positive, then it must be zero.- Returns:
- true if positive, false if zero
-
isZero
public boolean isZero()Returns true if the speed is zero, false otherwise. If the speed is not zero, then it must be positive.- Returns:
- true if zero, false if positive
-