Class Speed
java.lang.Object
net.okapia.osid.primordium.mapping.spi.AbstractSpeed
net.okapia.osid.primordium.mapping.Speed
- All Implemented Interfaces:
Serializable, Comparable<Speed>, OsidPrimitive, Speed, Speed, OsidPrimitive
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:
-
Nested Class Summary
Nested classes/interfaces inherited from class AbstractSpeed
AbstractSpeed.ParsedSpeedModifier and TypeClassDescriptionprotected static final classThe distance and time unit parsed from a speed string. -
Constructor Summary
ConstructorsConstructorDescriptionSpeed(Distance distance, DateTimeResolution time) Constructs a newSpeedof a distance per one time unit. -
Method Summary
Modifier and TypeMethodDescriptionstatic Speedlight()Gets the speed of light in a vacuum: 299,792,458 meters per second.protected SpeedmakeSpeed(Distance distance, DateTimeResolution time) Builds a speed of this type for a bound.static Speedunknown()Gets an unknown speed: an unknown distance over a second.static SpeedvalueOf(long metersPerSecond) Creates a newSpeedof meters per second.static SpeedCreates a newSpeedfrom the string form produced bytoString(), e.g.static SpeedvalueOf(BigDecimal metersPerSecond) Creates a newSpeedof meters per second.static SpeedvalueOf(Distance distance, DateTimeResolution per) Creates a newSpeedof a distance per one of the given time unit.static SpeedCreates a newSpeedfrom an arbitrary distance over an arbitrary duration, reduced to meters per second.static SpeedvalueOf(Distance distance, Duration duration, DateTimeResolution per) Creates a newSpeedfrom an arbitrary distance over an arbitrary duration, reduced to the distance covered in one of the given time unit.Methods inherited from class AbstractSpeed
compareTo, equals, getDistance, getLowerBound, getTimeUnit, getUpperBound, hashCode, isContained, isExclusive, isExclusive, isGreater, isInclusive, isLess, parseSpeed, secondsOf, toStringModifier and TypeMethodDescriptionintCompares this speed with the specifiedSpeedto determine the natural order.final booleanDetermines if the givenSpeedis equal to this one.final DistanceGets the distance.Gets the lower bound of the speed: the distance's lower bound over the same time unit.final DateTimeResolutionGets the time unit.Gets the upper bound of the speed: the distance's upper bound over the same time unit.final inthashCode()Returns a hash code value for thisSpeedbased on its distance and time unit.booleanisContained(Speed speed1, Speed speed2) Tests if the range of this Speed, as specified by its uncertainty, is included within the given two Speeds.booleanisExclusive(Speed speed) Tests if the range of this Speed, as specified by its uncertainty, does not overlap the given Speed.booleanisExclusive(Speed speed1, Speed speed2) Tests if the range of this Speed, as specified by its uncertainty, does not overlap with the range of the given two speeds.booleanTests if this Speed is greater than the given Speed.booleanisInclusive(Speed speed) Tests if the range of this Speed, as specified by its uncertainty, includes the given Speed ranged by its uncertainty.booleanTests if this Speed is less than the given Speed.protected static AbstractSpeed.ParsedSpeedparseSpeed(String text) Parses thetoString()form of a speed into its distance and time unit.protected static BigDecimalsecondsOf(DateTimeResolution unit) The number of seconds in one of the given time unit, taken from the calendaring Duration so the conventions (a Julian year, and so on) match the rest of the toolkit.toString()Returns a string representation of this Speed: the distance followed by the time unit, e.g.
-
Constructor Details
-
Speed
Constructs a newSpeedof a distance per one time unit.- Parameters:
distance- the distance traveled in one unit of timetime- the time unit- Throws:
NullArgumentException-distanceortimeisnull
-
-
Method Details
-
makeSpeed
Builds a speed of this type for a bound.- Specified by:
makeSpeedin classAbstractSpeed- Parameters:
distance- the distancetime- the time unit- Returns:
- a new speed
-
valueOf
Creates a newSpeedof meters per second.- Parameters:
metersPerSecond- the value in meters per second- Returns:
- a new speed
-
valueOf
Creates a newSpeedof meters per second.- Parameters:
metersPerSecond- the value in meters per second- Returns:
- a new speed
- Throws:
NullArgumentException-metersPerSecondisnull
-
valueOf
Creates a newSpeedof a distance per one of the given time unit.- Parameters:
distance- the distance traveled in one time unitper- the time unit- Returns:
- a new speed
- Throws:
NullArgumentException-distanceorperisnull
-
valueOf
Creates a newSpeedfrom 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 traveledduration- the time takenper- the time unit to express the speed in- Returns:
- a new speed
- Throws:
InvalidArgumentException-durationis zero, orperisINFINITYNullArgumentException- an argument isnull
-
valueOf
Creates a newSpeedfrom an arbitrary distance over an arbitrary duration, reduced to meters per second.- Parameters:
distance- the distance traveledduration- the time taken- Returns:
- a new speed
- Throws:
InvalidArgumentException-durationis zeroNullArgumentException-distanceordurationisnull
-
valueOf
Creates a newSpeedfrom the string form produced bytoString(), e.g."90 km/h". The time symbol follows the final/.- Parameters:
text- the speed string- Returns:
- a new speed
- Throws:
InvalidArgumentException-textcannot be parsedNullArgumentException-textisnull
-
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 andINFINITYhas no seconds -- so the unknown-ness is carried entirely by the distance, which has infinite resolution and infinite uncertainty.- Returns:
- an unknown 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
-