View Javadoc

1   /*
2    * Copyright 2006 - 2012 Christina Bohk and Roland Ewald
3    *  
4    * Licensed under the Apache License, Version 2.0 (the "License"); 
5    * you may not use this file except in compliance with the License. 
6    * You may obtain a copy of the License at 
7    *  
8    *  http://www.apache.org/licenses/LICENSE-2.0
9    *  
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
13   * See the License for the specific language governing permissions and 
14   * limitations under the License. 
15   */
16  package p3j.pppm;
17  
18  import java.util.ArrayList;
19  import java.util.Calendar;
20  import java.util.List;
21  
22  import org.jamesii.core.model.IModel;
23  import org.jamesii.core.model.formalism.Formalism;
24  import org.jamesii.core.model.plugintype.ModelFactory;
25  import org.jamesii.core.model.symbolic.ISymbolicModel;
26  
27  /**
28   * Creates {@link ProjectionModel} instances.
29   * 
30   * @author Christina Bohk
31   * @author Roland Ewald
32   * 
33   */
34  public class PPPModelFactory extends ModelFactory {
35  
36    /** Serialization ID. */
37    private static final long serialVersionUID = -8959309833233820296L;
38  
39    /** Default number of generations. */
40    public static final int DEFAULT_GENERATIONS = 2;
41  
42    /** Default number of years to be predicted. */
43    public static final int DEFAULT_YEARS = 10;
44  
45    /** Default maximum age. */
46    public static final int DEFAULT_MAX_AGE = 100;
47  
48    /** The default calendar year. */
49    public static final int DEFAULT_JUMP_OFF_YEAR = Calendar.getInstance().get(
50        Calendar.YEAR);
51  
52    /** The default model of sub-populations. */
53    public static final SubPopulationModel DEFAULT_SUBPOPULATION_MODEL = createDefaultSubPopulationModel();
54  
55    @Override
56    public ISymbolicModel<?> create() {
57      return new SymbolicProjectionModel(createDefaultModel());
58    }
59  
60    @Override
61    public Formalism getFormalism() {
62      return new PPPMFormalism();
63    }
64  
65    @Override
66    public List<Class<? extends IModel>> getSupportedInterfaces() {
67      ArrayList<Class<? extends IModel>> suppInterfaces = new ArrayList<Class<? extends IModel>>();
68      suppInterfaces.add(IProjectionModel.class);
69      return suppInterfaces;
70    }
71  
72    /**
73     * Creates a default {@link ProjectionModel}.
74     * 
75     * @return the projection model
76     */
77    public static ProjectionModel createDefaultModel() {
78      return createModel("New Projection", "No description entered.",
79          DEFAULT_GENERATIONS, DEFAULT_YEARS, DEFAULT_MAX_AGE,
80          DEFAULT_JUMP_OFF_YEAR, DEFAULT_SUBPOPULATION_MODEL);
81    }
82  
83    /**
84     * Creates the default sub-population model (natives, immigrants, and
85     * emigrants).
86     * 
87     * @return the sub-population model
88     */
89    public static SubPopulationModel createDefaultSubPopulationModel() {
90      SubPopulationModel defaultModel = new SubPopulationModel();
91      defaultModel.getSubPopulations().add(
92          new SubPopulation("Natives", true, true, false));
93      defaultModel.getSubPopulations().add(
94          new SubPopulation("Immigrants", false, true, true));
95      defaultModel.getSubPopulations().add(
96          new SubPopulation("Emigrants", false, false, true));
97      return defaultModel;
98    }
99  
100   /**
101    * Creates a new PPPModel object.
102    * 
103    * @param name
104    *          the name
105    * @param description
106    *          the description
107    * @param generations
108    *          the number of generations
109    * @param years
110    *          the number of years
111    * @param maxAge
112    *          the maximum age
113    * @param jumpOffYear
114    *          the jump-off year
115    * @param subPopModel
116    *          the model of sub-populations
117    * @return the projection model
118    */
119   public static ProjectionModel createModel(String name, String description,
120       int generations, int years, int maxAge, int jumpOffYear,
121       SubPopulationModel subPopModel) {
122     return new ProjectionModel(name, description, generations, years, maxAge,
123         jumpOffYear, subPopModel);
124   }
125 
126 }