1 package net.sf.openrocket.motor;
4 * An immutable identifier for a motor instance in a MotorInstanceConfiguration.
5 * The motor is identified by the ID of its mounting component and a
6 * positive motor count number.
8 * @author Sampo Niskanen <sampo.niskanen@iki.fi>
10 public final class MotorId {
12 private final String componentId;
13 private final int number;
19 * @param componentId the component ID, must not be null
20 * @param number a positive motor doun5 number
22 public MotorId(String componentId, int number) {
25 if (componentId == null) {
26 throw new IllegalArgumentException("Component ID was null");
29 throw new IllegalArgumentException("Number must be positive, n=" + number);
32 // Use intern so comparison can be done using == instead of equals()
33 this.componentId = componentId.intern();
38 public String getComponentId() {
42 public int getNumber() {
48 public boolean equals(Object o) {
52 if (!(o instanceof MotorId))
55 MotorId other = (MotorId)o;
56 // Comparison with == ok since string is intern()'ed
57 return this.componentId == other.componentId && this.number == other.number;
62 public int hashCode() {
63 return componentId.hashCode() + (number << 12);