1 package net.sf.openrocket.simulation;
3 import net.sf.openrocket.util.Coordinate;
4 import net.sf.openrocket.util.MathUtil;
7 * An immutable value object containing the mass data of a rocket.
9 * @author Sampo Niskanen <sampo.niskanen@iki.fi>
11 public class MassData {
13 private final Coordinate cg;
14 private final double longitudinalInertia;
15 private final double rotationalInertia;
16 private final double propellantMass;
19 public MassData(Coordinate cg, double longitudinalInertia, double rotationalInertia, double propellantMass) {
21 throw new IllegalArgumentException("cg is null");
24 this.longitudinalInertia = longitudinalInertia;
25 this.rotationalInertia = rotationalInertia;
26 this.propellantMass = propellantMass;
32 public Coordinate getCG() {
36 public double getLongitudinalInertia() {
37 return longitudinalInertia;
40 public double getRotationalInertia() {
41 return rotationalInertia;
44 public double getPropellantMass() {
45 return propellantMass;
50 public boolean equals(Object obj) {
53 if (!(obj instanceof MassData))
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) ;
63 public int hashCode() {
64 return (int) (cg.hashCode() ^ Double.doubleToLongBits(longitudinalInertia) ^ Double.doubleToLongBits(rotationalInertia) ^ Double.doubleToLongBits(propellantMass) );
69 public String toString() {
70 return "MassData [cg=" + cg + ", longitudinalInertia=" + longitudinalInertia
71 + ", rotationalInertia=" + rotationalInertia + ", propellantMass="+propellantMass + "]";