- if (designation == null) {
- warnings.add(Warning.fromString("No motor specified, ignoring."));
- return null;
- }
-
- List<? extends Motor> motors = Application.getMotorSetDatabase().findMotors(type, manufacturer,
- designation, diameter, length);
-
- // 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;
- }
-
- // One motor
- if (motors.size() == 1) {
- Motor m = motors.get(0);
- if (digest != null && !digest.equals(m.getDigest())) {
- String str = "Motor with designation '" + designation + "'";
- if (manufacturer != null)
- str += " for manufacturer '" + manufacturer + "'";
- str += " has differing thrust curve than the original.";
- warnings.add(str);
- }
- return m;
- }
-
- // Multiple motors, check digest for which one to use
- if (digest != null) {
-
- // Check for motor with correct digest
- for (Motor m : motors) {
- if (digest.equals(m.getDigest())) {
- return m;
- }
- }
- String str = "Motor with designation '" + designation + "'";
- if (manufacturer != null)
- str += " for manufacturer '" + manufacturer + "'";
- str += " has differing thrust curve than the original.";
- warnings.add(str);
-
- } else {
-
- // No digest, check for preferred digest (OpenRocket <= 1.1.0)
- // TODO: MEDIUM: This should only be done for document versions 1.1 and below
- for (Motor m : motors) {
- if (PreferredMotorDigests.DIGESTS.contains(m.getDigest())) {
- return m;
- }
- }
-
- String str = "Multiple motors with designation '" + designation + "'";
- if (manufacturer != null)
- str += " for manufacturer '" + manufacturer + "'";
- str += " found, one chosen arbitrarily.";
- warnings.add(str);
-
- }
- return motors.get(0);