BrightSide Workbench Full Report + Source Code
Constraints.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 package org.turro.scheduler.motor;
19 
20 import java.util.Date;
21 import org.jdom.Element;
22 import org.turro.scheduler.constraints.DayOfMonthConstraint;
23 import org.turro.scheduler.constraints.HourConstraint;
24 import org.turro.scheduler.constraints.MinuteConstraint;
25 import org.turro.scheduler.constraints.MonthConstraint;
26 import org.turro.scheduler.constraints.WeekDayConstraint;
27 
32 @Deprecated
33 public class Constraints {
34 
35  private final MonthConstraint months = new MonthConstraint();
36  private final DayOfMonthConstraint daysOfMonth = new DayOfMonthConstraint();
37  private final WeekDayConstraint weekDays = new WeekDayConstraint();
38  private final HourConstraint hours = new HourConstraint();
39  private final MinuteConstraint minutes = new MinuteConstraint();
40 
42  return daysOfMonth;
43  }
44 
46  return hours;
47  }
48 
50  return minutes;
51  }
52 
54  return months;
55  }
56 
58  return weekDays;
59  }
60 
61  public boolean isValid(Date date) {
62  if(isEmpty()) {
63  return false;
64  }
65  boolean valid = months.isValid(date);
66  if(valid) valid = daysOfMonth.isValid(date);
67  if(valid) valid = weekDays.isValid(date);
68  if(valid) valid = hours.isValid(date);
69  if(valid) valid = minutes.isValid(date);
70  return valid;
71  }
72 
73  public boolean needsRefresh() {
74  if(isEmpty()) {
75  return false;
76  }
77  boolean refresh = months.needsRefresh();
78  if(!refresh) refresh = daysOfMonth.needsRefresh();
79  if(!refresh) refresh = weekDays.needsRefresh();
80  if(!refresh) refresh = hours.needsRefresh();
81  if(!refresh) refresh = minutes.needsRefresh();
82  return refresh;
83  }
84 
85  public boolean isEmpty() {
86  return months.isEmpty() && daysOfMonth.isEmpty() &&
87  weekDays.isEmpty() && hours.isEmpty() && minutes.isEmpty();
88  }
89 
90  public void readXML(Element root) {
91  months.readXML(root.getChild("months"));
92  daysOfMonth.readXML(root.getChild("days-of-month"));
93  weekDays.readXML(root.getChild("week-days"));
94  hours.readXML(root.getChild("hours"));
95  minutes.readXML(root.getChild("minutes"));
96  }
97 
98  public void writeXML(Element root) {
99  Element el = new Element("months");
100  root.addContent(el);
101  months.writeXML(el);
102 
103  el = new Element("days-of-month");
104  root.addContent(el);
105  daysOfMonth.writeXML(el);
106 
107  el = new Element("week-days");
108  root.addContent(el);
109  weekDays.writeXML(el);
110 
111  el = new Element("hours");
112  root.addContent(el);
113  hours.writeXML(el);
114 
115  el = new Element("minutes");
116  root.addContent(el);
117  minutes.writeXML(el);
118  }
119 
120 }
DayOfMonthConstraint getDaysOfMonth()