Changed DatabaseMotorFinder to have a little template pattern in it to make implementing DatabaseMotorFinderWithMissingMotors much easier.
This commit is contained in:
parent
512a82f4c1
commit
e2e76e823f
@ -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) {
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user