X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fnet%2Fsf%2Fopenrocket%2Fdatabase%2FThrustCurveMotorSet.java;h=99c422e314c1a515217e5e758539e98ce799cac4;hb=f8f9a3cc430a2d4893de6157e483889439f33cc3;hp=afffd30bbe961a850a04437fd8aaefcc9afc4bae;hpb=4e356b38bfc24fc25a2fcf0ddbf0dee3a72d5f41;p=debian%2Fopenrocket diff --git a/src/net/sf/openrocket/database/ThrustCurveMotorSet.java b/src/net/sf/openrocket/database/ThrustCurveMotorSet.java index afffd30b..99c422e3 100644 --- a/src/net/sf/openrocket/database/ThrustCurveMotorSet.java +++ b/src/net/sf/openrocket/database/ThrustCurveMotorSet.java @@ -1,7 +1,6 @@ package net.sf.openrocket.database; import java.text.Collator; -import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.IdentityHashMap; @@ -13,14 +12,15 @@ import java.util.regex.Pattern; import net.sf.openrocket.motor.DesignationComparator; import net.sf.openrocket.motor.Manufacturer; -import net.sf.openrocket.motor.MotorDigest; import net.sf.openrocket.motor.Motor; -import net.sf.openrocket.motor.ThrustCurveMotor; import net.sf.openrocket.motor.Motor.Type; +import net.sf.openrocket.motor.MotorDigest; +import net.sf.openrocket.motor.ThrustCurveMotor; +import net.sf.openrocket.util.ArrayList; import net.sf.openrocket.util.MathUtil; public class ThrustCurveMotorSet implements Comparable { - + // Comparators: private static final Collator COLLATOR = Collator.getInstance(Locale.US); static { @@ -28,12 +28,12 @@ public class ThrustCurveMotorSet implements Comparable { } private static final DesignationComparator DESIGNATION_COMPARATOR = new DesignationComparator(); private static final ThrustCurveMotorComparator comparator = new ThrustCurveMotorComparator(); - - + + private final ArrayList motors = new ArrayList(); private final Map digestMap = - new IdentityHashMap(); + new IdentityHashMap(); private final List delays = new ArrayList(); @@ -45,7 +45,7 @@ public class ThrustCurveMotorSet implements Comparable { private Motor.Type type = Motor.Type.UNKNOWN; - + public void addMotor(ThrustCurveMotor motor) { // Check for first insertion @@ -60,8 +60,8 @@ public class ThrustCurveMotorSet implements Comparable { // Verify that the motor can be added if (!matches(motor)) { throw new IllegalArgumentException("Motor does not match the set:" + - " manufacturer="+manufacturer + - " designation="+designation + + " manufacturer=" + manufacturer + + " designation=" + designation + " diameter=" + diameter + " length=" + length + " set_size=" + motors.size() + @@ -71,6 +71,12 @@ public class ThrustCurveMotorSet implements Comparable { // Update the type if now known if (type == Motor.Type.UNKNOWN) { type = motor.getMotorType(); + // Add "Plugged" option if hybrid + if (type == Motor.Type.HYBRID) { + if (!delays.contains(Motor.PLUGGED)) { + delays.add(Motor.PLUGGED); + } + } } // Change the simplified designation if necessary @@ -79,23 +85,25 @@ public class ThrustCurveMotorSet implements Comparable { } // Add the standard delays - for (double d: motor.getStandardDelays()) { + for (double d : motor.getStandardDelays()) { d = Math.rint(d); - delays.add(d); + if (!delays.contains(d)) { + delays.add(d); + } } Collections.sort(delays); - + // Check whether to add as new motor or overwrite existing final String digest = MotorDigest.digestMotor(motor); for (int index = 0; index < motors.size(); index++) { Motor m = motors.get(index); - + if (digest.equals(digestMap.get(m)) && motor.getDesignation().equals(m.getDesignation())) { - + // Match found, check which one to keep (or both) based on comment - String newCmt = motor.getDescription().replaceAll("\\s+"," ").trim(); + String newCmt = motor.getDescription().replaceAll("\\s+", " ").trim(); String oldCmt = m.getDescription().replaceAll("\\s+", " ").trim(); if (newCmt.length() == 0 || newCmt.equals(oldCmt)) { @@ -123,7 +131,7 @@ public class ThrustCurveMotorSet implements Comparable { public boolean matches(ThrustCurveMotor m) { if (motors.isEmpty()) return true; - + if (manufacturer != m.getManufacturer()) return false; @@ -133,7 +141,7 @@ public class ThrustCurveMotorSet implements Comparable { if (!MathUtil.equals(length, m.getLength())) return false; - if ((type != Type.UNKNOWN) && (m.getMotorType()!= Type.UNKNOWN) && + if ((type != Type.UNKNOWN) && (m.getMotorType() != Type.UNKNOWN) && (type != m.getMotorType())) { return false; } @@ -143,14 +151,17 @@ public class ThrustCurveMotorSet implements Comparable { return true; } - - @SuppressWarnings("unchecked") + public List getMotors() { - return (List) motors.clone(); + return motors.clone(); } + public int getMotorCount() { + return motors.size(); + } + /** * Return the standard delays applicable to this motor type. This is a union of @@ -160,8 +171,8 @@ public class ThrustCurveMotorSet implements Comparable { public List getDelays() { return Collections.unmodifiableList(delays); } - - + + /** * Return the manufacturer of this motor type. * @return the manufacturer @@ -169,8 +180,8 @@ 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. @@ -179,8 +190,8 @@ public class ThrustCurveMotorSet implements Comparable { public String getDesignation() { return designation; } - - + + /** * Return the diameter of this motor type. * @return the diameter @@ -188,8 +199,8 @@ public class ThrustCurveMotorSet implements Comparable { public double getDiameter() { return diameter; } - - + + /** * Return the length of this motor type. * @return the length @@ -197,8 +208,8 @@ public class ThrustCurveMotorSet implements Comparable { public double getLength() { return length; } - - + + /** * Return the type of this motor type. If any of the added motors has a type different * from UNKNOWN, then that type will be returned. @@ -207,12 +218,21 @@ public class ThrustCurveMotorSet implements Comparable { public Motor.Type getType() { return type; } + + - + @Override + public String toString() { + 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. @@ -235,7 +255,7 @@ public class ThrustCurveMotorSet implements Comparable { * Comparator for deciding in which order to display matching motors. */ private static class ThrustCurveMotorComparator implements Comparator { - + @Override public int compare(ThrustCurveMotor o1, ThrustCurveMotor o2) { // 1. Designation @@ -253,15 +273,15 @@ public class ThrustCurveMotorSet implements Comparable { } } - - + + @Override public int compareTo(ThrustCurveMotorSet other) { - + int value; // 1. Manufacturer - value = COLLATOR.compare(this.manufacturer.getDisplayName(), + value = COLLATOR.compare(this.manufacturer.getDisplayName(), other.manufacturer.getDisplayName()); if (value != 0) return value; @@ -272,12 +292,12 @@ public class ThrustCurveMotorSet implements Comparable { return value; // 3. Diameter - value = (int)((this.diameter - other.diameter)*1000000); + value = (int) ((this.diameter - other.diameter) * 1000000); if (value != 0) return value; - + // 4. Length - value = (int)((this.length - other.length)*1000000); + value = (int) ((this.length - other.length) * 1000000); return value; }