create changelog entry
[debian/openrocket] / core / src / net / sf / openrocket / optimization / rocketoptimization / modifiers / GenericComponentModifier.java
1 package net.sf.openrocket.optimization.rocketoptimization.modifiers;
2
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;
7
8 /**
9  * A generic simulation modifier that modifies a value of a certain RocketComponent
10  * based on the component's ID and the value name.
11  * 
12  * @author Sampo Niskanen <sampo.niskanen@iki.fi>
13  */
14 public class GenericComponentModifier extends GenericModifier<RocketComponent> {
15         
16         private final Class<? extends RocketComponent> componentClass;
17         private final String componentId;
18         
19         /**
20          * Sole constructor.
21          * 
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")
31          */
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);
35                 
36                 this.componentClass = componentClass;
37                 this.componentId = componentId;
38         }
39         
40         @Override
41         protected RocketComponent getModifiedObject(Simulation simulation) throws OptimizationException {
42                 RocketComponent c = simulation.getRocket().findComponent(componentId);
43                 if (c == null) {
44                         throw new OptimizationException("Could not find component of type " + componentClass.getSimpleName()
45                                         + " with correct ID");
46                 }
47                 return c;
48         }
49         
50 }