| 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.network; | |
| 21 | ||
| 22 | import java.util.Hashtable; | |
| 23 | import java.util.Iterator; | |
| 24 | import java.util.Vector; | |
| 25 | ||
| 26 | public class Network { | |
| 27 | ||
| 28 | 0 | private String name = "Network's Name"; |
| 29 | ||
| 30 | 0 | private Hashtable<String, Workstation> client = new Hashtable<String, Workstation>(); |
| 31 | ||
| 32 | 0 | private Hashtable<String, Workstation> server = new Hashtable<String, Workstation>(); |
| 33 | ||
| 34 | 0 | public Network() { |
| 35 | ||
| 36 | 0 | } |
| 37 | ||
| 38 | 0 | public Network(String name, Workstation[] server, Workstation[] client) { |
| 39 | 0 | this.name = name; |
| 40 | 0 | this.addServerSet(server); |
| 41 | 0 | this.addClientSet(client); |
| 42 | 0 | } |
| 43 | ||
| 44 | public Workstation[] getAllWorkstation() { | |
| 45 | 0 | Vector<Workstation> result = new Vector<Workstation>(); |
| 46 | 0 | result.addAll(client.values()); |
| 47 | 0 | result.addAll(server.values()); |
| 48 | 0 | return result.toArray(new Workstation[0]); |
| 49 | } | |
| 50 | ||
| 51 | /** | |
| 52 | * @return Returns the server. | |
| 53 | */ | |
| 54 | public Workstation[] getServer() { | |
| 55 | 0 | return server.values().toArray(new Workstation[0]); |
| 56 | } | |
| 57 | ||
| 58 | /** | |
| 59 | * @return Returns the client. | |
| 60 | */ | |
| 61 | public Workstation[] getClient() { | |
| 62 | 0 | 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) { | |
| 72 | 0 | this.client.put(NetworkManager.workstationKey(client), client); |
| 73 | 0 | } |
| 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) { | |
| 82 | 0 | this.server.put(NetworkManager.workstationKey(server), server); |
| 83 | 0 | } |
| 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) { | |
| 92 | 0 | for (int i = 0; i < client.length; i++) |
| 93 | 0 | this.addClient(client[i]); |
| 94 | 0 | } |
| 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) { | |
| 103 | 0 | for (int i = 0; i < server.length; i++) |
| 104 | 0 | this.addServer(server[i]); |
| 105 | 0 | } |
| 106 | ||
| 107 | /** | |
| 108 | * @return Returns the name. | |
| 109 | */ | |
| 110 | public String getName() { | |
| 111 | 0 | return name; |
| 112 | } | |
| 113 | ||
| 114 | /* | |
| 115 | * (non-Javadoc) | |
| 116 | * | |
| 117 | * @see java.lang.Object#toString() | |
| 118 | */ | |
| 119 | @Override | |
| 120 | public String toString() { | |
| 121 | 0 | StringBuffer sb = new StringBuffer(); |
| 122 | 0 | sb.append("NETWORK"); |
| 123 | 0 | sb.append("\n"); |
| 124 | 0 | sb.append("name: " + name); |
| 125 | 0 | sb.append("\n"); |
| 126 | 0 | sb.append("clients: "); |
| 127 | 0 | sb.append("\n"); |
| 128 | 0 | Iterator<Workstation> iterator = server.values().iterator(); |
| 129 | 0 | while (iterator.hasNext()) { |
| 130 | 0 | sb.append(iterator.next()); |
| 131 | 0 | sb.append("\n"); |
| 132 | 0 | } |
| 133 | 0 | sb.append("clients: "); |
| 134 | 0 | sb.append("\n"); |
| 135 | 0 | iterator = client.values().iterator(); |
| 136 | 0 | while (iterator.hasNext()) { |
| 137 | 0 | sb.append(iterator.next()); |
| 138 | 0 | sb.append("\n"); |
| 139 | 0 | } |
| 140 | ||
| 141 | 0 | 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) { | |
| 151 | 0 | this.client.remove(workstationKey); |
| 152 | 0 | } |
| 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) { | |
| 161 | 0 | this.server.remove(workstationKey); |
| 162 | 0 | } |
| 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) { | |
| 173 | 0 | Workstation[] workstation = getClient(); |
| 174 | 0 | for (int i = 0; i < workstation.length; i++) |
| 175 | 0 | if (workstation[i].getId() == workstationId) |
| 176 | 0 | return workstation[i]; |
| 177 | 0 | 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) { | |
| 189 | 0 | Workstation[] workstation = getServer(); |
| 190 | 0 | for (int i = 0; i < workstation.length; i++) |
| 191 | 0 | if (workstation[i].getId() == workstationId) |
| 192 | 0 | return workstation[i]; |
| 193 | 0 | return null; |
| 194 | } | |
| 195 | } |
|
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |