Source Code Cross Referenced for BuddhistChronology.java in  » Development » Joda-Time » org » joda » time » chrono » 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 » Development » Joda Time » org.joda.time.chrono 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Copyright 2001-2005 Stephen Colebourne
003:         *
004:         *  Licensed under the Apache License, Version 2.0 (the "License");
005:         *  you may not use this file except in compliance with the License.
006:         *  You may obtain a copy 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,
012:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         *  See the License for the specific language governing permissions and
014:         *  limitations under the License.
015:         */
016:        package org.joda.time.chrono;
017:
018:        import java.util.HashMap;
019:        import java.util.Map;
020:
021:        import org.joda.time.Chronology;
022:        import org.joda.time.DateTime;
023:        import org.joda.time.DateTimeConstants;
024:        import org.joda.time.DateTimeField;
025:        import org.joda.time.DateTimeFieldType;
026:        import org.joda.time.DateTimeZone;
027:        import org.joda.time.field.DelegatedDateTimeField;
028:        import org.joda.time.field.DividedDateTimeField;
029:        import org.joda.time.field.OffsetDateTimeField;
030:        import org.joda.time.field.RemainderDateTimeField;
031:        import org.joda.time.field.SkipUndoDateTimeField;
032:
033:        /**
034:         * A chronology that matches the BuddhistCalendar class supplied by Sun.
035:         * <p>
036:         * The chronology is identical to the Gregorian/Julian, except that the
037:         * year is offset by +543 and the era is named 'BE' for Buddhist Era.
038:         * <p>
039:         * This class was intended by Sun to model the calendar used in Thailand.
040:         * However, the actual rules for Thailand are much more involved than
041:         * this class covers. (This class is accurate after 1941-01-01 ISO).
042:         * <p>
043:         * This chronlogy is being retained for those who want a same effect
044:         * replacement for the Sun class. It is hoped that community support will
045:         * enable a more accurate chronology for Thailand, to be developed.
046:         * <p>
047:         * BuddhistChronology is thread-safe and immutable.
048:         *
049:         * @author Stephen Colebourne
050:         * @author Brian S O'Neill
051:         * @since 1.0
052:         */
053:        public final class BuddhistChronology extends AssembledChronology {
054:
055:            /** Serialization lock */
056:            private static final long serialVersionUID = -3474595157769370126L;
057:
058:            /**
059:             * Constant value for 'Buddhist Era', equivalent to the value returned
060:             * for AD/CE. Note that this differs from the constant in BuddhistCalendar.
061:             */
062:            public static final int BE = DateTimeConstants.CE;
063:
064:            /** A singleton era field. */
065:            private static final DateTimeField ERA_FIELD = new BasicSingleEraDateTimeField(
066:                    "BE");
067:
068:            /** Number of years difference in calendars. */
069:            private static final int BUDDHIST_OFFSET = 543;
070:
071:            /** Cache of zone to chronology */
072:            private static final Map cCache = new HashMap();
073:
074:            /** UTC instance of the chronology */
075:            private static final BuddhistChronology INSTANCE_UTC = getInstance(DateTimeZone.UTC);
076:
077:            /**
078:             * Standard instance of a Buddhist Chronology, that matches
079:             * Sun's BuddhistCalendar class. This means that it follows the
080:             * GregorianJulian calendar rules with a cutover date.
081:             * <p>
082:             * The time zone of the returned instance is UTC.
083:             */
084:            public static BuddhistChronology getInstanceUTC() {
085:                return INSTANCE_UTC;
086:            }
087:
088:            /**
089:             * Standard instance of a Buddhist Chronology, that matches
090:             * Sun's BuddhistCalendar class. This means that it follows the
091:             * GregorianJulian calendar rules with a cutover date.
092:             */
093:            public static BuddhistChronology getInstance() {
094:                return getInstance(DateTimeZone.getDefault());
095:            }
096:
097:            /**
098:             * Standard instance of a Buddhist Chronology, that matches
099:             * Sun's BuddhistCalendar class. This means that it follows the
100:             * GregorianJulian calendar rules with a cutover date.
101:             *
102:             * @param zone  the time zone to use, null is default
103:             */
104:            public static synchronized BuddhistChronology getInstance(
105:                    DateTimeZone zone) {
106:                if (zone == null) {
107:                    zone = DateTimeZone.getDefault();
108:                }
109:                BuddhistChronology chrono = (BuddhistChronology) cCache
110:                        .get(zone);
111:                if (chrono == null) {
112:                    // First create without a lower limit.
113:                    chrono = new BuddhistChronology(GJChronology.getInstance(
114:                            zone, null), null);
115:                    // Impose lower limit and make another BuddhistChronology.
116:                    DateTime lowerLimit = new DateTime(1, 1, 1, 0, 0, 0, 0,
117:                            chrono);
118:                    chrono = new BuddhistChronology(LimitChronology
119:                            .getInstance(chrono, lowerLimit, null), "");
120:                    cCache.put(zone, chrono);
121:                }
122:                return chrono;
123:            }
124:
125:            // Constructors and instance variables
126:            //-----------------------------------------------------------------------
127:
128:            /**
129:             * Restricted constructor.
130:             *
131:             * @param param if non-null, then don't change the field set
132:             */
133:            private BuddhistChronology(Chronology base, Object param) {
134:                super (base, param);
135:            }
136:
137:            /**
138:             * Serialization singleton
139:             */
140:            private Object readResolve() {
141:                Chronology base = getBase();
142:                return base == null ? getInstanceUTC() : getInstance(base
143:                        .getZone());
144:            }
145:
146:            // Conversion
147:            //-----------------------------------------------------------------------
148:            /**
149:             * Gets the Chronology in the UTC time zone.
150:             * 
151:             * @return the chronology in UTC
152:             */
153:            public Chronology withUTC() {
154:                return INSTANCE_UTC;
155:            }
156:
157:            /**
158:             * Gets the Chronology in a specific time zone.
159:             * 
160:             * @param zone  the zone to get the chronology in, null is default
161:             * @return the chronology
162:             */
163:            public Chronology withZone(DateTimeZone zone) {
164:                if (zone == null) {
165:                    zone = DateTimeZone.getDefault();
166:                }
167:                if (zone == getZone()) {
168:                    return this ;
169:                }
170:                return getInstance(zone);
171:            }
172:
173:            // Output
174:            //-----------------------------------------------------------------------
175:            /**
176:             * Gets a debugging toString.
177:             * 
178:             * @return a debugging string
179:             */
180:            public String toString() {
181:                String str = "BuddhistChronology";
182:                DateTimeZone zone = getZone();
183:                if (zone != null) {
184:                    str = str + '[' + zone.getID() + ']';
185:                }
186:                return str;
187:            }
188:
189:            protected void assemble(Fields fields) {
190:                if (getParam() == null) {
191:                    // julian chrono removed zero, but we need to put it back
192:                    DateTimeField field = fields.year;
193:                    fields.year = new OffsetDateTimeField(
194:                            new SkipUndoDateTimeField(this , field),
195:                            BUDDHIST_OFFSET);
196:
197:                    // one era, so yearOfEra is the same
198:                    field = fields.yearOfEra;
199:                    fields.yearOfEra = new DelegatedDateTimeField(fields.year,
200:                            DateTimeFieldType.yearOfEra());
201:
202:                    // julian chrono removed zero, but we need to put it back
203:                    field = fields.weekyear;
204:                    fields.weekyear = new OffsetDateTimeField(
205:                            new SkipUndoDateTimeField(this , field),
206:                            BUDDHIST_OFFSET);
207:
208:                    field = new OffsetDateTimeField(fields.yearOfEra, 99);
209:                    fields.centuryOfEra = new DividedDateTimeField(field,
210:                            DateTimeFieldType.centuryOfEra(), 100);
211:
212:                    field = new RemainderDateTimeField(
213:                            (DividedDateTimeField) fields.centuryOfEra);
214:                    fields.yearOfCentury = new OffsetDateTimeField(field,
215:                            DateTimeFieldType.yearOfCentury(), 1);
216:
217:                    field = new RemainderDateTimeField(fields.weekyear,
218:                            DateTimeFieldType.weekyearOfCentury(), 100);
219:                    fields.weekyearOfCentury = new OffsetDateTimeField(field,
220:                            DateTimeFieldType.weekyearOfCentury(), 1);
221:
222:                    fields.era = ERA_FIELD;
223:                }
224:            }
225:
226:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.