Line | Hits | Source |
---|---|---|
1 | /******************************************************************************* | |
2 | * InternetCafe is a software solution that helps the management of Cybercafes | |
3 | * according with the ITALIAN DECREE LAW ON ANTI-TERROR MEASURES, 27 JULY 2005. | |
4 | * Copyright (C) 2006 Guido Angelo Ingenito | |
5 | ||
6 | * This program is free software; you can redistribute it and/or | |
7 | * modify it under the terms of the GNU General Public License | |
8 | * as published by the Free Software Foundation; either version 2 | |
9 | * of the License, or (at your option) any later version. | |
10 | ||
11 | * This program is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with this program; if not, write to the Free Software | |
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
19 | *******************************************************************************/ | |
20 | package base; | |
21 | ||
22 | import base.backup.Backup; | |
23 | import base.network.NetworkManager; | |
24 | import base.network.Workstation; | |
25 | import base.service.Service; | |
26 | import base.session.Session; | |
27 | import base.user.User; | |
28 | ||
29 | public class IdManager { | |
30 | private static IdManager instance; | |
31 | 56 | private int currentUserId = 0; |
32 | 56 | private int currentWorkstationId = 0; |
33 | 56 | private int currentSessionId = 0; |
34 | 282 | private int currentServiceId = 0; |
35 | 56 | private int currentBackupId = 0; |
36 | ||
37 | 282 | protected IdManager() { |
38 | // We must access to the InternetCafeManager in order to retrieve the | |
39 | 226 | // correct current values... |
40 | 56 | this.currentUserId = retrieveMaxUserId(); |
41 | 226 | this.currentWorkstationId = retrieveMaxWorkstationId(); |
42 | 0 | this.currentSessionId = retrieveMaxSessionId(); |
43 | 226 | this.currentServiceId = retrieveMaxServiceId(); |
44 | 0 | this.currentBackupId = retrieveMaxBackupId(); |
45 | 226 | } |
46 | ||
47 | 226 | public static IdManager getInstance() { |
48 | 56 | return (instance == null) ? (instance = new IdManager()) : instance; |
49 | } | |
50 | 226 | |
51 | 26 | private int retrieveMaxUserId() { |
52 | 56 | int max = -1; // This is an invalid value... |
53 | 56 | User[] user = InternetCafeManager.getInstance().getUser(); |
54 | 0 | |
55 | 0 | for (int i = 0; i < user.length; i++) { |
56 | 0 | if (user[i].getId() > max) { |
57 | 0 | max = user[i].getId(); |
58 | 226 | } |
59 | 226 | } |
60 | 26 | |
61 | 0 | return max; |
62 | 0 | } |
63 | ||
64 | 26 | private int retrieveMaxWorkstationId() { |
65 | 0 | int max = -1; // This is an invalid value... |
66 | 0 | Workstation[] workstation = NetworkManager.getInstance().getNetwork() |
67 | .getAllWorkstation(); | |
68 | 26 | |
69 | 26 | for (int i = 0; i < workstation.length; i++) { |
70 | 0 | if (workstation[i].getId() > max) { |
71 | 0 | max = workstation[i].getId(); |
72 | 0 | } |
73 | 0 | } |
74 | 0 | |
75 | 0 | return max; |
76 | } | |
77 | ||
78 | 0 | private int retrieveMaxSessionId() { |
79 | 0 | int max = -1; // This is an invalid value... |
80 | 0 | Session[] session = InternetCafeManager.getInstance().getSession(); |
81 | 0 | |
82 | 0 | for (int i = 0; i < session.length; i++) { |
83 | 0 | if (session[i].getId() > max) { |
84 | 0 | max = session[i].getId(); |
85 | } | |
86 | } | |
87 | 0 | |
88 | 0 | return max; |
89 | 0 | } |
90 | 0 | |
91 | 0 | private int retrieveMaxServiceId() { |
92 | 0 | int max = -1; // This is an invalid value... |
93 | 0 | Service[] service = InternetCafeManager.getInstance().getService(); |
94 | ||
95 | 0 | for (int i = 0; i < service.length; i++) { |
96 | 0 | if (service[i].getId() > max) { |
97 | 0 | max = service[i].getId(); |
98 | 0 | } |
99 | 0 | } |
100 | 0 | |
101 | 0 | return max; |
102 | } | |
103 | ||
104 | private int retrieveMaxBackupId() { | |
105 | 0 | int max = -1; // This is an invalid value... |
106 | 0 | Backup[] backup = InternetCafeManager.getInstance().getBackup(); |
107 | ||
108 | 0 | for (int i = 0; i < backup.length; i++) { |
109 | 0 | if (backup[i].getId() > max) { |
110 | 0 | max = backup[i].getId(); |
111 | } | |
112 | } | |
113 | ||
114 | 0 | return max; |
115 | 0 | } |
116 | ||
117 | /** | |
118 | * @return Returns the currenSessionId. | |
119 | */ | |
120 | public int getCurrentSessionId() { | |
121 | 0 | return currentSessionId; |
122 | 0 | } |
123 | ||
124 | /** | |
125 | * @return Returns the currentUserId. | |
126 | */ | |
127 | public int getCurrentUserId() { | |
128 | 0 | return currentUserId; |
129 | 0 | } |
130 | ||
131 | /** | |
132 | * @return Returns the currentWorkstationId. | |
133 | */ | |
134 | public int getCurrentWorkstationId() { | |
135 | 0 | return currentWorkstationId; |
136 | 0 | } |
137 | ||
138 | /** | |
139 | * @return Returns the currentServiceId. | |
140 | */ | |
141 | public int getCurrentServiceId() { | |
142 | 0 | return currentServiceId; |
143 | 0 | } |
144 | ||
145 | /** | |
146 | * @return Returns the currentBackupId. | |
147 | */ | |
148 | public int getCurrentBackupId() { | |
149 | 0 | return currentBackupId; |
150 | 0 | } |
151 | ||
152 | /** | |
153 | * @return Returns the currentSessionId increased of 1 unit. | |
154 | */ | |
155 | public int getNextSessionId() { | |
156 | 0 | return ++currentSessionId; |
157 | 0 | } |
158 | ||
159 | /** | |
160 | * @return Returns the currentUserId increased of 1 unit. | |
161 | */ | |
162 | public int getNextUserId() { | |
163 | 0 | return ++currentUserId; |
164 | 0 | } |
165 | ||
166 | /** | |
167 | * @return Returns the currentWorkstationId increased of 1 unit. | |
168 | */ | |
169 | public int getNextWorkstationId() { | |
170 | 0 | return ++currentWorkstationId; |
171 | 0 | } |
172 | ||
173 | /** | |
174 | * @return Returns the currentServiceId increased of 1 unit. | |
175 | */ | |
176 | public int getNextServiceId() { | |
177 | 0 | return ++currentServiceId; |
178 | } | |
179 | ||
180 | /** | |
181 | * @return Returns the currentBackupId increased of 1 unit. | |
182 | */ | |
183 | public int getNextBackupId() { | |
184 | 0 | return ++currentBackupId; |
185 | } | |
186 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |