Changed DatabaseMotorFinder to have a little template pattern in it to make implementing DatabaseMotorFinderWithMissingMotors much easier.

This commit is contained in:
Kevin Ruland 2012-02-05 01:40:57 +00:00
parent 512a82f4c1
commit e2e76e823f
2 changed files with 50 additions and 10 deletions

View File

@ -16,6 +16,27 @@ import net.sf.openrocket.startup.Application;
*/
public class DatabaseMotorFinder implements MotorFinder {
/**
* Do something when a missing motor is found.
*
* This implementation adds a Warning.MissingMotor to the warning set and returns null.
*
* Override this function to change the behavior.
*
* @return The Motor which will be put in the Rocket.
*/
protected Motor handleMissingMotor(Type type, String manufacturer, String designation, double diameter, double length, String digest, WarningSet warnings) {
Warning.MissingMotor mmw = new Warning.MissingMotor();
mmw.setDesignation(designation);
mmw.setDigest(digest);
mmw.setDiameter(diameter);
mmw.setLength(length);
mmw.setManufacturer(manufacturer);
mmw.setType(type);
warnings.add(mmw);
return null;
}
@Override
public Motor findMotor(Type type, String manufacturer, String designation, double diameter, double length, String digest, WarningSet warnings) {
@ -28,16 +49,8 @@ public class DatabaseMotorFinder implements MotorFinder {
// No motors
if (motors.size() == 0) {
Warning.MissingMotor mmw = new Warning.MissingMotor();
mmw.setDesignation(designation);
mmw.setDigest(digest);
mmw.setDiameter(diameter);
mmw.setLength(length);
mmw.setManufacturer(manufacturer);
mmw.setType(type);
warnings.add(mmw);
return null;
}
return handleMissingMotor(type, manufacturer, designation, diameter, length, digest, warnings);
}
// One motor
if (motors.size() == 1) {

View File

@ -0,0 +1,27 @@
package net.sf.openrocket.file;
import net.sf.openrocket.aerodynamics.WarningSet;
import net.sf.openrocket.motor.Motor;
import net.sf.openrocket.motor.Motor.Type;
import net.sf.openrocket.motor.ThrustCurveMotorPlaceholder;
public class DatabaseMotorFinderWithMissingMotors extends DatabaseMotorFinder
implements MotorFinder {
/**
* This implementation returns a ThrustCurveMotorPlaceholder.
*/
@Override
protected Motor handleMissingMotor(Type type, String manufacturer, String designation, double diameter, double length, String digest, WarningSet warnings) {
Motor motor = new ThrustCurveMotorPlaceholder(type,
manufacturer,
designation,
diameter,
length,
digest,
/* delay */ Double.NaN,
/*launchMass*/ Double.NaN,
/*emptyMass*/ Double.NaN);
return motor;
}
}