KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > tasklist > usertasks > model > Duration


1 package org.netbeans.modules.tasklist.usertasks.model;
2
3 /**
4  * A duration class.
5  */

6 public class Duration {
7     public int weeks, days, hours, minutes;
8     
9     /**
10      * Constructor.
11      *
12      * @param minutes duration in minutes
13      * @param hoursPerDay working hours per day
14      * @param daysPerWeek working days per week
15      */

16     public Duration(int weeks, int days, int hours, int minutes) {
17         this.weeks = weeks;
18         this.days = days;
19         this.hours = hours;
20         this.minutes = minutes;
21     }
22     
23     /**
24      * Constructor.
25      *
26      * @param minutes duration in minutes
27      * @param hoursPerDay working hours per day
28      * @param daysPerWeek working days per week
29      */

30     public Duration(int minutes, int hoursPerDay, int daysPerWeek) {
31         this.minutes = minutes % 60;
32         minutes /= 60;
33         this.hours = minutes % hoursPerDay;
34         minutes /= hoursPerDay;
35         this.days = minutes % daysPerWeek;
36         minutes /= daysPerWeek;
37         this.weeks = minutes;
38     }
39
40     /**
41      * Constructor.
42      *
43      * @param minutes duration in minutes
44      * @param minutesPerDay working minutes per day
45      * @param daysPerWeek working days per week
46      * @param ignored will be ignored
47      */

48     public Duration(int minutes, int minutesPerDay, int daysPerWeek,
49             boolean ignored) {
50         this.minutes = minutes % minutesPerDay;
51         this.hours = this.minutes / 60;
52         this.minutes = this.minutes % 60;
53         
54         this.days = minutes / minutesPerDay;
55         this.weeks = this.days / daysPerWeek;
56         this.days = this.days % daysPerWeek;
57     }
58
59     /**
60      * Converts the value to minutes.
61      *
62      * @param hoursPerDay hours per day
63      * @param daysPerWeek days per week
64      */

65     public int toMinutes(int hoursPerDay, int daysPerWeek) {
66         return ((weeks * daysPerWeek + days) * hoursPerDay + hours) * 60 +
67                 minutes;
68     }
69
70     /**
71      * Converts the value to minutes.
72      *
73      * @param minutesPerDay minutes per day
74      * @param daysPerWeek days per week
75      * @param ignore will be ignored
76      */

77     public int toMinutes(int minutesPerDay, int daysPerWeek, boolean ignore) {
78         return (weeks * daysPerWeek + days) * minutesPerDay + hours * 60 +
79                 minutes;
80     }
81
82     public boolean equals(Object JavaDoc obj) {
83         if (!(obj instanceof Duration))
84             return false;
85         Duration d = (Duration) obj;
86         return d.weeks == weeks && d.days == days && d.hours == hours &&
87                 d.minutes == minutes;
88     }
89 }
90
Popular Tags