It is a mechanism which allows a module to provide standardized computation method adapted to its internal structure. Method provider can be used by external modules or extension : they can access uniformly to these methods without knowing the implementation of the module.
Generally, method provider are used but not limited to dendrometric measurements, like basal area, height, mean diameters etc…
Each module can provide some of these methods. The modeler can add new method when he want. Capsis detect dynamically the method the module provide.
External tools using this functionality are often extensions like data extractors. They can compute for instance basal area evolution during time by using basal area module method. This extension can be used by any module which provide the method provider, and thus it is possible to combine several evolution plot from different simualtion and different models on the same frame.
All method provider implements the interface MethodProvider capsis.util.methodprovider.MethodProvider
.
abstract public class MyMethodProvider implements MethodProvider { public MyMethodProvider () {} }
The package capsis.util.methodprovider
provides method provider interfaces and default implementation.
Default implementations :
Some Method provider interfaces :
Each interface declare on or several method with a conventional name inspired by the data to compute. For instance, the method to compute a data A will be written like this:
public interface AProvider extends MethodProvider { public double getA (GStand s); }
These interfaces are shared by all the module and should be reused to ensure model compatibility.
For instance for the “sapin” module with 'Sap' prefix :
The model class sapin.model.SapModel
implements a method which returns its Method Provider.
protected MethodProvider createMethodProvider () { return new SapMethodProvider (); }
This method should return an instance of a MethodeProvider. Several solutions are possible :
MethodProvider p = CompositeProvider.create( new Class<?>[] { SpatializedMethodProvider.class, GenericMethodProvider.class });
sapin.model
:public class SapMethodProvider extends SpatializedMethodProvider implements GProvider, DgProvider, HgProvider, NProvider, VProvider, MeanVProvider, GTreeVProvider, CoverProvider {...}
Methods can be written from scratch or reuse inherited methods.
public int getN (GScene stand) { TreeCollection tc = null; try { tc = (TreeCollection) stand; } catch (Exception e) { return -1; } return tc.size (); } public double getG (GScene stand) { return super.getG (stand); }
Method provider are used in extension to determine the compatibility of the module and to calculate some output with the correct method (the one provided by the modeler).
For instance, we consider an extractor to represent the evolution of the basal aera of a stand during time.
The extension first determine if the model is compatible by using the matchWith function :
static public boolean matchWith (Object referent) { try { if (!(referent instanceof GModel)) {return false;} GModel m = (GModel) referent; MethodProvider mp = m.getMethodProvider (); if (!(mp instanceof GProvider)) {return false;} } catch (Exception e) { Log.println (Log.ERROR, "DETimeG.matchWith ()", "Error in matchWith () (returned false)", e); return false; } return true; }
Then, the method which builds the plots will use the “provided method” when necessary :
public boolean doExtraction () { ... methodProvider = step.getProject ().getModel ().getMethodProvider (); ... int date = stand.getDate (); double G = ((GProvider) methodProvider).getG ((GStand) stand) * coefHa; ... }