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 modifierDescription the description of this modifier (returned by {@link #getDescription()})
24 * @param relatedObject the related object (returned by {@link #getRelatedObject()})
25 * @param unitGroup the unit group (returned by {@link #getUnitGroup()})
26 * @param multiplier the multiplier by which the value returned by the getter is multiplied
27 * to obtain the desired value
28 * @param componentClass the RocketComponent class type that is being modified
29 * @param componentId the ID of the component to modify
30 * @param methodName the base name of the getter/setter methods (without "get"/"set")
32 public GenericComponentModifier(String modifierName, String modifierDescription, Object relatedObject, UnitGroup unitGroup,
33 double multiplier, Class<? extends RocketComponent> componentClass, String componentId, String methodName) {
34 super(modifierName, modifierDescription, relatedObject, unitGroup, multiplier, componentClass, methodName);
36 this.componentClass = componentClass;
37 this.componentId = componentId;
41 protected RocketComponent getModifiedObject(Simulation simulation) throws OptimizationException {
42 RocketComponent c = simulation.getRocket().findComponent(componentId);
44 throw new OptimizationException("Could not find component of type " + componentClass.getSimpleName()
45 + " with correct ID");