1 package net.sf.openrocket.optimization.rocketoptimization.modifiers;
3 import net.sf.openrocket.document.Simulation;
4 import net.sf.openrocket.optimization.general.OptimizationException;
5 import net.sf.openrocket.rocketcomponent.RocketComponent;
6 import net.sf.openrocket.unit.UnitGroup;
9 * A generic simulation modifier that modifies a value of a certain RocketComponent
10 * based on the component's ID and the value name.
12 * @author Sampo Niskanen <sampo.niskanen@iki.fi>
14 public class GenericComponentModifier extends GenericModifier<RocketComponent> {
16 private final Class<? extends RocketComponent> componentClass;
17 private final String componentId;
22 * @param modifierName the name of this modifier (returned by {@link #getName()})
23 * @param relatedObject the related object (returned by {@link #getRelatedObject()})
24 * @param unitGroup the unit group (returned by {@link #getUnitGroup()})
25 * @param multiplier the multiplier by which the value returned by the getter is multiplied
26 * to obtain the desired value
27 * @param componentClass the RocketComponent class type that is being modified
28 * @param componentId the ID of the component to modify
29 * @param methodName the base name of the getter/setter methods (without "get"/"set")
31 public GenericComponentModifier(String modifierName, Object relatedObject, UnitGroup unitGroup,
32 double multiplier, Class<? extends RocketComponent> componentClass, String componentId, String methodName) {
33 super(modifierName, relatedObject, unitGroup, multiplier, componentClass, methodName);
35 this.componentClass = componentClass;
36 this.componentId = componentId;
40 protected RocketComponent getModifiedObject(Simulation simulation) throws OptimizationException {
41 RocketComponent c = simulation.getRocket().findComponent(componentId);
43 throw new OptimizationException("Could not find component of type " + componentClass.getSimpleName()
44 + " with correct ID");