| 1 | package desmoj.core.report; |
| 2 | |
| 3 | import desmoj.core.simulator.Model; |
| 4 | import desmoj.core.simulator.Reportable; |
| 5 | |
| 6 | /** |
| 7 | * Declares the basic methods needed for reporter to be able to print reports |
| 8 | * about a model component. Since individual components need individual reports |
| 9 | * each component has to specify a special reporter to print its data. Derive |
| 10 | * from this class to implement the reporter for the specific |
| 11 | * <code>Reportable</code> class. |
| 12 | * |
| 13 | * @see desmoj.core.simulator.Reportable |
| 14 | * |
| 15 | * @version DESMO-J, Ver. 2.3.3 copyright (c) 2011 |
| 16 | * @author Tim Lechler |
| 17 | * |
| 18 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 19 | * you may not use this file except in compliance with the License. You |
| 20 | * may obtain a copy of the License at |
| 21 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 22 | * |
| 23 | * Unless required by applicable law or agreed to in writing, software |
| 24 | * distributed under the License is distributed on an "AS IS" |
| 25 | * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
| 26 | * or implied. See the License for the specific language governing |
| 27 | * permissions and limitations under the License. |
| 28 | * |
| 29 | */ |
| 30 | public abstract class Reporter { |
| 31 | |
| 32 | /** |
| 33 | * The group-id of the reporters of this class. This ID resembles |
| 34 | * group-identification and ordering information inside a group. The HTML |
| 35 | * output classes order <code>Reporters</code> by groups of hundred ID |
| 36 | * numbers. So i.e. all <code>Distributions</code> have |
| 37 | * <code>Reporters</code> with GroupID's in the range between 100 and 199. |
| 38 | * Highest numbers are always listed first. If in a sequence of |
| 39 | * <code>Reporters</code> its GroupID is in another century range, the |
| 40 | * HTML output will automatically insert a horizontal ruler and a new |
| 41 | * heading to indicate the new group of |
| 42 | * <code>Reportable ModelComponents</code>. |
| 43 | * <p> |
| 44 | * <DIV align=center> <TABLE BORDER > <CAPTION>Reserved GroupID ranges |
| 45 | * </CAPTION> |
| 46 | * <TR> |
| 47 | * <TH>GroupID range</TH> |
| 48 | * <TH>Reportables</TH> |
| 49 | * </TR> |
| 50 | * <TR> |
| 51 | * <TD>2147483647</TD> |
| 52 | * <TD>ModelReporter. Highest number possible, so always first in order. |
| 53 | * Ensures that SubModelReporter will be printed before other Reportables in |
| 54 | * the main model report.</TD> |
| 55 | * </TR> |
| 56 | * <TR> |
| 57 | * <TD>1800 +</TD> |
| 58 | * <TD>Free for additional Reporters of new constructs that will be listed |
| 59 | * before the <code>StatisticObjects</code> used in a <code>Model</code>. |
| 60 | * </TD> |
| 61 | * </TR> |
| 62 | * <TR> |
| 63 | * <TD>1300 - 1799</TD> |
| 64 | * <TD>Reporters for <code>StatisticObjects</code> as the |
| 65 | * <code>Accumulate, Tally, Histogram, Regression</code> and |
| 66 | * <code>Count</code>, which will be listed before the process |
| 67 | * synchronisation constructs used in the <code>Model</code>.</TD> |
| 68 | * </TR> |
| 69 | * <TR> |
| 70 | * <TD>400 - 1299</TD> |
| 71 | * <TD>Additional Reporters for process synchronisation constructs as the |
| 72 | * <code>Bin, Stock, Entrepot, Res, CondQueue, WaitQueue, Transporter</code> |
| 73 | * and <code>WorkStation</code>, which will be listed before the |
| 74 | * <code>Queues</code> used in a <code>Model</code>.</TD> |
| 75 | * </TR> |
| 76 | * <TR> |
| 77 | * <TD>300 - 399</TD> |
| 78 | * <TD>Free for additional Reporters of new constructs that will be listed |
| 79 | * before the <code>Queues</code> used in a <code>Model</code>.</TD> |
| 80 | * </TR> |
| 81 | * <TR> |
| 82 | * <TD>200 - 299</TD> |
| 83 | * <TD>Queues. Queue will be sorted first, ProcessQueue last</TD> |
| 84 | * </TR> |
| 85 | * <TR> |
| 86 | * <TD>100 - 199</TD> |
| 87 | * <TD>Distributions. The generic <code>DistributionReporter</code> will |
| 88 | * be last with its GroupID of 100.</TD> |
| 89 | * </TR> |
| 90 | * <TR> |
| 91 | * <TD>1-99</TD> |
| 92 | * <TD>Free for additional Reporters of new constructs that will be listed |
| 93 | * after the <code>Queues</code> used in a <code>Model</code>.</TD> |
| 94 | * </TR> |
| 95 | * </TABLE> </DIV> |
| 96 | */ |
| 97 | protected int groupID; |
| 98 | |
| 99 | /** |
| 100 | * The column headings of this reporter. Reporters of the same group always |
| 101 | * have the same column headings. Entries should contain in the elements in |
| 102 | * the same order as the <code>entries[]</code>. |
| 103 | */ |
| 104 | protected String columns[]; |
| 105 | |
| 106 | /** |
| 107 | * The data entries of this reporter. Reporters of the same group always |
| 108 | * have the same number of entries. Entries should contain in the data |
| 109 | * elements in the same order as defined in the <code>columns[]</code> |
| 110 | * array. |
| 111 | */ |
| 112 | protected String entries[]; |
| 113 | |
| 114 | /** |
| 115 | * The group's heading of this class of reporters. The String containe here |
| 116 | * is used as a table heading. All reporters of the same group must have the |
| 117 | * same group heading. |
| 118 | */ |
| 119 | protected String groupHeading; |
| 120 | |
| 121 | /** |
| 122 | * The Reportable that this reporter generates the report about |
| 123 | */ |
| 124 | protected Reportable source; |
| 125 | |
| 126 | /** |
| 127 | * The number of columns this reporter produces. |
| 128 | */ |
| 129 | protected int numColumns; |
| 130 | |
| 131 | /** |
| 132 | * Creates a reporter for the given reportable information source. |
| 133 | * |
| 134 | * @param informationSource |
| 135 | * desmoj.report.Reportable : The source of information to report |
| 136 | * about |
| 137 | */ |
| 138 | public Reporter(Reportable informationSource) { |
| 139 | |
| 140 | source = informationSource; |
| 141 | |
| 142 | } |
| 143 | |
| 144 | /** |
| 145 | * Returns an array of Strings each containing the title for the |
| 146 | * corresponding entry in array <code>entries[]</code>. |
| 147 | * |
| 148 | * @return java.lang.String[] : Array containing column titles |
| 149 | */ |
| 150 | public String[] getColumnTitles() { |
| 151 | |
| 152 | return columns.clone(); |
| 153 | |
| 154 | } |
| 155 | |
| 156 | /** |
| 157 | * Returns an array of strings each containing the data for the |
| 158 | * corresponding column in array <code>columns[]</code>. Implement this |
| 159 | * method the an array of the same length as the columntitles is produced |
| 160 | * containing the data at the point of time this method is called by someone |
| 161 | * else to produce up-to-date information. |
| 162 | * |
| 163 | * @return java.lang.String[] : Array containing the data for reporting |
| 164 | */ |
| 165 | public abstract String[] getEntries(); |
| 166 | |
| 167 | /** |
| 168 | * Returns the ID of the group this reporter belongs to. The group-ID is |
| 169 | * used to give reporters a key to be ordered by. This allows reporters of |
| 170 | * the same group to be printed together in one table in a report file. |
| 171 | * |
| 172 | * @return int : The reporter's group ID |
| 173 | */ |
| 174 | public int getGroupID() { |
| 175 | |
| 176 | return groupID; |
| 177 | |
| 178 | } |
| 179 | |
| 180 | /** |
| 181 | * Returns the heading for the group this reporter belongs to. This can |
| 182 | * easily be used as a heading in the reporter to introduce a new group of |
| 183 | * reporters. |
| 184 | * |
| 185 | * @return java.lang.String : The group heading for this group of reporters |
| 186 | */ |
| 187 | public String getHeading() { |
| 188 | |
| 189 | return groupHeading; |
| 190 | |
| 191 | } |
| 192 | |
| 193 | /** |
| 194 | * Returns the Model that the Reportable belongs to that this reporter |
| 195 | * produces a report about. |
| 196 | * |
| 197 | * @return Model : The Model the reporter's reportable belongs to |
| 198 | */ |
| 199 | public Model getModel() { |
| 200 | |
| 201 | return source.getModel(); |
| 202 | |
| 203 | } |
| 204 | |
| 205 | /** |
| 206 | * Returns the reportable object that this reporter contains informations |
| 207 | * about. |
| 208 | * |
| 209 | * @return desmoj.core.simulator.Reportable : The reportable this reporter carries |
| 210 | * information about |
| 211 | */ |
| 212 | public Reportable getReportable() { |
| 213 | |
| 214 | return source; |
| 215 | |
| 216 | } |
| 217 | |
| 218 | /** |
| 219 | * Compares the ID's of the two given reporters and returns |
| 220 | * <code>true</code> if both have the same ID, <code>false</code> if |
| 221 | * their ID's are different. |
| 222 | * |
| 223 | * @return boolean : Is <code>true</code> if both reporter's ID's are the |
| 224 | * same, <code>false</code> if not |
| 225 | * @param a |
| 226 | * desmoj.report.Reporter : comparand a |
| 227 | * @param b |
| 228 | * desmoj.report.Reporter : comparand b |
| 229 | */ |
| 230 | public static boolean isEqual(Reporter a, Reporter b) { |
| 231 | |
| 232 | return (a.getGroupID() == b.getGroupID()); |
| 233 | |
| 234 | } |
| 235 | |
| 236 | /** |
| 237 | * Compares the ID's of the two given reporters and returns |
| 238 | * <code>true</code> if reporter 'a' has a higher ID than reporter 'b', |
| 239 | * <code>false</code> if not. |
| 240 | * |
| 241 | * @return boolean : Is <code>true</code> if reporter 'a' has a higher ID |
| 242 | * than reporter 'b', <code>false</code> if not |
| 243 | * @param a |
| 244 | * desmoj.report.Reporter : comparand a |
| 245 | * @param b |
| 246 | * desmoj.report.Reporter : comparand b |
| 247 | */ |
| 248 | public static boolean isLarger(Reporter a, Reporter b) { |
| 249 | |
| 250 | return (a.getGroupID() > b.getGroupID()); |
| 251 | |
| 252 | } |
| 253 | |
| 254 | /** |
| 255 | * Compares the ID's of the two given reporters and returns |
| 256 | * <code>true</code> if reporter 'a' belongs to a different group of ID's |
| 257 | * than reporter 'b', <code>false</code> if not. |
| 258 | * |
| 259 | * @return boolean : Is <code>true</code> if reporter 'a' has an ID |
| 260 | * belonging to a different group than reporter 'b', |
| 261 | * <code>false</code> if not |
| 262 | * @param a |
| 263 | * desmoj.report.Reporter : comparand a |
| 264 | * @param b |
| 265 | * desmoj.report.Reporter : comparand b |
| 266 | */ |
| 267 | public static boolean isOtherGroup(Reporter a, Reporter b) { |
| 268 | |
| 269 | return !isSameGroup(a, b); |
| 270 | |
| 271 | } |
| 272 | |
| 273 | /** |
| 274 | * Compares the ID's of the two given reporters and returns |
| 275 | * <code>true</code> if reporter 'a' belongs to the same group of ID's as |
| 276 | * reporter 'b', <code>false</code> if not. |
| 277 | * |
| 278 | * @return boolean : Is <code>true</code> if reporter 'a' has an ID |
| 279 | * belonging to the same group as reporter 'b', <code>false</code> |
| 280 | * if not |
| 281 | * @param a |
| 282 | * desmoj.report.Reporter : comparand a |
| 283 | * @param b |
| 284 | * desmoj.report.Reporter : comparand b |
| 285 | */ |
| 286 | public static boolean isSameGroup(Reporter a, Reporter b) { |
| 287 | |
| 288 | int groupStep = 100; |
| 289 | |
| 290 | // Since 2.3.0: To provide additional groups for new |
| 291 | // statistics objects (BooleanStatistic, ConfidenceCalculator...), |
| 292 | // groups between 1300 and 1799 are considered different based on |
| 293 | // steps of 50 instead of 100 (default). |
| 294 | if (a.groupID >= 1300 && a.groupID < 1800 && b.groupID >= 1300 && b.groupID < 1800) { |
| 295 | groupStep = 50; |
| 296 | } |
| 297 | |
| 298 | return (a.getGroupID() / groupStep == b.getGroupID() / groupStep); |
| 299 | } |
| 300 | |
| 301 | /** |
| 302 | * Returns the number of columns or data this reporter is containing. |
| 303 | * |
| 304 | * @return int : The number of columns/data this reporter is containing |
| 305 | */ |
| 306 | public int numColumns() { |
| 307 | |
| 308 | return numColumns; |
| 309 | |
| 310 | } |
| 311 | |
| 312 | /*@TODO: Comment */ |
| 313 | public boolean isContinuingReporter() { |
| 314 | return false; |
| 315 | } |
| 316 | |
| 317 | /* @TODO: Comment */ |
| 318 | public boolean isTwoRowReporter() { |
| 319 | return false; |
| 320 | } |
| 321 | |
| 322 | /* @TODO: Comment */ |
| 323 | public int getNumOfSlaveQueues() { |
| 324 | return 0; |
| 325 | } |
| 326 | } |