View Javadoc

1   
2   package edu.iris.Fissures.model;
3   
4   import java.io.Serializable;
5   import edu.iris.Fissures.Sampling;
6   
7   /***
8    * SamplingImpl.java
9    *
10   *
11   * Created: Wed Aug 11 11:02:00 1999
12   *
13   * @author Philip Crotwell
14   * @version
15   */
16  
17  public class SamplingImpl extends Sampling {
18      protected SamplingImpl() {}
19  
20      public static Serializable createEmpty() { return new SamplingImpl(); }
21  
22      public SamplingImpl(int numPoints, TimeInterval interval) {
23          if (interval.value == Double.POSITIVE_INFINITY && numPoints == 1) {
24              // in this case, the DMC database likely had 0 sps, and converted
25              // it to 1 sample in inifinity seconds. So we change to
26              // 0 samples in 1 second, which is probably more correct
27              interval = new TimeInterval(1, UnitImpl.SECOND);
28              numPoints = 0;
29          }
30          this.interval = interval;
31          this.numPoints = numPoints;
32      }
33  
34      public static SamplingImpl createSamplingImpl(Sampling samp) {
35          if (samp instanceof SamplingImpl)  return (SamplingImpl)samp;
36  
37          return new SamplingImpl(samp.numPoints,
38                                  TimeInterval.createTimeInterval(samp.interval));
39      }
40  
41  
42      /*** Gets the sample period. Returns a Quantity object that has
43       Units of time, usually seconds.
44       @returns the sample period in units of time
45       */
46      public TimeInterval getPeriod() {
47          return (TimeInterval)(getTimeInterval().divideBy(numPoints));
48      }
49  
50      /*** Gets the sample frequency. Returns a Quantity object that has
51       units of 1/time, usually Hz.
52       @returns the sample frequency.
53       */
54      public QuantityImpl getFrequency() {
55          return getTimeInterval().inverse().multiplyBy(numPoints);
56      }
57  
58      public int getNumPoints() { return numPoints; }
59  
60      public TimeInterval getTimeInterval() { return TimeInterval.createTimeInterval(interval); }
61  
62      public String toString() { return numPoints +" in "+interval; }
63  
64      public int hashCode(){
65          int result = 38;
66          result += 37* result + getTimeInterval().hashCode();
67          result += 37 * result + getNumPoints();
68          return result;
69      }
70  
71      public boolean equals(Object o) {
72          if (super.equals(o))  return true;
73          if (o instanceof SamplingImpl) {
74              SamplingImpl sampImpl = (SamplingImpl)o;
75              if (sampImpl.getPeriod().equals(getPeriod()))  return true;
76          }
77          return false;
78      }
79  
80  } // SamplingImpl