1 package net.sf.openrocket.masscalc;
3 import net.sf.openrocket.logging.LogHelper;
4 import net.sf.openrocket.rocketcomponent.Configuration;
5 import net.sf.openrocket.startup.Application;
8 * Abstract base for mass calculators. Provides functionality for cacheing mass data.
10 * @author Sampo Niskanen <sampo.niskanen@iki.fi>
12 public abstract class AbstractMassCalculator implements MassCalculator {
13 private static final LogHelper log = Application.getLogger();
15 private int rocketMassModID = -1;
16 private int rocketTreeModID = -1;
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.
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.
28 * @param configuration the configuration of the current call
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");
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
49 protected void voidMassCache() {