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


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