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.parameters;
17  
18  import java.io.Serializable;
19  
20  import p3j.misc.MatrixDimension;
21  import p3j.misc.math.Matrix2D;
22  
23  /**
24   * Represents a parameter instance for the PPPM. This 'instantiates' a
25   * {@link Parameter} (which might be generation dependent) for a certain
26   * generation. Apart from that, this class also defines a comparison index,
27   * which is mostly defined for interaction with the user. For example, all
28   * parameter instances regarding the second generation of emigrants should be
29   * shown in the GUI before the parameters of the third generation of emigrants,
30   * and so on.
31   * 
32   * Created on August 7, 2006
33   * 
34   * @author Christina Bohk
35   * @author Roland Ewald
36   * 
37   */
38  public class ParameterInstance implements Serializable {
39  
40  	/** Serialization ID. */
41  	private static final long serialVersionUID = -1513086327051860243L;
42  
43  	/** ID of this instance. */
44  	private int id = -1;
45  
46  	/**
47  	 * Generation to which this parameter applies (-1 if it is a general
48  	 * parameter).
49  	 */
50  	private int generation = -1;
51  
52  	/** Parameter that is instantiated. */
53  	private Parameter parameter;
54  
55  	/**
56  	 * Overall index that is used for comparison. This is used for the GUI etc. to
57  	 * preserve the same order of parameter kinds (i.e., parameter instances).
58  	 * This facilitates finding a particular instance for the user.
59  	 */
60  	private int comparisonIndex;
61  
62  	/**
63  	 * Default constructor.
64  	 * 
65  	 * @param cIndex
66  	 *          the comparison index
67  	 * @param param
68  	 *          the parameter that is instantiated
69  	 * @param gen
70  	 *          the generation this parameter belongs to
71  	 */
72  	public ParameterInstance(int cIndex, Parameter param, int gen) {
73  		this.comparisonIndex = cIndex;
74  		this.parameter = param;
75  		this.generation = param.isGenerationDependent() ? gen : -1;
76  	}
77  
78  	/**
79  	 * Constructor for bean compatibility.
80  	 */
81  	public ParameterInstance() {
82  		this.comparisonIndex = -1;
83  		this.parameter = null;
84  		this.generation = -1;
85  	}
86  
87  	/**
88  	 * Constructor for general parameters.
89  	 * 
90  	 * @param cIndex
91  	 *          the comparison index
92  	 * @param param
93  	 *          the parameter that is instantiated
94  	 */
95  	public ParameterInstance(int cIndex, Parameter param) {
96  		this.comparisonIndex = cIndex;
97  		this.generation = -1;
98  		this.parameter = param;
99  	}
100 
101 	/**
102 	 * Creates empty matrix with the dimensions as specified by this parameter
103 	 * instance.
104 	 * 
105 	 * @return well-dimensioned empty matrix
106 	 */
107 	public Matrix2D createEmptyValue() {
108 		Matrix2D returnMatrix = new Matrix2D(getValueHeight().getDimension(),
109 		    getValueWidth().getDimension());
110 		returnMatrix.setRowLabel(getValueHeight().getLabel());
111 		returnMatrix.setColumnLabel(getValueWidth().getLabel());
112 		return returnMatrix;
113 	}
114 
115 	@Override
116 	public String toString() {
117 		return parameter.getName()
118 		    + (generation == -1 ? "" : " [ " + this.generation + " ]");
119 	}
120 
121 	/**
122 	 * Gets the value width.
123 	 * 
124 	 * @return the value width
125 	 */
126 	public MatrixDimension getValueWidth() {
127 		return parameter.getValueWidth();
128 	}
129 
130 	/**
131 	 * Gets the value height.
132 	 * 
133 	 * @return the value height
134 	 */
135 	public MatrixDimension getValueHeight() {
136 		return parameter.getValueHeight();
137 	}
138 
139 	public int getComparisonIndex() {
140 		return comparisonIndex;
141 	}
142 
143 	public void setComparisonIndex(int comparisonIndex) {
144 		this.comparisonIndex = comparisonIndex;
145 	}
146 
147 	public int getGeneration() {
148 		return generation;
149 	}
150 
151 	public void setGeneration(int generation) {
152 		this.generation = generation;
153 	}
154 
155 	public Parameter getParameter() {
156 		return parameter;
157 	}
158 
159 	public void setParameter(Parameter parameter) {
160 		this.parameter = parameter;
161 	}
162 
163 	public int getID() {
164 		return id;
165 	}
166 
167 	public void setID(int uniqueID) {
168 		id = uniqueID;
169 	}
170 }