1 | package desmoj.core.report; |
2 | |
3 | import desmoj.core.simulator.Queue; |
4 | |
5 | /** |
6 | * Captures all relevant information about a queue. |
7 | * |
8 | * @version DESMO-J, Ver. 2.3.3 copyright (c) 2011 |
9 | * @author Tim Lechler |
10 | * @author modified by Soenke Claassen |
11 | * |
12 | * Licensed under the Apache License, Version 2.0 (the "License"); |
13 | * you may not use this file except in compliance with the License. You |
14 | * may obtain a copy of the License at |
15 | * http://www.apache.org/licenses/LICENSE-2.0 |
16 | * |
17 | * Unless required by applicable law or agreed to in writing, software |
18 | * distributed under the License is distributed on an "AS IS" |
19 | * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
20 | * or implied. See the License for the specific language governing |
21 | * permissions and limitations under the License. |
22 | * |
23 | */ |
24 | public class QueueReporter extends Reporter { |
25 | /** |
26 | * Creates a QueueReporter. Note that although any Reportable is accepted |
27 | * you should make sure that only subtypes of Queue are passed to this |
28 | * constructor. Otherwise the number of column titles and their individual |
29 | * headings will differ from the actual content collected by this reporter. |
30 | * |
31 | * @param informationSource |
32 | * desmoj.core.simulator.Reportable : The Queue to report about |
33 | */ |
34 | public QueueReporter(desmoj.core.simulator.Reportable informationSource) { |
35 | |
36 | super(informationSource); |
37 | |
38 | numColumns = 12; |
39 | columns = new String[numColumns]; |
40 | columns[0] = "Title"; |
41 | columns[1] = "Qorder"; |
42 | columns[2] = "(Re)set"; |
43 | columns[3] = "Obs"; |
44 | columns[4] = "QLimit"; |
45 | columns[5] = "Qmax"; |
46 | columns[6] = "Qnow"; |
47 | columns[7] = "Qavg."; |
48 | columns[8] = "Zeros"; |
49 | columns[9] = "max.Wait"; |
50 | columns[10] = "avg.Wait"; |
51 | columns[11] = "refus."; |
52 | groupHeading = "Queues"; |
53 | groupID = 201; |
54 | entries = new String[numColumns]; |
55 | |
56 | } |
57 | |
58 | /** |
59 | * Returns an array of Strings each containing the data for the |
60 | * corresponding column in array <code>columns[]</code>. Implement this |
61 | * method tha an array of the same langth as the columntitles is produced |
62 | * containing the data at the point of time this method is called by someone |
63 | * else to produce up-to-date information. |
64 | * |
65 | * @return java.lang.String[] : Array containing the data for reporting |
66 | */ |
67 | public String[] getEntries() { |
68 | |
69 | if (source instanceof Queue) { |
70 | |
71 | // variable valid for block only - for faster access |
72 | Queue<?> q = (Queue<?>) source; |
73 | |
74 | // Title |
75 | entries[0] = source.getName(); |
76 | // Qorder |
77 | entries[1] = q.getQueueStrategy(); |
78 | // (Re)set |
79 | entries[2] = source.resetAt().toString(); |
80 | // Obs |
81 | entries[3] = Long.toString(source.getObservations()); |
82 | // Qlimit |
83 | entries[4] = Long.toString(q.getQueueLimit()); |
84 | if (q.getQueueLimit() == Integer.MAX_VALUE) { |
85 | entries[4] = "unlimit."; |
86 | } |
87 | // Qmax |
88 | entries[5] = Long.toString(q.maxLength()); |
89 | // Qnow |
90 | entries[6] = Long.toString(q.length()); |
91 | // Qavg. |
92 | entries[7] = Double.toString(q.averageLength()); |
93 | // Zeros |
94 | entries[8] = Long.toString(q.zeroWaits()); |
95 | // max.Wait |
96 | entries[9] = q.maxWaitTime().toString(); |
97 | // avg.Wait |
98 | entries[10] = q.averageWaitTime().toString(); |
99 | // refused |
100 | entries[11] = Long.toString(q.getRefused()); |
101 | |
102 | } else { |
103 | |
104 | for (int i = 0; i < numColumns; i++) { |
105 | entries[i] = "Invalid source!"; |
106 | } |
107 | |
108 | } |
109 | |
110 | return entries; |
111 | |
112 | } |
113 | } |