package net.sf.openrocket.unit;
+import net.sf.openrocket.util.MathUtil;
+
/**
* A class representing an SI value and a unit. The toString() method yields the
* current value in the current units. This class may be used to encapsulate
public Value(double value, UnitGroup group) {
this(value, group.getDefaultUnit());
}
-
+
/**
* Get the value of this object.
public double getValue() {
return value;
}
-
+
/**
* Set the value of this object.
*
this.value = unit.fromUnit(value);
}
-
+
/**
* Get the unit of this object.
*
public Unit getUnit() {
return unit;
}
-
+
/**
* Set the value of this object.
*
public String toString() {
return unit.toStringUnit(value);
}
+
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+
+ Value other = (Value) obj;
+ if (this.unit != other.unit) {
+ return false;
+ }
+
+ if (!MathUtil.equals(this.value, other.value)) {
+ return false;
+ }
+
+ return true;
+ }
+
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((unit == null) ? 0 : unit.hashCode());
+ long temp;
+ temp = Double.doubleToLongBits(value);
+ result = prime * result + (int) (temp ^ (temp >>> 32));
+ return result;
+ }
/**
else
return 0;
}
-
+
}