1 | package desmoj.core.simulator; |
2 | |
3 | /** |
4 | * Represents a code to be passed to interrupted SimProcesses to give |
5 | * information about the reason for the interruption. Each new interrupt code |
6 | * instantiated will carry an individual internal integer codenumber to help |
7 | * identify different interrupt code objects. These can be checked using the |
8 | * static <code>equals(InterruptCode a, InterruptCode b)</code> method. It |
9 | * might come handy to clone an interrupt code object to make it known at |
10 | * different objects in a model. To produce a clone, create a new interrupt code |
11 | * using the alternative constructor method giving the interrupt code to be |
12 | * cloned as a parameter. That constructor will return a clone of the given |
13 | * interrupt code. |
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 class InterruptCode extends NamedObject { |
31 | |
32 | /** |
33 | * Static counter to provide each new interrupt code with a unique internal |
34 | * serial number. |
35 | */ |
36 | private static int irqCounter = 0; |
37 | |
38 | /** |
39 | * The internal unique number to identify different interrupt codes. |
40 | */ |
41 | private int _irqCode; |
42 | |
43 | /** |
44 | * Constructs a new interrupt code to be an identical clone of the given |
45 | * interrupt code object. The constructor provides the new interrupt code |
46 | * object with same name and internal codenumber as the interrupt code |
47 | * object given as parameter. |
48 | * |
49 | * @param cloneMe |
50 | * desmoj.InterruptCode : The interrupt code object to produce a |
51 | * clone of |
52 | */ |
53 | public InterruptCode(InterruptCode cloneMe) { |
54 | |
55 | super(cloneMe.getName()); |
56 | _irqCode = cloneMe.getCodeNumber(); |
57 | |
58 | } |
59 | |
60 | /** |
61 | * Produces a new interrupt code with a unique internal serial number and |
62 | * the given name. |
63 | * |
64 | * @param name |
65 | * java.lang.String : The interrupt code's name |
66 | */ |
67 | public InterruptCode(String name) { |
68 | |
69 | super(name); |
70 | |
71 | _irqCode = ++irqCounter; // increment counter and set code |
72 | |
73 | } |
74 | |
75 | /** |
76 | * Returns <code>true</code> if the two given interrupt codes have the |
77 | * same internal code, <code>false</code> otherwise. |
78 | * |
79 | * @return boolean : Is <code>true</code> if the two given interrupt codes |
80 | * have the same internal code, <code>false</code> otherwise |
81 | * @param a |
82 | * desmoj.InterruptCode : First comparand |
83 | * @param b |
84 | * desmoj.InterruptCode : Second comparand |
85 | */ |
86 | public static boolean equals(InterruptCode a, InterruptCode b) { |
87 | |
88 | if ((a != null) && (b != null)) |
89 | return (a.getCodeNumber() == b.getCodeNumber()); |
90 | else |
91 | return false; |
92 | |
93 | } |
94 | |
95 | /** |
96 | * Returns the internal unique number to identify different interrupt codes. |
97 | * |
98 | * @return int : The internal unique number of the interrupt code |
99 | */ |
100 | public int getCodeNumber() { |
101 | return _irqCode; |
102 | } |
103 | } |