Added convenience function RocketComponent.getMotorMounts() returning List<MotorMount>.

This commit is contained in:
Kevin Ruland 2012-05-16 06:49:04 +00:00
parent 7420f5c18b
commit ba4ceccf26
2 changed files with 340 additions and 329 deletions

View File

@ -70,15 +70,7 @@ public class EditMotorConfigurationDialog extends JDialog {
this.rocket = rocket; this.rocket = rocket;
ArrayList<MotorMount> mountList = new ArrayList<MotorMount>(); mounts = rocket.getMotorMounts().toArray( new MotorMount[0]) ;
Iterator<RocketComponent> iterator = rocket.iterator();
while (iterator.hasNext()) {
RocketComponent c = iterator.next();
if (c instanceof MotorMount) {
mountList.add((MotorMount) c);
}
}
mounts = mountList.toArray(new MotorMount[0]);

View File

@ -704,7 +704,7 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
throw new IllegalArgumentException("Attempting to load preset of type " + preset.getComponentClass() throw new IllegalArgumentException("Attempting to load preset of type " + preset.getComponentClass()
+ " into component of type " + this.getClass()); + " into component of type " + this.getClass());
} }
*/ */
RocketComponent root = getRoot(); RocketComponent root = getRoot();
final Rocket rocket; final Rocket rocket;
@ -1408,7 +1408,7 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
sb.append("Inconsistent internal state: "); sb.append("Inconsistent internal state: ");
sb.append("this=").append(this).append('[') sb.append("this=").append(this).append('[')
.append(System.identityHashCode(this)).append(']'); .append(System.identityHashCode(this)).append(']');
sb.append(" parent.children=["); sb.append(" parent.children=[");
for (int i = 0; i < parent.children.size(); i++) { for (int i = 0; i < parent.children.size(); i++) {
RocketComponent c = parent.children.get(i); RocketComponent c = parent.children.get(i);
@ -1669,9 +1669,28 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
return iterator(true); return iterator(true);
} }
/**
* Retrieve the List of MotorMounts in the Rocket.
*
* Each element returned will a RocketComponent which implements MotorMount. Further isMotorMount()
* returns true.
*
* @return List<MotorMount>
*/
public final List<MotorMount> getMotorMounts() {
Iterator<RocketComponent> it = iterator();
List<MotorMount> mmts = new ArrayList<MotorMount>();
while (it.hasNext()) {
RocketComponent c = it.next();
if (c instanceof MotorMount) {
if ( ((MotorMount)c).isMotorMount() ) {
mmts.add((MotorMount) c);
}
}
}
return mmts;
}
/** /**
* Compare component equality based on the ID of this component. Only the * Compare component equality based on the ID of this component. Only the