1 | package desmoj.core.report; |
2 | |
3 | import java.util.List; |
4 | |
5 | import desmoj.core.simulator.Entity; |
6 | import desmoj.core.simulator.EventAbstract; |
7 | import desmoj.core.simulator.Model; |
8 | import desmoj.core.simulator.TimeInstant; |
9 | |
10 | /** |
11 | * Represents a message produced by a simulation run whenever entities and / or |
12 | * events are scheduled, created, deleted or enqueued. Tracenotes document the |
13 | * changes of state of the model and allow modellers to trace and check the |
14 | * model's dynamic behaviour. The basic information needed to trace a model's |
15 | * changes of state are: |
16 | * <ul> |
17 | * <li>The name of the Model this message was produced in</li> |
18 | * <li>The point of simulation time that this message was created</li> |
19 | * <li>The name of the event involved in the change of state</li> |
20 | * <li>The name of the entity or process involved in the change of state</li> |
21 | * <li>A text to describe the kind of changes made to the model</li> |
22 | * </ul> |
23 | * |
24 | * @version DESMO-J, Ver. 2.3.3 copyright (c) 2011 |
25 | * @author Tim Lechler |
26 | * |
27 | * Licensed under the Apache License, Version 2.0 (the "License"); |
28 | * you may not use this file except in compliance with the License. You |
29 | * may obtain a copy of the License at |
30 | * http://www.apache.org/licenses/LICENSE-2.0 |
31 | * |
32 | * Unless required by applicable law or agreed to in writing, software |
33 | * distributed under the License is distributed on an "AS IS" |
34 | * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
35 | * or implied. See the License for the specific language governing |
36 | * permissions and limitations under the License. |
37 | * |
38 | */ |
39 | public class TraceNote extends Message { |
40 | |
41 | /** |
42 | * The current entity/entities that produced this message. |
43 | */ |
44 | private String _who; |
45 | |
46 | /** |
47 | * The current Event that produced this message. is especially useful when |
48 | * using multiple models. |
49 | */ |
50 | private String _what; |
51 | |
52 | /** |
53 | * Creates a new tracenote with the given parameters as initial values. If |
54 | * <code>null</code> references are given, they are displayed as "----" in |
55 | * the trace output. |
56 | * |
57 | * @param origin |
58 | * Model : The model that produced this tracenote |
59 | * @param message |
60 | * java.lang.String : The actual trace message |
61 | * @param time |
62 | * TimeInstant : The point in simulation time this tracenote was |
63 | * produced |
64 | * @param entityInvolved |
65 | * Entity : The entity involved in this change of state |
66 | * @param eventInvolved |
67 | * Event : The event involved in this change of state |
68 | */ |
69 | public TraceNote(Model origin, String message, TimeInstant time, |
70 | Entity entityInvolved, EventAbstract eventInvolved) { |
71 | |
72 | super(origin, message, time); |
73 | |
74 | if (entityInvolved == null) |
75 | _who = "----"; |
76 | else |
77 | _who = entityInvolved.getName(); |
78 | |
79 | if (eventInvolved == null) |
80 | _what = "----"; |
81 | else |
82 | _what = eventInvolved.getName(); |
83 | |
84 | } |
85 | |
86 | /** |
87 | * Creates a new tracenote with the given parameters as initial values. If |
88 | * <code>null</code> references are given, they are displayed as "----" in |
89 | * the trace output. |
90 | * |
91 | * @param origin |
92 | * Model : The model that produced this tracenote |
93 | * @param message |
94 | * java.lang.String : The actual trace message |
95 | * @param time |
96 | * TimeInstant : The point in simulation time this tracenote was |
97 | * produced |
98 | * @param entitiesInvolved |
99 | * List<Entity> : The entities involved in this change of state |
100 | * @param eventInvolved |
101 | * Event : The event involved in this change of state |
102 | */ |
103 | public TraceNote(Model origin, String message, TimeInstant time, |
104 | List<Entity> entitiesInvolved, EventAbstract eventInvolved) { |
105 | |
106 | super(origin, message, time); |
107 | |
108 | if (entitiesInvolved == null || entitiesInvolved.isEmpty()) |
109 | _who = "----"; |
110 | else { |
111 | _who = entitiesInvolved.get(0).getQuotedName(); |
112 | if (entitiesInvolved.size() > 1) { |
113 | _who += entitiesInvolved.size() > 2 ? |
114 | ", " + entitiesInvolved.get(1).getQuotedName() : " and " + entitiesInvolved.get(1).getQuotedName(); |
115 | if (entitiesInvolved.size() > 2) { |
116 | _who += " and " + entitiesInvolved.get(2).getQuotedName(); |
117 | } |
118 | } |
119 | } |
120 | |
121 | if (eventInvolved == null) |
122 | _what = "----"; |
123 | else |
124 | _what = eventInvolved.getQuotedName(); |
125 | |
126 | } |
127 | |
128 | /** |
129 | * Returns the name of the entity this tracenote evolved from. |
130 | * |
131 | * @return java.lang.String : The name of the entity that produced this |
132 | * tracenote |
133 | */ |
134 | public String getEntity() { |
135 | |
136 | return _who; |
137 | |
138 | } |
139 | |
140 | /** |
141 | * Returns the name of the event described in this tracenote from. |
142 | * |
143 | * @return java.lang.String : The name of the event that produced this |
144 | * tracenote |
145 | */ |
146 | public String getEvent() { |
147 | |
148 | return _what; |
149 | |
150 | } |
151 | } |