commit
201de6a6de
@ -17,10 +17,7 @@ public interface MotorDatabase {
|
|||||||
* @param length the length, or NaN.
|
* @param length the length, or NaN.
|
||||||
* @return a list of all the matching motors.
|
* @return a list of all the matching motors.
|
||||||
*/
|
*/
|
||||||
public List<? extends Motor> findMotors(Motor.Type type,
|
public List<? extends Motor> findMotors(String digest, Motor.Type type,
|
||||||
String manufacturer, String designation, double diameter,
|
String manufacturer, String designation, double diameter,
|
||||||
double length);
|
double length);
|
||||||
|
|
||||||
public Motor findMotor(String digest);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,9 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import net.sf.openrocket.motor.Motor;
|
import net.sf.openrocket.motor.Motor;
|
||||||
import net.sf.openrocket.motor.ThrustCurveMotor;
|
import net.sf.openrocket.motor.ThrustCurveMotor;
|
||||||
|
|
||||||
@ -14,51 +17,59 @@ import net.sf.openrocket.motor.ThrustCurveMotor;
|
|||||||
* @author Sampo Niskanen <sampo.niskanen@iki.fi>
|
* @author Sampo Niskanen <sampo.niskanen@iki.fi>
|
||||||
*/
|
*/
|
||||||
public class ThrustCurveMotorSetDatabase implements MotorDatabase {
|
public class ThrustCurveMotorSetDatabase implements MotorDatabase {
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(ThrustCurveMotorSetDatabase.class);
|
||||||
|
|
||||||
private final List<ThrustCurveMotorSet> motorSets = new ArrayList<ThrustCurveMotorSet>();
|
private final List<ThrustCurveMotorSet> motorSets = new ArrayList<ThrustCurveMotorSet>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ThrustCurveMotor findMotor(String digest) {
|
public List<ThrustCurveMotor> findMotors(String digest, Motor.Type type, String manufacturer, String designation,
|
||||||
if (digest == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
for (ThrustCurveMotorSet set : motorSets) {
|
|
||||||
for (ThrustCurveMotor m : set.getMotors()) {
|
|
||||||
if (digest.equals(m.getDigest())) {
|
|
||||||
return m;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<ThrustCurveMotor> findMotors(Motor.Type type, String manufacturer, String designation,
|
|
||||||
double diameter, double length) {
|
double diameter, double length) {
|
||||||
ArrayList<ThrustCurveMotor> results = new ArrayList<ThrustCurveMotor>();
|
ArrayList<ThrustCurveMotor> fullMatches = new ArrayList<ThrustCurveMotor>();
|
||||||
|
ArrayList<ThrustCurveMotor> digestMatches = new ArrayList<ThrustCurveMotor>();
|
||||||
|
ArrayList<ThrustCurveMotor> descriptionMatches = new ArrayList<ThrustCurveMotor>();
|
||||||
|
|
||||||
|
// Apply filters to see if we can find any motors that match the given criteria. We'll return
|
||||||
|
// the most restrictive nonempty list we find, or empty list if no matches at all
|
||||||
for (ThrustCurveMotorSet set : motorSets) {
|
for (ThrustCurveMotorSet set : motorSets) {
|
||||||
for (ThrustCurveMotor m : set.getMotors()) {
|
for (ThrustCurveMotor m : set.getMotors()) {
|
||||||
boolean match = true;
|
boolean matchDescription = true;
|
||||||
|
boolean matchDigest = true;
|
||||||
|
|
||||||
|
// unlike the description, digest must be present in search criteria to get a match
|
||||||
|
if (digest == null || digest != m.getDigest())
|
||||||
|
matchDigest = false;
|
||||||
|
|
||||||
|
// match description
|
||||||
if (type != null && type != set.getType())
|
if (type != null && type != set.getType())
|
||||||
match = false;
|
matchDescription = false;
|
||||||
else if (manufacturer != null && !m.getManufacturer().matches(manufacturer))
|
else if (manufacturer != null && !m.getManufacturer().matches(manufacturer))
|
||||||
match = false;
|
matchDescription = false;
|
||||||
else if (designation != null && !designation.equalsIgnoreCase(m.getDesignation()))
|
else if (designation != null && !designation.equalsIgnoreCase(m.getDesignation()))
|
||||||
match = false;
|
matchDescription = false;
|
||||||
else if (!Double.isNaN(diameter) && (Math.abs(diameter - m.getDiameter()) > 0.005))
|
else if (!Double.isNaN(diameter) && (Math.abs(diameter - m.getDiameter()) > 0.005))
|
||||||
match = false;
|
matchDescription = false;
|
||||||
else if (!Double.isNaN(length) && (Math.abs(length - m.getLength()) > 0.005))
|
else if (!Double.isNaN(length) && (Math.abs(length - m.getLength()) > 0.005))
|
||||||
match = false;
|
matchDescription = false;
|
||||||
|
|
||||||
if (match)
|
if (matchDigest)
|
||||||
results.add(m);
|
digestMatches.add(m);
|
||||||
|
|
||||||
|
if (matchDescription)
|
||||||
|
descriptionMatches.add(m);
|
||||||
|
|
||||||
|
if (matchDigest && matchDescription)
|
||||||
|
fullMatches.add(m);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return results;
|
if (!fullMatches.isEmpty())
|
||||||
|
return fullMatches;
|
||||||
|
|
||||||
|
if (!digestMatches.isEmpty())
|
||||||
|
return digestMatches;
|
||||||
|
|
||||||
|
return descriptionMatches;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,6 +3,9 @@ package net.sf.openrocket.file;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import net.sf.openrocket.aerodynamics.Warning;
|
import net.sf.openrocket.aerodynamics.Warning;
|
||||||
import net.sf.openrocket.aerodynamics.WarningSet;
|
import net.sf.openrocket.aerodynamics.WarningSet;
|
||||||
import net.sf.openrocket.motor.Motor;
|
import net.sf.openrocket.motor.Motor;
|
||||||
@ -16,6 +19,7 @@ import net.sf.openrocket.startup.Application;
|
|||||||
* @author Sampo Niskanen <sampo.niskanen@iki.fi>
|
* @author Sampo Niskanen <sampo.niskanen@iki.fi>
|
||||||
*/
|
*/
|
||||||
public class DatabaseMotorFinder implements MotorFinder {
|
public class DatabaseMotorFinder implements MotorFinder {
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(DatabaseMotorFinder.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Do something when a missing motor is found.
|
* Do something when a missing motor is found.
|
||||||
@ -40,6 +44,8 @@ public class DatabaseMotorFinder implements MotorFinder {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Motor findMotor(Type type, String manufacturer, String designation, double diameter, double length, String digest, WarningSet warnings) {
|
public Motor findMotor(Type type, String manufacturer, String designation, double diameter, double length, String digest, WarningSet warnings) {
|
||||||
|
|
||||||
|
log.debug("type " + type + ", manufacturer " + manufacturer + ", designation " + designation + ", diameter " + diameter + ", length " + length + ", digest " + digest + ", warnings " + warnings);
|
||||||
|
|
||||||
if (designation == null) {
|
if (designation == null) {
|
||||||
warnings.add(Warning.fromString("No motor specified, ignoring."));
|
warnings.add(Warning.fromString("No motor specified, ignoring."));
|
||||||
@ -48,14 +54,7 @@ public class DatabaseMotorFinder implements MotorFinder {
|
|||||||
|
|
||||||
List<? extends Motor> motors;
|
List<? extends Motor> motors;
|
||||||
|
|
||||||
{
|
motors = Application.getMotorSetDatabase().findMotors(digest, type, manufacturer, designation, diameter, length);
|
||||||
Motor m = Application.getMotorSetDatabase().findMotor(digest);
|
|
||||||
if (m != null) {
|
|
||||||
motors = Collections.<Motor> singletonList(m);
|
|
||||||
} else {
|
|
||||||
motors = Application.getMotorSetDatabase().findMotors(type, manufacturer, designation, diameter, length);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// No motors
|
// No motors
|
||||||
if (motors.size() == 0) {
|
if (motors.size() == 0) {
|
||||||
@ -65,6 +64,9 @@ public class DatabaseMotorFinder implements MotorFinder {
|
|||||||
// One motor
|
// One motor
|
||||||
if (motors.size() == 1) {
|
if (motors.size() == 1) {
|
||||||
Motor m = motors.get(0);
|
Motor m = motors.get(0);
|
||||||
|
|
||||||
|
log.debug("motor is " + m.getDesignation());
|
||||||
|
|
||||||
if (digest != null && !digest.equals(m.getDigest())) {
|
if (digest != null && !digest.equals(m.getDigest())) {
|
||||||
String str = "Motor with designation '" + designation + "'";
|
String str = "Motor with designation '" + designation + "'";
|
||||||
if (manufacturer != null)
|
if (manufacturer != null)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user