Added gravitational acceleration and propellant mass datatypes.
[debian/openrocket] / core / src / net / sf / openrocket / simulation / MassData.java
1 package net.sf.openrocket.simulation;
2
3 import net.sf.openrocket.util.Coordinate;
4 import net.sf.openrocket.util.MathUtil;
5
6 /**
7  * An immutable value object containing the mass data of a rocket.
8  * 
9  * @author Sampo Niskanen <sampo.niskanen@iki.fi>
10  */
11 public class MassData {
12
13         private final Coordinate cg;
14         private final double longitudinalInertia;
15         private final double rotationalInertia;
16         private final double propellantMass;
17         
18         
19         public MassData(Coordinate cg, double longitudinalInertia, double rotationalInertia, double propellantMass) {
20                 if (cg == null) {
21                         throw new IllegalArgumentException("cg is null");
22                 }
23                 this.cg = cg;
24                 this.longitudinalInertia = longitudinalInertia;
25                 this.rotationalInertia = rotationalInertia;
26                 this.propellantMass = propellantMass;
27         }
28
29         
30         
31         
32         public Coordinate getCG() {
33                 return cg;
34         }
35         
36         public double getLongitudinalInertia() {
37                 return longitudinalInertia;
38         }
39         
40         public double getRotationalInertia() {
41                 return rotationalInertia;
42         }
43
44         public double getPropellantMass() {
45                 return propellantMass;
46         }
47         
48         
49         @Override
50         public boolean equals(Object obj) {
51                 if (this == obj)
52                         return true;
53                 if (!(obj instanceof MassData))
54                         return false;
55                 
56                 MassData other = (MassData) obj;
57                 return (this.cg.equals(other.cg) && MathUtil.equals(this.longitudinalInertia, other.longitudinalInertia) &&
58                                 MathUtil.equals(this.rotationalInertia, other.rotationalInertia)) && MathUtil.equals(this.propellantMass, other.propellantMass) ;
59         }
60
61         
62         @Override
63         public int hashCode() {
64                 return (int) (cg.hashCode() ^ Double.doubleToLongBits(longitudinalInertia) ^ Double.doubleToLongBits(rotationalInertia) ^ Double.doubleToLongBits(propellantMass) );
65         }
66
67
68         @Override
69         public String toString() {
70                 return "MassData [cg=" + cg + ", longitudinalInertia=" + longitudinalInertia
71                                 + ", rotationalInertia=" + rotationalInertia + ", propellantMass="+propellantMass + "]";
72         }
73         
74 }