| 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.service; | |
| 21 | ||
| 22 | import java.util.Date; | |
| 23 | ||
| 24 | import org.w3c.dom.Document; | |
| 25 | import org.w3c.dom.Element; | |
| 26 | import org.w3c.dom.Node; | |
| 27 | ||
| 28 | import ui.Messages; | |
| 29 | import base.ICXmlTags; | |
| 30 | import base.IXMLSaveable; | |
| 31 | ||
| 32 | public class Service implements IXMLSaveable { | |
| 33 | ||
| 34 | private final int id; | |
| 35 | ||
| 36 | private String name; | |
| 37 | ||
| 38 | private String description; | |
| 39 | 0 | |
| 40 | 0 | private String rateType = ServiceRateType.RATE_TYPE[0]; |
| 41 | 0 | |
| 42 | 0 | private double baseRate = Double.parseDouble(Messages.getString("service.default.baserate")); //$NON-NLS-1$ |
| 43 | 0 | |
| 44 | 0 | private int minDurationInMinute = Integer.parseInt(Messages.getString("service.default.mindurationinminute")); //$NON-NLS-1$ |
| 45 | 0 | |
| 46 | 0 | private boolean careAboutMinDuration = true; |
| 47 | 0 | |
| 48 | 0 | private int maxDurationInMinute = Integer.parseInt(Messages.getString("service.default.maxdurationinminute")); //$NON-NLS-1$ |
| 49 | 0 | |
| 50 | 0 | private boolean careAboutMaxDuration = false; |
| 51 | 0 | |
| 52 | /** | |
| 53 | * @param id | |
| 54 | * The Service's id. | |
| 55 | * @param name | |
| 56 | * The Service's name. | |
| 57 | * @param description | |
| 58 | * The Service's description. | |
| 59 | * @param rateType | |
| 60 | * The Service's rateType. | |
| 61 | * @param baseRate | |
| 62 | * The Service's baseRate. | |
| 63 | * @param minDurationInMinute | |
| 64 | * The Service's minDurationInMinute. | |
| 65 | * @param maxDurationInMinute | |
| 66 | * The Service's maxDurationInMinute. | |
| 67 | * @param careAboutMaxDuration | |
| 68 | * States if must be applied the max duration or not. | |
| 69 | 0 | */ |
| 70 | 0 | protected Service(int id, String name, String description, String rateType, |
| 71 | double baseRate, int minDurationInMinute, | |
| 72 | 0 | boolean careAboutMinDuration, int maxDurationInMinute, |
| 73 | 0 | boolean careAboutMaxDuration) { |
| 74 | 0 | this.id = id; |
| 75 | 0 | this.name = name; |
| 76 | 0 | this.description = description; |
| 77 | 0 | this.rateType = rateType; |
| 78 | 0 | this.baseRate = baseRate; |
| 79 | 0 | this.minDurationInMinute = minDurationInMinute; |
| 80 | 0 | this.careAboutMinDuration = careAboutMinDuration; |
| 81 | 0 | this.maxDurationInMinute = maxDurationInMinute; |
| 82 | 0 | this.careAboutMaxDuration = careAboutMaxDuration; |
| 83 | 0 | } |
| 84 | 0 | |
| 85 | /** | |
| 86 | * @return Returns the baseRate. | |
| 87 | */ | |
| 88 | 0 | public double getBaseRate() { |
| 89 | 0 | return this.baseRate; |
| 90 | 0 | } |
| 91 | ||
| 92 | /** | |
| 93 | * @param baseRate | |
| 94 | * The baseRate to set. | |
| 95 | */ | |
| 96 | 0 | public void setBaseRate(double baseRate) { |
| 97 | 0 | this.baseRate = baseRate; |
| 98 | 0 | } |
| 99 | 0 | |
| 100 | /** | |
| 101 | * @return Returns the description. | |
| 102 | */ | |
| 103 | 0 | public String getDescription() { |
| 104 | 0 | return this.description; |
| 105 | 0 | } |
| 106 | ||
| 107 | /** | |
| 108 | * @param description | |
| 109 | * The description to set. | |
| 110 | */ | |
| 111 | 0 | public void setDescription(String description) { |
| 112 | 0 | this.description = description; |
| 113 | 0 | } |
| 114 | 0 | |
| 115 | /** | |
| 116 | * @return Returns the name. | |
| 117 | */ | |
| 118 | 0 | public String getName() { |
| 119 | 0 | return this.name; |
| 120 | 0 | } |
| 121 | ||
| 122 | /** | |
| 123 | * @param name | |
| 124 | * The name to set. | |
| 125 | */ | |
| 126 | 0 | public void setName(String name) { |
| 127 | 0 | this.name = name; |
| 128 | 0 | } |
| 129 | 0 | |
| 130 | /** | |
| 131 | * @return Returns the id. | |
| 132 | */ | |
| 133 | 0 | public int getId() { |
| 134 | 0 | return id; |
| 135 | 0 | } |
| 136 | ||
| 137 | /** | |
| 138 | * @return Returns the rateType. | |
| 139 | */ | |
| 140 | 0 | public String getRateType() { |
| 141 | 0 | return rateType; |
| 142 | 0 | } |
| 143 | ||
| 144 | /** | |
| 145 | * @param rateType | |
| 146 | * The rateType to set. | |
| 147 | */ | |
| 148 | 0 | public void setRateType(String rateType) { |
| 149 | 0 | this.rateType = rateType; |
| 150 | 0 | } |
| 151 | 0 | |
| 152 | /** | |
| 153 | * @return Returns the maxDurationInMinute. | |
| 154 | */ | |
| 155 | 0 | public int getMaxDurationInMinute() { |
| 156 | 0 | return maxDurationInMinute; |
| 157 | 0 | } |
| 158 | ||
| 159 | /** | |
| 160 | * @param maxDurationInMinute | |
| 161 | * The maxDurationInMinute to set. | |
| 162 | */ | |
| 163 | 0 | public void setMaxDurationInMinute(int maxDurationInMinute) { |
| 164 | 0 | this.maxDurationInMinute = maxDurationInMinute; |
| 165 | 0 | } |
| 166 | 0 | |
| 167 | /** | |
| 168 | * @return Returns the minDurationInMinute. | |
| 169 | */ | |
| 170 | 0 | public int getMinDurationInMinute() { |
| 171 | 0 | return minDurationInMinute; |
| 172 | 0 | } |
| 173 | ||
| 174 | /** | |
| 175 | * @param minDurationInMinute | |
| 176 | * The minDurationInMinute to set. | |
| 177 | */ | |
| 178 | 0 | public void setMinDurationInMinute(int minDurationInMinute) { |
| 179 | 0 | this.minDurationInMinute = minDurationInMinute; |
| 180 | 0 | } |
| 181 | 0 | |
| 182 | /** | |
| 183 | * This method determines a service's cost on the bases of the provided | |
| 184 | * arguments. | |
| 185 | * | |
| 186 | * @param startTime | |
| 187 | * The service's start time. | |
| 188 | * @param endTime | |
| 189 | * The service's end time. | |
| 190 | * @param rateType | |
| 191 | * The service's rate type. | |
| 192 | * @param baseRate | |
| 193 | * The service's test.base rate. | |
| 194 | * @return The cost of a service according to the provided arguments. | |
| 195 | */ | |
| 196 | public static double cost(Date startTime, Date endTime, String rateType, | |
| 197 | 0 | double baseRate) { |
| 198 | 0 | double cost = 0.0; |
| 199 | 0 | if (rateType |
| 200 | 0 | .equals(ServiceRateType.RATE_TYPE[ServiceRateType.UNDEFINED])) |
| 201 | 0 | cost = 0.0; |
| 202 | 0 | else if (rateType |
| 203 | 0 | .equals(ServiceRateType.RATE_TYPE[ServiceRateType.DAY])) |
| 204 | 0 | cost = baseRate * durationInMinute(startTime, endTime) / 60 / 24; |
| 205 | 0 | else if (rateType |
| 206 | 0 | .equals(ServiceRateType.RATE_TYPE[ServiceRateType.HOUR])) |
| 207 | 0 | cost = baseRate * durationInMinute(startTime, endTime) / 60; |
| 208 | 0 | else if (rateType |
| 209 | 0 | .equals(ServiceRateType.RATE_TYPE[ServiceRateType.MINUTE])) |
| 210 | 0 | cost = baseRate * durationInMinute(startTime, endTime); |
| 211 | 0 | return cost; |
| 212 | 0 | } |
| 213 | ||
| 214 | /* | |
| 215 | * (non-Javadoc) | |
| 216 | * | |
| 217 | * @see java.lang.Object#toString() | |
| 218 | */ | |
| 219 | @Override | |
| 220 | 0 | public String toString() { |
| 221 | 0 | return "Service: " + this.getName() + " Rate Type: " //$NON-NLS-1$ //$NON-NLS-2$ |
| 222 | 0 | + this.getRateType() + " Base Rate: " + this.getBaseRate(); //$NON-NLS-1$ |
| 223 | } | |
| 224 | ||
| 225 | /** | |
| 226 | * @param startTime | |
| 227 | * A service's start time. | |
| 228 | * @param endTime | |
| 229 | * A service's end time. | |
| 230 | * @return A minute rappresentation of a service's duration. | |
| 231 | */ | |
| 232 | 0 | public static double durationInMinute(Date startTime, Date endTime) { |
| 233 | 0 | return (endTime.getTime() - startTime.getTime()) / 1000 / 60; |
| 234 | 0 | } |
| 235 | ||
| 236 | /** | |
| 237 | * @return Returns the careAboutMaxDuration. | |
| 238 | */ | |
| 239 | 0 | public boolean careAboutMaxDuration() { |
| 240 | 0 | return careAboutMaxDuration; |
| 241 | 0 | } |
| 242 | ||
| 243 | /** | |
| 244 | * @param careAboutMaxDuration | |
| 245 | * The careAboutMaxDuration to set. | |
| 246 | */ | |
| 247 | 0 | public void setCareAboutMaxDuration(boolean careAboutMaxDuration) { |
| 248 | 0 | this.careAboutMaxDuration = careAboutMaxDuration; |
| 249 | 0 | } |
| 250 | 0 | |
| 251 | /** | |
| 252 | * @return Returns the careAboutMinDuration. | |
| 253 | */ | |
| 254 | 0 | public boolean careAboutMinDuration() { |
| 255 | 0 | return careAboutMinDuration; |
| 256 | 0 | } |
| 257 | ||
| 258 | /** | |
| 259 | * @param careAboutMinDuration | |
| 260 | * The careAboutMinDuration to set. | |
| 261 | */ | |
| 262 | 0 | public void setCareAboutMinDuration(boolean careAboutMinDuration) { |
| 263 | 0 | this.careAboutMinDuration = careAboutMinDuration; |
| 264 | 0 | } |
| 265 | 0 | |
| 266 | /* | |
| 267 | * (non-Javadoc) | |
| 268 | * | |
| 269 | * @see test.base.IXMLSaveable#toXml(org.w3c.dom.Document) | |
| 270 | */ | |
| 271 | 0 | public Node toXml(Document document) { |
| 272 | 0 | Element serviceElement = document |
| 273 | 0 | .createElement(ICXmlTags.IC_SERVICE_TAG); |
| 274 | 0 | serviceElement.setAttribute(ICXmlTags.IC_SERVICE_ID_ATTRIBUTE, "" //$NON-NLS-1$ |
| 275 | 0 | + this.id); |
| 276 | 0 | |
| 277 | 0 | serviceElement.setAttribute( |
| 278 | 0 | ICXmlTags.IC_SERVICE_MIN_DURATION_IN_MINUTE_ATTRIBUTE, "" //$NON-NLS-1$ |
| 279 | 0 | + this.minDurationInMinute); |
| 280 | 0 | serviceElement.setAttribute( |
| 281 | 0 | ICXmlTags.IC_SERVICE_CARE_ABOUT_MIN_DURATION_ATTRIBUTE, "" //$NON-NLS-1$ |
| 282 | 0 | + this.careAboutMinDuration); |
| 283 | 0 | |
| 284 | 0 | serviceElement.setAttribute( |
| 285 | 0 | ICXmlTags.IC_SERVICE_MAX_DURATION_IN_MINUTE_ATTRIBUTE, "" //$NON-NLS-1$ |
| 286 | 0 | + this.maxDurationInMinute); |
| 287 | 0 | serviceElement.setAttribute( |
| 288 | 0 | ICXmlTags.IC_SERVICE_CARE_ABOUT_MAX_DURATION_ATTRIBUTE, "" //$NON-NLS-1$ |
| 289 | 0 | + this.careAboutMaxDuration); |
| 290 | 0 | |
| 291 | 0 | Element nameElement = document |
| 292 | 0 | .createElement(ICXmlTags.IC_SERVICE_NAME_TAG); |
| 293 | 0 | nameElement.setAttribute(ICXmlTags.IC_VALUE_ATTRIBUTE, this.name); |
| 294 | 0 | serviceElement.appendChild(nameElement); |
| 295 | 0 | |
| 296 | 0 | Element rateTypeElement = document |
| 297 | 0 | .createElement(ICXmlTags.IC_SERVICE_RATE_TYPE_TAG); |
| 298 | 0 | rateTypeElement.setAttribute(ICXmlTags.IC_VALUE_ATTRIBUTE, |
| 299 | 0 | this.rateType); |
| 300 | 0 | serviceElement.appendChild(rateTypeElement); |
| 301 | 0 | |
| 302 | 0 | Element baseRateElement = document |
| 303 | 0 | .createElement(ICXmlTags.IC_SERVICE_BASE_RATE_TAG); |
| 304 | 0 | baseRateElement.setAttribute(ICXmlTags.IC_VALUE_ATTRIBUTE, "" //$NON-NLS-1$ |
| 305 | 0 | + this.baseRate); |
| 306 | 0 | serviceElement.appendChild(baseRateElement); |
| 307 | 0 | |
| 308 | 0 | Element descriptionElement = document |
| 309 | 0 | .createElement(ICXmlTags.IC_SERVICE_DESCRIPTION_TAG); |
| 310 | 0 | descriptionElement.setAttribute(ICXmlTags.IC_VALUE_ATTRIBUTE, |
| 311 | 0 | this.description); |
| 312 | 0 | serviceElement.appendChild(descriptionElement); |
| 313 | 0 | |
| 314 | 0 | return serviceElement; |
| 315 | 0 | } |
| 316 | ||
| 317 | } |
|
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |