javax.realtime
Class RationalTime

java.lang.Object
  |
  +--javax.realtime.HighResolutionTime
        |
        +--javax.realtime.RelativeTime
              |
              +--javax.realtime.RationalTime
All Implemented Interfaces:
java.lang.Comparable

public class RationalTime
extends RelativeTime

An object that represents a time interval millis/1E3+nanos/1E9 seconds long that is divided into subintervals by some frequency. This is generally used in periodic events, threads, and feasibility analysis to specify periods where there is a basic period that must be adhered to strictly (the interval), but within that interval the periodic events are supposed to happen frequency times, as u niformly spaced as possible, but clock and scheduling jitter is moderately acceptable.

If the value of any of the millisecond or nanosecond fields is negative the variable is set to negative value. Although logically this may represent time before the epoch, invalid results may occur if an instance of AbsoluteTime representing time before the epoch is given as a parameter to a method.

Caution: This class is explicitly unsafe in multithreaded situations when it is being changed. No synchronization is done. It is assumed that users of this class who are mutating instances will be doing their own synchronization at a higher level.


Field Summary
private  int frequency
           
 
Fields inherited from class javax.realtime.RelativeTime
ZERO
 
Fields inherited from class javax.realtime.HighResolutionTime
defaultClock
 
Constructor Summary
RationalTime(int frequency)
          Constructs an instance of RationalTime.
RationalTime(int frequency, long millis, int nanos)
          Constructs an instance of RationalTime.
RationalTime(int frequency, javax.realtime.RelativeTime interval)
          Constructs an instance of RationalTime from the given RelativeTime.
 
Method Summary
 javax.realtime.AbsoluteTime absolute(javax.realtime.Clock clock, javax.realtime.AbsoluteTime destination)
          Convert this time to an absolute time.
 void addInterarrivalTo(javax.realtime.AbsoluteTime destination)
          Add this time to an AbsoluteTime.
 int getFrequency()
          Gets the value of frequency.
 javax.realtime.RelativeTime getInterarrivalTime()
          Gets the interarrival time.
 javax.realtime.RelativeTime getInterarrivalTime(javax.realtime.RelativeTime dest)
          Gets the interarrival time.
 void set(long millis, int nanos)
          Sets the indicated fields to the given values.
 void setFrequency(int frequency)
          Sets the value of the frequency field.
 
Methods inherited from class javax.realtime.RelativeTime
absolute, add, add, add, add, relative, relative, relative, subtract, subtract, toString
 
Methods inherited from class javax.realtime.HighResolutionTime
compareTo, compareTo, equals, equals, getMilliseconds, getNanoseconds, hashCode, set, set, time, waitForObject
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

frequency

private int frequency
Constructor Detail

RationalTime

public RationalTime(int frequency)
Constructs an instance of RationalTime. Equivalent to new RationalTime(frequency, 1000, 0) -- essentially a cycle-per-seconds value.

Parameters:
frequency - The frequency value.

RationalTime

public RationalTime(int frequency,
                    long millis,
                    int nanos)
             throws java.lang.IllegalArgumentException
Constructs an instance of RationalTime. All arguments must be greater than or equal to zero.

Parameters:
frequency - The frequency value.
millis - The milliseconds value.
nanos - The nanoseconds value.
Throws:
java.lang.IllegalArgumentException - If any of the argument values are less than zero.

RationalTime

public RationalTime(int frequency,
                    javax.realtime.RelativeTime interval)
             throws java.lang.IllegalArgumentException
Constructs an instance of RationalTime from the given RelativeTime.

Parameters:
frequency - The frequency value.
interval - The given instance of RelativeTime.
Throws:
java.lang.IllegalArgumentException - If any of the argument values are less than zero.
Method Detail

absolute

public javax.realtime.AbsoluteTime absolute(javax.realtime.Clock clock,
                                            javax.realtime.AbsoluteTime destination)
Convert this time to an absolute time.

Overrides:
absolute in class RelativeTime
Parameters:
clock - The reference clock. If null, Clock.getRealTimeClock() is used.
destination - A reference to the destination istance.
Returns:
The new instance of AbsoluteTime containing the result.

addInterarrivalTo

public void addInterarrivalTo(javax.realtime.AbsoluteTime destination)
Add this time to an AbsoluteTime. It is almost the same as destination.add(this, destination) except that it accounts for (ie. divides by) the frequency.

Overrides:
addInterarrivalTo in class RelativeTime
Parameters:
destination - A reference to the given instance of AbsoluteTime and the result.

getFrequency

public int getFrequency()
Gets the value of frequency.

Returns:
The value of frequency as an integer.

getInterarrivalTime

public javax.realtime.RelativeTime getInterarrivalTime()
Gets the interarrival time. This time is (milliseconds/10^3 + nanoseconds/10^9)/frequency rounded down to the nearest expressible value of the fields and their types of RelativeTime.

Overrides:
getInterarrivalTime in class RelativeTime
Returns:
A reference to a new instance of RelativeTime with the same interval as this.

getInterarrivalTime

public javax.realtime.RelativeTime getInterarrivalTime(javax.realtime.RelativeTime dest)
Gets the interarrival time. This time is (milliseconds/10^3 + nanoseconds/10^9)/frequency rounded down to the nearest expressible value of the fields and their types of RelativeTime.

Overrides:
getInterarrivalTime in class RelativeTime
Parameters:
dest - Result is stored in dest and returned; if null, a new object is returned.
Returns:
A reference to an object holding the result.

set

public void set(long millis,
                int nanos)
         throws java.lang.IllegalArgumentException
Sets the indicated fields to the given values.

Overrides:
set in class HighResolutionTime
Parameters:
millis - The new value for the millisecond field.
nanos - The new value for the nanosecond field.
Throws:
java.lang.IllegalArgumentException

setFrequency

public void setFrequency(int frequency)
                  throws java.lang.ArithmeticException
Sets the value of the frequency field.

Parameters:
frequency - The new value for the frequency.
Throws:
java.lang.ArithmeticException