cfcf496bcdb1afffd2e61a3714b114145d3f44c6
[debian/openrocket] / src / net / sf / openrocket / masscalc / AbstractMassCalculator.java
1 package net.sf.openrocket.masscalc;
2
3 import net.sf.openrocket.rocketcomponent.Configuration;
4
5 /**
6  * Abstract base for mass calculators.  Provides functionality for cacheing mass data.
7  * 
8  * @author Sampo Niskanen <sampo.niskanen@iki.fi>
9  */
10 public abstract class AbstractMassCalculator implements MassCalculator {
11         
12         private int rocketMassModID = -1;
13         private int stageCount = -1;
14         
15         
16         /**
17          * Check the current cache consistency.  This method must be called by all
18          * methods that may use any cached data before any other operations are
19          * performed.  If the rocket has changed since the previous call to
20          * <code>checkCache()</code>, then {@link #voidMassCache()} is called.
21          * <p>
22          * This method performs the checking based on the rocket's modification IDs,
23          * so that these method may be called from listeners of the rocket itself.
24          * 
25          * @param       configuration   the configuration of the current call
26          */
27         protected final void checkCache(Configuration configuration) {
28                 if (rocketMassModID != configuration.getRocket().getMassModID() ||
29                                 stageCount != configuration.getStageCount()) {
30                         rocketMassModID = configuration.getRocket().getMassModID();
31                         stageCount = configuration.getStageCount();
32                         voidMassCache();
33                 }
34         }
35         
36         
37
38         /**
39          * Void cached mass data.  This method is called whenever a change occurs in 
40          * the rocket structure that affects the mass of the rocket and when a new 
41          * Rocket is used.  This method must be overridden to void any cached data 
42          * necessary.  The method must call <code>super.voidMassCache()</code> during 
43          * its execution.
44          */
45         protected void voidMassCache() {
46                 // No-op
47         }
48         
49 }