Source Code Cross Referenced for RuleDay.java in  » 6.0-JDK-Modules-sun » tools » sun » tools » javazic » 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 » 6.0 JDK Modules sun » tools » sun.tools.javazic 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2000-2004 Sun Microsystems, Inc.  All Rights Reserved.
003:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004:         *
005:         * This code is free software; you can redistribute it and/or modify it
006:         * under the terms of the GNU General Public License version 2 only, as
007:         * published by the Free Software Foundation.  Sun designates this
008:         * particular file as subject to the "Classpath" exception as provided
009:         * by Sun in the LICENSE file that accompanied this code.
010:         *
011:         * This code is distributed in the hope that it will be useful, but WITHOUT
012:         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013:         * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014:         * version 2 for more details (a copy is included in the LICENSE file that
015:         * accompanied this code).
016:         *
017:         * You should have received a copy of the GNU General Public License version
018:         * 2 along with this work; if not, write to the Free Software Foundation,
019:         * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020:         *
021:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022:         * CA 95054 USA or visit www.sun.com if you need additional information or
023:         * have any questions.
024:         */
025:
026:        package sun.tools.javazic;
027:
028:        import java.util.ArrayList;
029:        import java.util.HashMap;
030:        import java.util.List;
031:        import java.util.Map;
032:
033:        /**
034:         * RuleDay class represents the value of the "ON" field.  The day of
035:         * week values start from 1 following the {@link java.util.Calendar}
036:         * convention.
037:         *
038:         * @since 1.4
039:         */
040:        class RuleDay {
041:            private static final Map<String, DayOfWeek> abbreviations = new HashMap<String, DayOfWeek>(
042:                    7);
043:            static {
044:                for (DayOfWeek day : DayOfWeek.values()) {
045:                    abbreviations.put(day.getAbbr(), day);
046:                }
047:            }
048:
049:            private String dayName = null;
050:            private DayOfWeek dow;
051:            private boolean lastOne = false;
052:            private int soonerOrLater = 0;
053:            private int thanDayOfMonth; // day of month (e.g., 8 for "Sun>=8")
054:
055:            RuleDay() {
056:            }
057:
058:            RuleDay(int day) {
059:                thanDayOfMonth = day;
060:            }
061:
062:            int getDay() {
063:                return thanDayOfMonth;
064:            }
065:
066:            /**
067:             * @return the day of week value (1-based)
068:             */
069:            int getDayOfWeekNum() {
070:                return dow.value();
071:            }
072:
073:            /**
074:             * @return true if this rule day represents the last day of
075:             * week. (e.g., lastSun).
076:             */
077:            boolean isLast() {
078:                return lastOne;
079:            }
080:
081:            /**
082:             * @return true if this rule day represents the day of week on or
083:             * later than (after) the {@link #getDay}. (e.g., Sun>=1)
084:             */
085:            boolean isLater() {
086:                return soonerOrLater > 0;
087:            }
088:
089:            /**
090:             * @return true if this rule day represents the day of week on or
091:             * earlier than (before) the {@link #getDay}. (e.g., Sun<=15)
092:             */
093:            boolean isEarlier() {
094:                return soonerOrLater < 0;
095:            }
096:
097:            /**
098:             * @return true if this rule day represents an exact day.
099:             */
100:            boolean isExact() {
101:                return soonerOrLater == 0;
102:            }
103:
104:            /**
105:             * Parses the "ON" field and constructs a RuleDay.
106:             * @param day an "ON" field string (e.g., "Sun>=1")
107:             * @return a RuleDay representing the given "ON" field
108:             */
109:            static RuleDay parse(String day) {
110:                RuleDay d = new RuleDay();
111:                if (day.startsWith("last")) {
112:                    d.lastOne = true;
113:                    d.dayName = day.substring(4);
114:                    d.dow = getDOW(d.dayName);
115:                } else {
116:                    int index;
117:                    if ((index = day.indexOf(">=")) != -1) {
118:                        d.dayName = day.substring(0, index);
119:                        d.dow = getDOW(d.dayName);
120:                        d.soonerOrLater = 1; // greater or equal
121:                        d.thanDayOfMonth = Integer.parseInt(day
122:                                .substring(index + 2));
123:                    } else if ((index = day.indexOf("<=")) != -1) {
124:                        d.dayName = day.substring(0, index);
125:                        d.dow = getDOW(d.dayName);
126:                        d.soonerOrLater = -1; // less or equal
127:                        d.thanDayOfMonth = Integer.parseInt(day
128:                                .substring(index + 2));
129:                    } else {
130:                        // it should be an integer value.
131:                        d.thanDayOfMonth = Integer.parseInt(day);
132:                    }
133:                }
134:                return d;
135:            }
136:
137:            /**
138:             * Converts this RuleDay to the SimpleTimeZone day rule.
139:             * @return the converted SimpleTimeZone day rule
140:             */
141:            int getDayForSimpleTimeZone() {
142:                if (isLast()) {
143:                    return -1;
144:                }
145:                return getDay();
146:            }
147:
148:            /**
149:             * Converts this RuleDay to the SimpleTimeZone day-of-week rule.
150:             * @return the SimpleTimeZone day-of-week rule value
151:             */
152:            int getDayOfWeekForSimpleTimeZoneInt() {
153:                if (!isLater() && !isEarlier() && !isLast()) {
154:                    return 0;
155:                }
156:                if (isLater()) {
157:                    return -getDayOfWeekNum();
158:                }
159:                return getDayOfWeekNum();
160:            }
161:
162:            /**
163:             * @return the string representation of the {@link
164:             * #getDayOfWeekForSimpleTimeZoneInt} value
165:             */
166:            String getDayOfWeekForSimpleTimeZone() {
167:                int d = getDayOfWeekForSimpleTimeZoneInt();
168:                if (d == 0) {
169:                    return "0";
170:                }
171:                String sign = "";
172:                if (d < 0) {
173:                    sign = "-";
174:                    d = -d;
175:                }
176:                return sign + toString(d);
177:            }
178:
179:            private static DayOfWeek getDOW(String abbr) {
180:                return abbreviations.get(abbr);
181:            }
182:
183:            /**
184:             * Converts the specified day of week value to the day-of-week
185:             * name defined in {@link java.util.Calenda}.
186:             * @param dow 1-based day of week value
187:             * @return the Calendar day of week name with "Calendar." prefix.
188:             * @throws IllegalArgumentException if the specified dow value is out of range.
189:             */
190:            static String toString(int dow) {
191:                if (dow >= DayOfWeek.SUNDAY.value()
192:                        && dow <= DayOfWeek.SATURDAY.value()) {
193:                    return "Calendar." + DayOfWeek.values()[dow - 1];
194:                }
195:                throw new IllegalArgumentException("wrong Day_of_Week number: "
196:                        + dow);
197:            }
198:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.