Coverage details for base.service.Service

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.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;
390 
400    private String rateType = ServiceRateType.RATE_TYPE[0];
410 
420    private double baseRate = Double.parseDouble(Messages.getString("service.default.baserate")); //$NON-NLS-1$
430 
440    private int minDurationInMinute = Integer.parseInt(Messages.getString("service.default.mindurationinminute")); //$NON-NLS-1$
450 
460    private boolean careAboutMinDuration = true;
470 
480    private int maxDurationInMinute = Integer.parseInt(Messages.getString("service.default.maxdurationinminute")); //$NON-NLS-1$
490 
500    private boolean careAboutMaxDuration = false;
510 
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.
690     */
700    protected Service(int id, String name, String description, String rateType,
71             double baseRate, int minDurationInMinute,
720            boolean careAboutMinDuration, int maxDurationInMinute,
730            boolean careAboutMaxDuration) {
740        this.id = id;
750        this.name = name;
760        this.description = description;
770        this.rateType = rateType;
780        this.baseRate = baseRate;
790        this.minDurationInMinute = minDurationInMinute;
800        this.careAboutMinDuration = careAboutMinDuration;
810        this.maxDurationInMinute = maxDurationInMinute;
820        this.careAboutMaxDuration = careAboutMaxDuration;
830    }
840 
85     /**
86      * @return Returns the baseRate.
87      */
880    public double getBaseRate() {
890        return this.baseRate;
900    }
91  
92     /**
93      * @param baseRate
94      * The baseRate to set.
95      */
960    public void setBaseRate(double baseRate) {
970        this.baseRate = baseRate;
980    }
990 
100     /**
101      * @return Returns the description.
102      */
1030    public String getDescription() {
1040        return this.description;
1050    }
106  
107     /**
108      * @param description
109      * The description to set.
110      */
1110    public void setDescription(String description) {
1120        this.description = description;
1130    }
1140 
115     /**
116      * @return Returns the name.
117      */
1180    public String getName() {
1190        return this.name;
1200    }
121  
122     /**
123      * @param name
124      * The name to set.
125      */
1260    public void setName(String name) {
1270        this.name = name;
1280    }
1290 
130     /**
131      * @return Returns the id.
132      */
1330    public int getId() {
1340        return id;
1350    }
136  
137     /**
138      * @return Returns the rateType.
139      */
1400    public String getRateType() {
1410        return rateType;
1420    }
143  
144     /**
145      * @param rateType
146      * The rateType to set.
147      */
1480    public void setRateType(String rateType) {
1490        this.rateType = rateType;
1500    }
1510 
152     /**
153      * @return Returns the maxDurationInMinute.
154      */
1550    public int getMaxDurationInMinute() {
1560        return maxDurationInMinute;
1570    }
158  
159     /**
160      * @param maxDurationInMinute
161      * The maxDurationInMinute to set.
162      */
1630    public void setMaxDurationInMinute(int maxDurationInMinute) {
1640        this.maxDurationInMinute = maxDurationInMinute;
1650    }
1660 
167     /**
168      * @return Returns the minDurationInMinute.
169      */
1700    public int getMinDurationInMinute() {
1710        return minDurationInMinute;
1720    }
173  
174     /**
175      * @param minDurationInMinute
176      * The minDurationInMinute to set.
177      */
1780    public void setMinDurationInMinute(int minDurationInMinute) {
1790        this.minDurationInMinute = minDurationInMinute;
1800    }
1810 
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,
1970            double baseRate) {
1980        double cost = 0.0;
1990        if (rateType
2000                .equals(ServiceRateType.RATE_TYPE[ServiceRateType.UNDEFINED]))
2010            cost = 0.0;
2020        else if (rateType
2030                .equals(ServiceRateType.RATE_TYPE[ServiceRateType.DAY]))
2040            cost = baseRate * durationInMinute(startTime, endTime) / 60 / 24;
2050        else if (rateType
2060                .equals(ServiceRateType.RATE_TYPE[ServiceRateType.HOUR]))
2070            cost = baseRate * durationInMinute(startTime, endTime) / 60;
2080        else if (rateType
2090                .equals(ServiceRateType.RATE_TYPE[ServiceRateType.MINUTE]))
2100            cost = baseRate * durationInMinute(startTime, endTime);
2110        return cost;
2120    }
213  
214     /*
215      * (non-Javadoc)
216      *
217      * @see java.lang.Object#toString()
218      */
219     @Override
2200    public String toString() {
2210        return "Service: " + this.getName() + " Rate Type: " //$NON-NLS-1$ //$NON-NLS-2$
2220                + 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      */
2320    public static double durationInMinute(Date startTime, Date endTime) {
2330        return (endTime.getTime() - startTime.getTime()) / 1000 / 60;
2340    }
235  
236     /**
237      * @return Returns the careAboutMaxDuration.
238      */
2390    public boolean careAboutMaxDuration() {
2400        return careAboutMaxDuration;
2410    }
242  
243     /**
244      * @param careAboutMaxDuration
245      * The careAboutMaxDuration to set.
246      */
2470    public void setCareAboutMaxDuration(boolean careAboutMaxDuration) {
2480        this.careAboutMaxDuration = careAboutMaxDuration;
2490    }
2500 
251     /**
252      * @return Returns the careAboutMinDuration.
253      */
2540    public boolean careAboutMinDuration() {
2550        return careAboutMinDuration;
2560    }
257  
258     /**
259      * @param careAboutMinDuration
260      * The careAboutMinDuration to set.
261      */
2620    public void setCareAboutMinDuration(boolean careAboutMinDuration) {
2630        this.careAboutMinDuration = careAboutMinDuration;
2640    }
2650 
266     /*
267      * (non-Javadoc)
268      *
269      * @see test.base.IXMLSaveable#toXml(org.w3c.dom.Document)
270      */
2710    public Node toXml(Document document) {
2720        Element serviceElement = document
2730                .createElement(ICXmlTags.IC_SERVICE_TAG);
2740        serviceElement.setAttribute(ICXmlTags.IC_SERVICE_ID_ATTRIBUTE, "" //$NON-NLS-1$
2750                + this.id);
2760 
2770        serviceElement.setAttribute(
2780                ICXmlTags.IC_SERVICE_MIN_DURATION_IN_MINUTE_ATTRIBUTE, "" //$NON-NLS-1$
2790                        + this.minDurationInMinute);
2800        serviceElement.setAttribute(
2810                ICXmlTags.IC_SERVICE_CARE_ABOUT_MIN_DURATION_ATTRIBUTE, "" //$NON-NLS-1$
2820                        + this.careAboutMinDuration);
2830 
2840        serviceElement.setAttribute(
2850                ICXmlTags.IC_SERVICE_MAX_DURATION_IN_MINUTE_ATTRIBUTE, "" //$NON-NLS-1$
2860                        + this.maxDurationInMinute);
2870        serviceElement.setAttribute(
2880                ICXmlTags.IC_SERVICE_CARE_ABOUT_MAX_DURATION_ATTRIBUTE, "" //$NON-NLS-1$
2890                        + this.careAboutMaxDuration);
2900 
2910        Element nameElement = document
2920                .createElement(ICXmlTags.IC_SERVICE_NAME_TAG);
2930        nameElement.setAttribute(ICXmlTags.IC_VALUE_ATTRIBUTE, this.name);
2940        serviceElement.appendChild(nameElement);
2950 
2960        Element rateTypeElement = document
2970                .createElement(ICXmlTags.IC_SERVICE_RATE_TYPE_TAG);
2980        rateTypeElement.setAttribute(ICXmlTags.IC_VALUE_ATTRIBUTE,
2990                this.rateType);
3000        serviceElement.appendChild(rateTypeElement);
3010 
3020        Element baseRateElement = document
3030                .createElement(ICXmlTags.IC_SERVICE_BASE_RATE_TAG);
3040        baseRateElement.setAttribute(ICXmlTags.IC_VALUE_ATTRIBUTE, "" //$NON-NLS-1$
3050                + this.baseRate);
3060        serviceElement.appendChild(baseRateElement);
3070 
3080        Element descriptionElement = document
3090                .createElement(ICXmlTags.IC_SERVICE_DESCRIPTION_TAG);
3100        descriptionElement.setAttribute(ICXmlTags.IC_VALUE_ATTRIBUTE,
3110                this.description);
3120        serviceElement.appendChild(descriptionElement);
3130 
3140        return serviceElement;
3150    }
316  
317 }

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.