Source Code Cross Referenced for WeeklyCalendar.java in  » Project-Management » quartz » org » quartz » impl » calendar » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Project Management » quartz » org.quartz.impl.calendar 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* 
002:         * Copyright 2004-2005 OpenSymphony 
003:         * 
004:         * Licensed under the Apache License, Version 2.0 (the "License"); you may not 
005:         * use this file except in compliance with the License. You may obtain a copy 
006:         * of the License at 
007:         * 
008:         *   http://www.apache.org/licenses/LICENSE-2.0 
009:         *   
010:         * Unless required by applicable law or agreed to in writing, software 
011:         * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 
012:         * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 
013:         * License for the specific language governing permissions and limitations 
014:         * under the License.
015:         * 
016:         */
017:
018:        /*
019:         * Previously Copyright (c) 2001-2004 James House
020:         * and Juergen Donnerstag (c) 2002, EDS 2002
021:         */
022:
023:        package org.quartz.impl.calendar;
024:
025:        import java.io.Serializable;
026:        import java.util.TimeZone;
027:
028:        import org.quartz.Calendar;
029:
030:        /**
031:         * <p>
032:         * This implementation of the Calendar excludes a set of days of the week. You
033:         * may use it to exclude weekends for example. But you may define any day of
034:         * the week.  By default it excludes SATURDAY and SUNDAY.
035:         * </p>
036:         * 
037:         * @see org.quartz.Calendar
038:         * @see org.quartz.impl.calendar.BaseCalendar
039:         * 
040:         * @author Juergen Donnerstag
041:         */
042:        public class WeeklyCalendar extends BaseCalendar implements  Calendar,
043:                Serializable {
044:            static final long serialVersionUID = -6809298821229007586L;
045:
046:            // An array to store the week days which are to be excluded.
047:            // java.util.Calendar.MONDAY etc. are used as index.
048:            private boolean[] excludeDays = new boolean[8];
049:
050:            // Will be set to true, if all week days are excluded
051:            private boolean excludeAll = false;
052:
053:            public WeeklyCalendar() {
054:                this (null, null);
055:            }
056:
057:            public WeeklyCalendar(Calendar baseCalendar) {
058:                this (baseCalendar, null);
059:            }
060:
061:            public WeeklyCalendar(TimeZone timeZone) {
062:                super (null, timeZone);
063:            }
064:
065:            public WeeklyCalendar(Calendar baseCalendar, TimeZone timeZone) {
066:                super (baseCalendar, timeZone);
067:
068:                excludeDays[java.util.Calendar.SUNDAY] = true;
069:                excludeDays[java.util.Calendar.SATURDAY] = true;
070:                excludeAll = areAllDaysExcluded();
071:            }
072:
073:            /**
074:             * <p>
075:             * Get the array with the week days
076:             * </p>
077:             */
078:            public boolean[] getDaysExcluded() {
079:                return excludeDays;
080:            }
081:
082:            /**
083:             * <p>
084:             * Return true, if wday (see Calendar.get()) is defined to be exluded. E. g.
085:             * saturday and sunday.
086:             * </p>
087:             */
088:            public boolean isDayExcluded(int wday) {
089:                return excludeDays[wday];
090:            }
091:
092:            /**
093:             * <p>
094:             * Redefine the array of days excluded. The array must of size greater or
095:             * equal 8. java.util.Calendar's constants like MONDAY should be used as
096:             * index. A value of true is regarded as: exclude it.
097:             * </p>
098:             */
099:            public void setDaysExcluded(boolean[] weekDays) {
100:                if (weekDays == null) {
101:                    return;
102:                }
103:
104:                excludeDays = weekDays;
105:                excludeAll = areAllDaysExcluded();
106:            }
107:
108:            /**
109:             * <p>
110:             * Redefine a certain day of the week to be excluded (true) or included
111:             * (false). Use java.util.Calendar's constants like MONDAY to determine the
112:             * wday.
113:             * </p>
114:             */
115:            public void setDayExcluded(int wday, boolean exclude) {
116:                excludeDays[wday] = exclude;
117:                excludeAll = areAllDaysExcluded();
118:            }
119:
120:            /**
121:             * <p>
122:             * Check if all week days are excluded. That is no day is included.
123:             * </p>
124:             * 
125:             * @return boolean
126:             */
127:            public boolean areAllDaysExcluded() {
128:                return isDayExcluded(java.util.Calendar.SUNDAY)
129:                        && isDayExcluded(java.util.Calendar.MONDAY)
130:                        && isDayExcluded(java.util.Calendar.TUESDAY)
131:                        && isDayExcluded(java.util.Calendar.WEDNESDAY)
132:                        && isDayExcluded(java.util.Calendar.THURSDAY)
133:                        && isDayExcluded(java.util.Calendar.FRIDAY)
134:                        && isDayExcluded(java.util.Calendar.SATURDAY);
135:            }
136:
137:            /**
138:             * <p>
139:             * Determine whether the given time (in milliseconds) is 'included' by the
140:             * Calendar.
141:             * </p>
142:             * 
143:             * <p>
144:             * Note that this Calendar is only has full-day precision.
145:             * </p>
146:             */
147:            public boolean isTimeIncluded(long timeStamp) {
148:                if (excludeAll == true) {
149:                    return false;
150:                }
151:
152:                // Test the base calendar first. Only if the base calendar not already
153:                // excludes the time/date, continue evaluating this calendar instance.
154:                if (super .isTimeIncluded(timeStamp) == false) {
155:                    return false;
156:                }
157:
158:                java.util.Calendar cl = createJavaCalendar(timeStamp);
159:                int wday = cl.get(java.util.Calendar.DAY_OF_WEEK);
160:
161:                return !(isDayExcluded(wday));
162:            }
163:
164:            /**
165:             * <p>
166:             * Determine the next time (in milliseconds) that is 'included' by the
167:             * Calendar after the given time. Return the original value if timeStamp is
168:             * included. Return 0 if all days are excluded.
169:             * </p>
170:             * 
171:             * <p>
172:             * Note that this Calendar is only has full-day precision.
173:             * </p>
174:             */
175:            public long getNextIncludedTime(long timeStamp) {
176:                if (excludeAll == true) {
177:                    return 0;
178:                }
179:
180:                // Call base calendar implementation first
181:                long baseTime = super .getNextIncludedTime(timeStamp);
182:                if ((baseTime > 0) && (baseTime > timeStamp)) {
183:                    timeStamp = baseTime;
184:                }
185:
186:                // Get timestamp for 00:00:00
187:                java.util.Calendar cl = getStartOfDayJavaCalendar(timeStamp);
188:                int wday = cl.get(java.util.Calendar.DAY_OF_WEEK);
189:
190:                if (!isDayExcluded(wday)) {
191:                    return timeStamp; // return the original value
192:                }
193:
194:                while (isDayExcluded(wday) == true) {
195:                    cl.add(java.util.Calendar.DATE, 1);
196:                    wday = cl.get(java.util.Calendar.DAY_OF_WEEK);
197:                }
198:
199:                return cl.getTime().getTime();
200:            }
201:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.