Coverage details for base.IdManager

LineHitsSource
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;
3156    private int currentUserId = 0;
3256    private int currentWorkstationId = 0;
3356    private int currentSessionId = 0;
34282    private int currentServiceId = 0;
3556    private int currentBackupId = 0;
36  
37282    protected IdManager() {
38         // We must access to the InternetCafeManager in order to retrieve the
39226        // correct current values...
4056        this.currentUserId = retrieveMaxUserId();
41226        this.currentWorkstationId = retrieveMaxWorkstationId();
420        this.currentSessionId = retrieveMaxSessionId();
43226        this.currentServiceId = retrieveMaxServiceId();
440        this.currentBackupId = retrieveMaxBackupId();
45226    }
46  
47226    public static IdManager getInstance() {
4856        return (instance == null) ? (instance = new IdManager()) : instance;
49     }
50226 
5126    private int retrieveMaxUserId() {
5256        int max = -1; // This is an invalid value...
5356        User[] user = InternetCafeManager.getInstance().getUser();
540 
550        for (int i = 0; i < user.length; i++) {
560            if (user[i].getId() > max) {
570                max = user[i].getId();
58226            }
59226        }
6026 
610        return max;
620    }
63  
6426    private int retrieveMaxWorkstationId() {
650        int max = -1; // This is an invalid value...
660        Workstation[] workstation = NetworkManager.getInstance().getNetwork()
67                                                   .getAllWorkstation();
6826 
6926        for (int i = 0; i < workstation.length; i++) {
700            if (workstation[i].getId() > max) {
710                max = workstation[i].getId();
720            }
730        }
740 
750        return max;
76     }
77  
780    private int retrieveMaxSessionId() {
790        int max = -1; // This is an invalid value...
800        Session[] session = InternetCafeManager.getInstance().getSession();
810 
820        for (int i = 0; i < session.length; i++) {
830            if (session[i].getId() > max) {
840                max = session[i].getId();
85             }
86         }
870 
880        return max;
890    }
900 
910    private int retrieveMaxServiceId() {
920        int max = -1; // This is an invalid value...
930        Service[] service = InternetCafeManager.getInstance().getService();
94  
950        for (int i = 0; i < service.length; i++) {
960            if (service[i].getId() > max) {
970                max = service[i].getId();
980            }
990        }
1000 
1010        return max;
102     }
103  
104     private int retrieveMaxBackupId() {
1050        int max = -1; // This is an invalid value...
1060        Backup[] backup = InternetCafeManager.getInstance().getBackup();
107  
1080        for (int i = 0; i < backup.length; i++) {
1090            if (backup[i].getId() > max) {
1100                max = backup[i].getId();
111             }
112         }
113  
1140        return max;
1150    }
116  
117     /**
118      * @return Returns the currenSessionId.
119      */
120     public int getCurrentSessionId() {
1210        return currentSessionId;
1220    }
123  
124     /**
125      * @return Returns the currentUserId.
126      */
127     public int getCurrentUserId() {
1280        return currentUserId;
1290    }
130  
131     /**
132      * @return Returns the currentWorkstationId.
133      */
134     public int getCurrentWorkstationId() {
1350        return currentWorkstationId;
1360    }
137  
138     /**
139      * @return Returns the currentServiceId.
140      */
141     public int getCurrentServiceId() {
1420        return currentServiceId;
1430    }
144  
145     /**
146      * @return Returns the currentBackupId.
147      */
148     public int getCurrentBackupId() {
1490        return currentBackupId;
1500    }
151  
152     /**
153      * @return Returns the currentSessionId increased of 1 unit.
154      */
155     public int getNextSessionId() {
1560        return ++currentSessionId;
1570    }
158  
159     /**
160      * @return Returns the currentUserId increased of 1 unit.
161      */
162     public int getNextUserId() {
1630        return ++currentUserId;
1640    }
165  
166     /**
167      * @return Returns the currentWorkstationId increased of 1 unit.
168      */
169     public int getNextWorkstationId() {
1700        return ++currentWorkstationId;
1710    }
172  
173     /**
174      * @return Returns the currentServiceId increased of 1 unit.
175      */
176     public int getNextServiceId() {
1770        return ++currentServiceId;
178     }
179  
180     /**
181      * @return Returns the currentBackupId increased of 1 unit.
182      */
183     public int getNextBackupId() {
1840        return ++currentBackupId;
185     }
186 }

this report was generated by version 1.0.5 of jcoverage.
visit www.jcoverage.com for updates.

copyright © 2003, jcoverage ltd. all rights reserved.
Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.