Coverage details for base.network.Network

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.network;
21  
22 import java.util.Hashtable;
23 import java.util.Iterator;
24 import java.util.Vector;
25  
26 public class Network {
27  
280    private String name = "Network's Name";
29  
300    private Hashtable<String, Workstation> client = new Hashtable<String, Workstation>();
31  
320    private Hashtable<String, Workstation> server = new Hashtable<String, Workstation>();
33  
340    public Network() {
35  
360    }
37  
380    public Network(String name, Workstation[] server, Workstation[] client) {
390        this.name = name;
400        this.addServerSet(server);
410        this.addClientSet(client);
420    }
43  
44     public Workstation[] getAllWorkstation() {
450        Vector<Workstation> result = new Vector<Workstation>();
460        result.addAll(client.values());
470        result.addAll(server.values());
480        return result.toArray(new Workstation[0]);
49     }
50  
51     /**
52      * @return Returns the server.
53      */
54     public Workstation[] getServer() {
550        return server.values().toArray(new Workstation[0]);
56     }
57  
58     /**
59      * @return Returns the client.
60      */
61     public Workstation[] getClient() {
620        return client.values().toArray(new Workstation[0]);
63     }
64  
65     /**
66      * This method simply adds a client to the network.
67      *
68      * @param client
69      * The client to add to the network.
70      */
71     protected void addClient(Workstation client) {
720        this.client.put(NetworkManager.workstationKey(client), client);
730    }
74  
75     /**
76      * This method simply adds a server to the network.
77      *
78      * @param server
79      * The server to add to the network.
80      */
81     protected void addServer(Workstation server) {
820        this.server.put(NetworkManager.workstationKey(server), server);
830    }
84  
85     /**
86      * This method simply adds a workstation's client set to the network.
87      *
88      * @param client
89      * A set of client workstations to add to the network.
90      */
91     protected void addClientSet(Workstation[] client) {
920        for (int i = 0; i < client.length; i++)
930            this.addClient(client[i]);
940    }
95  
96     /**
97      * This method simply adds a workstation's server set to the network.
98      *
99      * @param server
100      * A set of server workstations to add to the network.
101      */
102     protected void addServerSet(Workstation[] server) {
1030        for (int i = 0; i < server.length; i++)
1040            this.addServer(server[i]);
1050    }
106  
107     /**
108      * @return Returns the name.
109      */
110     public String getName() {
1110        return name;
112     }
113  
114     /*
115      * (non-Javadoc)
116      *
117      * @see java.lang.Object#toString()
118      */
119     @Override
120     public String toString() {
1210        StringBuffer sb = new StringBuffer();
1220        sb.append("NETWORK");
1230        sb.append("\n");
1240        sb.append("name: " + name);
1250        sb.append("\n");
1260        sb.append("clients: ");
1270        sb.append("\n");
1280        Iterator<Workstation> iterator = server.values().iterator();
1290        while (iterator.hasNext()) {
1300            sb.append(iterator.next());
1310            sb.append("\n");
1320        }
1330        sb.append("clients: ");
1340        sb.append("\n");
1350        iterator = client.values().iterator();
1360        while (iterator.hasNext()) {
1370            sb.append(iterator.next());
1380            sb.append("\n");
1390        }
140  
1410        return sb.toString();
142     }
143  
144     /**
145      * This method deletes a client workstation.
146      *
147      * @param workstationKey
148      * The client workstation to delete in form of key string.
149      */
150     protected void deleteClient(String workstationKey) {
1510        this.client.remove(workstationKey);
1520    }
153  
154     /**
155      * This method deletes a server workstation.
156      *
157      * @param workstationKey
158      * The server workstation to delete in form of key string.
159      */
160     protected void deleteServer(String workstationKey) {
1610        this.server.remove(workstationKey);
1620    }
163  
164     /**
165      * This method retrieves a client workstation specifying his id.
166      *
167      * @param workstationId
168      * An id associated to the client to retrieve.
169      * @return A client workstation with id equals to workstationId, null if the
170      * specified workstationId is not a valid client workstation's id.
171      */
172     public Workstation getClientById(int workstationId) {
1730        Workstation[] workstation = getClient();
1740        for (int i = 0; i < workstation.length; i++)
1750            if (workstation[i].getId() == workstationId)
1760                return workstation[i];
1770        return null;
178     }
179  
180     /**
181      * This method retrieves a server workstation specifying his id.
182      *
183      * @param workstationId
184      * An id associated to the server to retrieve.
185      * @return A server workstation with id equals to workstationId, null if the
186      * specified workstationId is not a valid server workstation's id.
187      */
188     public Workstation getServerById(int workstationId) {
1890        Workstation[] workstation = getServer();
1900        for (int i = 0; i < workstation.length; i++)
1910            if (workstation[i].getId() == workstationId)
1920                return workstation[i];
1930        return null;
194     }
195 }

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.