1d910df0a751f0a0e1edfe84f8647002c4697115
[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         
17         
18         public MassData(Coordinate cg, double longitudinalInertia, double rotationalInertia) {
19                 if (cg == null) {
20                         throw new IllegalArgumentException("cg is null");
21                 }
22                 this.cg = cg;
23                 this.longitudinalInertia = longitudinalInertia;
24                 this.rotationalInertia = rotationalInertia;
25         }
26
27         
28         
29         
30         public Coordinate getCG() {
31                 return cg;
32         }
33         
34         public double getLongitudinalInertia() {
35                 return longitudinalInertia;
36         }
37         
38         public double getRotationalInertia() {
39                 return rotationalInertia;
40         }
41
42         
43         
44         @Override
45         public boolean equals(Object obj) {
46                 if (this == obj)
47                         return true;
48                 if (!(obj instanceof MassData))
49                         return false;
50                 
51                 MassData other = (MassData) obj;
52                 return (this.cg.equals(other.cg) && MathUtil.equals(this.longitudinalInertia, other.longitudinalInertia) &&
53                                 MathUtil.equals(this.rotationalInertia, other.rotationalInertia));
54         }
55
56         
57         @Override
58         public int hashCode() {
59                 return (int) (cg.hashCode() ^ Double.doubleToLongBits(longitudinalInertia) ^ Double.doubleToLongBits(rotationalInertia));
60         }
61
62
63         @Override
64         public String toString() {
65                 return "MassData [cg=" + cg + ", longitudinalInertia=" + longitudinalInertia
66                                 + ", rotationalInertia=" + rotationalInertia + "]";
67         }
68         
69 }