View Javadoc

1   
2   package edu.iris.Fissures.model;
3   
4   import edu.iris.Fissures.Quantity;
5   
6   /***
7    * TimeInterval.java
8    *
9    *
10   * Created: Wed Sep  1 20:23:31 1999
11   *
12   * @author Philip Crotwell
13   * @version
14   */
15  
16  public class TimeInterval extends QuantityImpl {
17  
18      public TimeInterval(edu.iris.Fissures.Quantity interval) {
19          this(interval.value, UnitImpl.createUnitImpl(interval.the_units));
20      }
21  
22      public TimeInterval(MicroSecondDate begin, MicroSecondDate end) {
23          this(end.getMicroSecondTime() - begin.getMicroSecondTime(),
24               UnitImpl.MICROSECOND);
25      }
26  
27      /*** Creates a TimeInterval with the units and value.
28       * @throws IllegalArgumentException if the units are not time.
29       */
30      public TimeInterval(double f, UnitImpl the_unit) {
31          super(f, the_unit);
32          if ( ! the_unit.isConvertableTo(UnitImpl.TIME)) {
33              throw new IllegalArgumentException("TimeInterval "+f+" "+the_units+
34                                                     " does not have units of time.");
35          }
36      }
37  
38      /*** Creates a TimeInterval froma  Quantity, making sure that the
39       *  units are time.
40       * @throws IllegalArgumentException if the units are not time.
41       */
42      public static TimeInterval createTimeInterval(Quantity q) {
43          if (q instanceof TimeInterval) {
44              return (TimeInterval)q;
45          }
46          return new TimeInterval(q);
47      }
48  
49      /*** overrides covertTo() in QuantityImpl to return a TimeInterval instead
50       *  of a QuantityImpl.
51       */
52      public QuantityImpl convertTo(UnitImpl newUnit) {
53          QuantityImpl q = super.convertTo(newUnit);
54          return new TimeInterval(q);
55      }
56  
57      /*** overrides multiplyBy() in QuantityImpl to return a TimeInterval instead
58       *  of a QuantityImpl.
59       */
60      public QuantityImpl multiplyBy(double f) {
61          QuantityImpl newq = super.multiplyBy(f);
62          return new TimeInterval(newq);
63      }
64  
65      /*** overrides divideBy() in QuantityImpl to return a TimeInterval instead
66       *  of a QuantityImpl.
67       */
68      public QuantityImpl divideBy(double f) {
69          QuantityImpl newq = super.divideBy(f);
70          return new TimeInterval(newq);
71      }
72  
73      public TimeInterval add(TimeInterval t) {
74          QuantityImpl newq = super.add(t);
75          return new TimeInterval(newq);
76      }
77  
78      public TimeInterval subtract(TimeInterval t) {
79          QuantityImpl newq = super.subtract(t);
80          return new TimeInterval(newq);
81      }
82  
83  } // TimeInterval