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 james.core.model.IModel;
19  import james.core.model.formalism.Formalism;
20  import james.core.model.plugintype.ModelFactory;
21  import james.core.model.symbolic.ISymbolicModel;
22  
23  import java.util.ArrayList;
24  import java.util.Calendar;
25  import java.util.List;
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  	@Override
53  	public ISymbolicModel<?> create() {
54  		return new SymbolicProjectionModel(createDefaultModel());
55  	}
56  
57  	@Override
58  	public Formalism getFormalism() {
59  		return new PPPMFormalism();
60  	}
61  
62  	@Override
63  	public List<Class<? extends IModel>> getSupportedInterfaces() {
64  		ArrayList<Class<? extends IModel>> suppInterfaces = new ArrayList<Class<? extends IModel>>();
65  		suppInterfaces.add(IProjectionModel.class);
66  		return suppInterfaces;
67  	}
68  
69  	/**
70  	 * Creates a default {@link ProjectionModel}.
71  	 * 
72  	 * @return the projection model
73  	 */
74  	public ProjectionModel createDefaultModel() {
75  		return createModel("New Projection", "No description entered.",
76  		    DEFAULT_GENERATIONS, DEFAULT_YEARS, DEFAULT_MAX_AGE,
77  		    DEFAULT_JUMP_OFF_YEAR);
78  	}
79  
80  	/**
81  	 * Creates a new PPPModel object.
82  	 * 
83  	 * @param name
84  	 *          the name
85  	 * @param description
86  	 *          the description
87  	 * @param generations
88  	 *          the number of generations
89  	 * @param years
90  	 *          the number of years
91  	 * @param maxAge
92  	 *          the maximum age
93  	 * @param jumpOffYear
94  	 *          the jump-off year
95  	 * @return the projection model
96  	 */
97  	public ProjectionModel createModel(String name, String description,
98  	    int generations, int years, int maxAge, int jumpOffYear) {
99  		return new ProjectionModel(name, description, generations, years, maxAge,
100 		    jumpOffYear);
101 	}
102 
103 }