From 88f5d19185170f0709ffc61128fae50f6c616e83 Mon Sep 17 00:00:00 2001 From: JoePfeiffer Date: Fri, 20 Aug 2021 14:18:26 -0600 Subject: [PATCH] Replace designation with common name in ThrustCurveMotorColumns Get rid of simplified designation in ThrustCurveMotorSet, using common name instead --- core/resources/l10n/messages.properties | 2 +- .../database/motor/ThrustCurveMotorSet.java | 59 +++++-------------- .../thrustcurve/ThrustCurveMotorColumns.java | 6 +- 3 files changed, 18 insertions(+), 49 deletions(-) diff --git a/core/resources/l10n/messages.properties b/core/resources/l10n/messages.properties index 2e2e983e8..42429aac9 100644 --- a/core/resources/l10n/messages.properties +++ b/core/resources/l10n/messages.properties @@ -1588,7 +1588,7 @@ FlightEvent.Type.EXCEPTION = Exception ! ThrustCurveMotorColumns TCurveMotorCol.MANUFACTURER = Manufacturer -TCurveMotorCol.DESIGNATION = Designation +TCurveMotorCol.COMMON_NAME = Name TCurveMotorCol.CASEINFO = Case TCurveMotorCol.DIAMETER = Diameter TCurveMotorCol.LENGTH = Length diff --git a/core/src/net/sf/openrocket/database/motor/ThrustCurveMotorSet.java b/core/src/net/sf/openrocket/database/motor/ThrustCurveMotorSet.java index fe9428976..38479dee5 100644 --- a/core/src/net/sf/openrocket/database/motor/ThrustCurveMotorSet.java +++ b/core/src/net/sf/openrocket/database/motor/ThrustCurveMotorSet.java @@ -38,8 +38,8 @@ public class ThrustCurveMotorSet implements Comparable { private final List delays = new ArrayList(); private Manufacturer manufacturer = null; + private String commonName = null; private String designation = null; - private String simplifiedDesignation = null; private double diameter = -1; private double length = -1; private long totalImpulse = 0; @@ -57,7 +57,6 @@ public class ThrustCurveMotorSet implements Comparable { checkFirstInsertion(motor); verifyMotor(motor); updateType(motor); - checkChangeSimplifiedDesignation(motor); addStandardDelays(motor); if(!checkMotorOverwrite(motor)){ motors.add(motor); @@ -144,23 +143,6 @@ public class ThrustCurveMotorSet implements Comparable { Collections.sort(delays); } - - /** - * checks if simplified designation should be changed with the given motor - * @param motor the motor to be checked with - */ - private void checkChangeSimplifiedDesignation(ThrustCurveMotor motor) { - // Change the simplified designation if necessary - if (!designation.equalsIgnoreCase(motor.getDesignation().trim())) { - designation = simplifiedDesignation; - } - - if (caseInfo == null) { - caseInfo = motor.getCaseInfo(); - } - } - - /** * checks if the cached type should be changed with the given motor * if it's hybrid, delays will be added @@ -206,7 +188,7 @@ public class ThrustCurveMotorSet implements Comparable { if (motors.isEmpty()) { manufacturer = motor.getManufacturer(); designation = motor.getDesignation(); - simplifiedDesignation = simplifyDesignation(designation); + commonName = motor.getCommonName(); diameter = motor.getDiameter(); length = motor.getLength(); totalImpulse = Math.round((motor.getTotalImpulseEstimate())); @@ -239,14 +221,14 @@ public class ThrustCurveMotorSet implements Comparable { return false; } - if (!simplifiedDesignation.equalsIgnoreCase(simplifyDesignation(m.getDesignation()))) + if (!designation.equalsIgnoreCase(m.getDesignation())) return false; if (caseInfo != null && !caseInfo.equalsIgnoreCase(m.getCaseInfo())) return false; return true; - } + } /** * returns a new list with the stored motors @@ -283,11 +265,17 @@ public class ThrustCurveMotorSet implements Comparable { public Manufacturer getManufacturer() { return manufacturer; } - - + /** - * Return the designation of this motor type. This is either the exact or simplified - * designation, depending on what motors have been added. + * Return the common name of this motor type. + * @return the common name + */ + public String getCommonName() { + return commonName; + } + + /** + * Return the designation of this motor type. * @return the designation */ public String getDesignation() { @@ -352,25 +340,6 @@ public class ThrustCurveMotorSet implements Comparable { return "ThrustCurveMotorSet[" + manufacturer + " " + designation + ", type=" + type + ", count=" + motors.size() + "]"; } - - private static final Pattern SIMPLIFY_PATTERN = Pattern.compile("^[0-9]*[ -]*([A-Z][0-9]+).*"); - - /** - * Simplify a motor designation, if possible. This attempts to reduce the designation - * into a simple letter + number notation for the impulse class and average thrust. - * - * @param str the designation to simplify - * @return the simplified designation, or the string itself if the format was not detected - */ - public static String simplifyDesignation(String str) { - str = str.trim(); - Matcher m = SIMPLIFY_PATTERN.matcher(str); - if (m.matches()) { - return m.group(1); - } else { - return str.replaceAll("\\s", ""); - } - } /** * Comparator for deciding in which order to display matching motors. diff --git a/swing/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/ThrustCurveMotorColumns.java b/swing/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/ThrustCurveMotorColumns.java index fcefe9ec3..c502bc817 100644 --- a/swing/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/ThrustCurveMotorColumns.java +++ b/swing/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/ThrustCurveMotorColumns.java @@ -30,11 +30,11 @@ enum ThrustCurveMotorColumns { return Collator.getInstance(); } }, - //// Designation - DESIGNATION("TCurveMotorCol.DESIGNATION") { + //// Common name + COMMON_NAME("TCurveMotorCol.COMMON_NAME") { @Override public String getValue(ThrustCurveMotorSet m) { - return m.getDesignation(); + return m.getCommonName(); } @Override