From: kruland2607 Date: Thu, 12 Jan 2012 19:32:23 +0000 (+0000) Subject: Created static function Motor.Type.fromName( String ) to Motor.Type based on the... X-Git-Tag: upstream/12.03~1^2~129 X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=77f87189269756130a240daa719b1710c10d2dd3;p=debian%2Fopenrocket Created static function Motor.Type.fromName( String ) to Motor.Type based on the logic in RockSimMotorLoader. Use this new lookup method in RockSimMotorLoader. This method was moved because it is useful to have it in Android project motor database. git-svn-id: https://openrocket.svn.sourceforge.net/svnroot/openrocket/trunk@342 180e2498-e6e9-4542-8430-84ac67f01cd8 --- diff --git a/core/src/net/sf/openrocket/file/motor/RockSimMotorLoader.java b/core/src/net/sf/openrocket/file/motor/RockSimMotorLoader.java index d2bbcd26..5b0743e1 100644 --- a/core/src/net/sf/openrocket/file/motor/RockSimMotorLoader.java +++ b/core/src/net/sf/openrocket/file/motor/RockSimMotorLoader.java @@ -234,15 +234,7 @@ public class RockSimMotorLoader extends AbstractMotorLoader { // Motor type str = attributes.get("Type"); - if (str != null && str.equalsIgnoreCase("single-use")) { - type = Motor.Type.SINGLE; - } else if (str != null && str.equalsIgnoreCase("hybrid")) { - type = Motor.Type.HYBRID; - } else if (str != null && str.equalsIgnoreCase("reloadable")) { - type = Motor.Type.RELOAD; - } else { - type = Motor.Type.UNKNOWN; - } + type = Motor.Type.fromName(str); // Calculate mass str = attributes.get("auto-calc-mass"); diff --git a/core/src/net/sf/openrocket/motor/Motor.java b/core/src/net/sf/openrocket/motor/Motor.java index fda0eebb..afe06212 100644 --- a/core/src/net/sf/openrocket/motor/Motor.java +++ b/core/src/net/sf/openrocket/motor/Motor.java @@ -22,6 +22,21 @@ public interface Motor { this.name = name; this.description = description; } + + public static Type fromName( String name ) { + if ( name == null ) { + return UNKNOWN; + } + if ("single-use".equalsIgnoreCase(name)) { + return SINGLE; + } else if ("hybrid".equalsIgnoreCase(name)) { + return HYBRID; + } else if ("reloadable".equalsIgnoreCase(name)) { + return RELOAD; + } else { + return UNKNOWN; + } + } /** * Return a short name of this motor type.