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