KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > proactive > p2p > peerconfiguration > ScheduleBean


1 package org.objectweb.proactive.p2p.peerconfiguration;
2 import java.util.*;
3
4 /*
5  * Created on Jan 21, 2004
6  *
7  * To change the template for this generated file go to
8  * Window>Preferences>Java>Code Generation>Code and Comments
9  */

10
11 /**
12  * @author jbustos
13  *
14  * To change the template for this generated type comment go to
15  * Window>Preferences>Java>Code Generation>Code and Comments
16  */

17 public class ScheduleBean {
18 private double maxLoad;
19 private int days;
20 private int startTime;
21 private int workTime;
22 private GregorianCalendar begin;
23 private GregorianCalendar end;
24
25 public ScheduleBean() {
26     maxLoad=0;
27     days = 0;
28     startTime = 0;
29     workTime=0;
30     begin = null;
31     end = null;
32 }
33
34 /******************** SETTERS ***************************/
35
36 public void setMaxLoad(double maxLoad) {
37     this.maxLoad = maxLoad;
38 }
39
40 public void setDays (int days) {
41     this.days = days;
42 }
43
44 public void setStartTime (int startTime) {
45     this.startTime = startTime;
46 }
47
48 public void setWorkTime (int workTime) {
49     this.workTime = workTime;
50 }
51
52 public void setBegin(GregorianCalendar begin) {
53     this.begin = begin;
54 }
55
56 public void setEnd(GregorianCalendar end) {
57     this.end=end;
58 }
59 /******************** GETTERS *****************************/
60
61
62 public double getMaxLoad() {
63     return maxLoad;
64 }
65
66 public int getDays() {
67     return days;
68 }
69
70 public int getStartTime() {
71     return startTime;
72 }
73
74 public int getWorkTime() {
75     return workTime;
76 }
77
78 public GregorianCalendar getBegin() {
79     return begin;
80 }
81
82 public GregorianCalendar getEnd() {
83     return end;
84 }
85
86 /********************* other methods ************************/
87
88 /* The days are scheduled in a long string "Monday, Fryday, etc"
89  * This method traduce that string to an internal representation (bit = 1 => valid day)
90  */

91  
92 public int Days2Byte(String JavaDoc strDays) {
93     strDays = strDays.trim();
94     
95     int internal = 0;
96     String JavaDoc days[] = strDays.split(" ");
97     
98     String JavaDoc[] week = {"Sunday","Monday", "Tuesday","Wednesday", "Thursday","Friday", "Saturday"};
99     int j=days.length-1;
100     for (int i=week.length-1; i >=0 ; i--) {
101         internal = internal << 1;
102         if (j >=0 && week[i].equals(days[j])) {
103             internal++;
104             j--;
105         }
106     }
107     
108     return internal;
109 }
110
111 /*
112  * This method return true if, by calendar, the load balancer has to work today
113  */

114  
115 public boolean WorkToday() {
116     Calendar today= Calendar.getInstance();
117     
118     if (begin==null && end == null) return true;
119      
120     if (today.after(begin) && today.before(end)) {
121         today.setFirstDayOfWeek(Calendar.SUNDAY);
122         int weekday = (int) Math.round(Math.pow(2,today.get(Calendar.DAY_OF_WEEK)-1));
123         return (days & weekday) != 0;
124     }
125     return false;
126 }
127
128 }
129
Popular Tags