Changed DatabaseMotorFinder to have a little template pattern in it to make implement...
authorkruland2607 <kruland2607@180e2498-e6e9-4542-8430-84ac67f01cd8>
Sun, 5 Feb 2012 01:40:57 +0000 (01:40 +0000)
committerkruland2607 <kruland2607@180e2498-e6e9-4542-8430-84ac67f01cd8>
Sun, 5 Feb 2012 01:40:57 +0000 (01:40 +0000)
git-svn-id: https://openrocket.svn.sourceforge.net/svnroot/openrocket/trunk@390 180e2498-e6e9-4542-8430-84ac67f01cd8

core/src/net/sf/openrocket/file/DatabaseMotorFinder.java
core/src/net/sf/openrocket/file/DatabaseMotorFinderWithMissingMotors.java [new file with mode: 0644]

index 9af7a739193d5e6c7239987d98c38f2e814119e4..0232bbd1b11744a5f978f98f1baa16ccbb3baad3 100644 (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) {
diff --git a/core/src/net/sf/openrocket/file/DatabaseMotorFinderWithMissingMotors.java b/core/src/net/sf/openrocket/file/DatabaseMotorFinderWithMissingMotors.java
new file mode 100644 (file)
index 0000000..5270151
--- /dev/null
@@ -0,0 +1,27 @@
+package net.sf.openrocket.file;\r
+\r
+import net.sf.openrocket.aerodynamics.WarningSet;\r
+import net.sf.openrocket.motor.Motor;\r
+import net.sf.openrocket.motor.Motor.Type;\r
+import net.sf.openrocket.motor.ThrustCurveMotorPlaceholder;\r
+\r
+public class DatabaseMotorFinderWithMissingMotors extends DatabaseMotorFinder\r
+implements MotorFinder {\r
+\r
+       /**\r
+        * This implementation returns a ThrustCurveMotorPlaceholder.\r
+        */\r
+       @Override\r
+       protected Motor handleMissingMotor(Type type, String manufacturer, String designation, double diameter, double length, String digest, WarningSet warnings) {\r
+               Motor motor = new ThrustCurveMotorPlaceholder(type,\r
+                               manufacturer,\r
+                               designation,\r
+                               diameter,\r
+                               length,\r
+                               digest,\r
+                               /* delay */ Double.NaN,\r
+                               /*launchMass*/ Double.NaN,\r
+                               /*emptyMass*/ Double.NaN);\r
+               return motor;\r
+       }\r
+}\r