]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-4_4_2-src/main/classes/core/src/com/ibm/icu/util/JapaneseCalendar.java
go
[Dictionary.git] / jars / icu4j-4_4_2-src / main / classes / core / src / com / ibm / icu / util / JapaneseCalendar.java
1 /*\r
2  *******************************************************************************\r
3  * Copyright (C) 1996-2010, International Business Machines Corporation and    *\r
4  * others. All Rights Reserved.                                                *\r
5  *******************************************************************************\r
6  */\r
7 package com.ibm.icu.util;\r
8 import java.util.Date;\r
9 import java.util.Locale;\r
10 \r
11 /**\r
12  * <code>JapaneseCalendar</code> is a subclass of <code>GregorianCalendar</code>\r
13  * that numbers years and eras based on the reigns of the Japanese emperors.\r
14  * The Japanese calendar is identical to the Gregorian calendar in all respects\r
15  * except for the year and era.  The ascension of each  emperor to the throne\r
16  * begins a new era, and the years of that era are numbered starting with the\r
17  * year of ascension as year 1.\r
18  * <p>\r
19  * Note that in the year of an imperial ascension, there are two possible sets\r
20  * of year and era values: that for the old era and for the new.  For example, a\r
21  * new era began on January 7, 1989 AD.  Strictly speaking, the first six days\r
22  * of that year were in the Showa era, e.g. "January 6, 64 Showa", while the rest\r
23  * of the year was in the Heisei era, e.g. "January 7, 1 Heisei".  This class\r
24  * handles this distinction correctly when computing dates.  However, in lenient\r
25  * mode either form of date is acceptable as input. \r
26  * <p>\r
27  * In modern times, eras have started on January 8, 1868 AD, Gregorian (Meiji),\r
28  * July 30, 1912 (Taisho), December 25, 1926 (Showa), and January 7, 1989 (Heisei).  Constants\r
29  * for these eras, suitable for use in the <code>ERA</code> field, are provided\r
30  * in this class.  Note that the <em>number</em> used for each era is more or\r
31  * less arbitrary.  Currently, the era starting in 1053 AD is era #0; however this\r
32  * may change in the future as we add more historical data.  Use the predefined\r
33  * constants rather than using actual, absolute numbers.\r
34  * <p>\r
35  * This class should not be subclassed.</p>\r
36  * <p>\r
37  * JapaneseCalendar usually should be instantiated using \r
38  * {@link com.ibm.icu.util.Calendar#getInstance(ULocale)} passing in a <code>ULocale</code>\r
39  * with the tag <code>"@calendar=japanese"</code>.</p>\r
40  *\r
41  * @see com.ibm.icu.util.GregorianCalendar\r
42  * @see com.ibm.icu.util.Calendar\r
43  *\r
44  * @author Laura Werner\r
45  * @author Alan Liu\r
46  * @stable ICU 2.8\r
47  */\r
48 public class JapaneseCalendar extends GregorianCalendar {\r
49     // jdk1.4.2 serialver\r
50     private static final long serialVersionUID = -2977189902603704691L;\r
51 \r
52     //-------------------------------------------------------------------------\r
53     // Constructors...\r
54     //-------------------------------------------------------------------------\r
55 \r
56     /**\r
57      * Constructs a default <code>JapaneseCalendar</code> using the current time\r
58      * in the default time zone with the default locale.\r
59      * @stable ICU 2.8\r
60      */\r
61     public JapaneseCalendar() {\r
62         super();\r
63     }\r
64 \r
65     /**\r
66      * Constructs a <code>JapaneseCalendar</code> based on the current time\r
67      * in the given time zone with the default locale.\r
68      * @param zone the given time zone.\r
69      * @stable ICU 2.8\r
70      */\r
71     public JapaneseCalendar(TimeZone zone) {\r
72         super(zone);\r
73     }\r
74 \r
75     /**\r
76      * Constructs a <code>JapaneseCalendar</code> based on the current time\r
77      * in the default time zone with the given locale.\r
78      * @param aLocale the given locale.\r
79      * @stable ICU 2.8\r
80      */\r
81     public JapaneseCalendar(Locale aLocale) {\r
82         super(aLocale);\r
83     }\r
84 \r
85     /**\r
86      * Constructs a <code>JapaneseCalendar</code> based on the current time\r
87      * in the default time zone with the given locale.\r
88      * @param locale the given ulocale.\r
89      * @stable ICU 3.2\r
90      */\r
91     public JapaneseCalendar(ULocale locale) {\r
92         super(locale);\r
93     }\r
94 \r
95     /**\r
96      * Constructs a <code>JapaneseCalendar</code> based on the current time\r
97      * in the given time zone with the given locale.\r
98      *\r
99      * @param zone the given time zone.\r
100      *\r
101      * @param aLocale the given locale.\r
102      * @stable ICU 2.8\r
103      */\r
104     public JapaneseCalendar(TimeZone zone, Locale aLocale) {\r
105         super(zone, aLocale);\r
106     }\r
107 \r
108     /**\r
109      * Constructs a <code>JapaneseCalendar</code> based on the current time\r
110      * in the given time zone with the given locale.\r
111      *\r
112      * @param zone the given time zone.\r
113      *\r
114      * @param locale the given ulocale.\r
115      * @stable ICU 3.2\r
116      */\r
117     public JapaneseCalendar(TimeZone zone, ULocale locale) {\r
118         super(zone, locale);\r
119     }\r
120 \r
121     /**\r
122      * Constructs a <code>JapaneseCalendar</code> with the given date set\r
123      * in the default time zone with the default locale.\r
124      *\r
125      * @param date      The date to which the new calendar is set.\r
126      * @stable ICU 2.8\r
127      */\r
128     public JapaneseCalendar(Date date) {\r
129         this();\r
130         setTime(date);\r
131     }\r
132 \r
133     /**\r
134      * Constructs a <code>JapaneseCalendar</code> with the given date set\r
135      * in the default time zone with the default locale.\r
136      *\r
137      * @param era       The imperial era used to set the calendar's {@link #ERA ERA} field.\r
138      *                  Eras are numbered starting with the Tenki era, which\r
139      *                  began in 1053 AD Gregorian, as era zero.  Recent\r
140      *                  eras can be specified using the constants\r
141      *                  {@link #MEIJI} (which started in 1868 AD),\r
142      *                  {@link #TAISHO} (1912 AD),\r
143      *                  {@link #SHOWA} (1926 AD), and\r
144      *                  {@link #HEISEI} (1989 AD).\r
145      *\r
146      * @param year      The value used to set the calendar's {@link #YEAR YEAR} field,\r
147      *                  in terms of the era.\r
148      *\r
149      * @param month     The value used to set the calendar's {@link #MONTH MONTH} field.\r
150      *                  The value is 0-based. e.g., 0 for January.\r
151      *\r
152      * @param date      The value used to set the calendar's DATE field.\r
153      * @stable ICU 2.8\r
154      */\r
155     public JapaneseCalendar(int era, int year, int month, int date) {\r
156         super(year, month, date);\r
157         set(ERA, era);\r
158     }\r
159 \r
160     /**\r
161      * Constructs a <code>JapaneseCalendar</code> with the given date set\r
162      * in the default time zone with the default locale.\r
163      *\r
164      * @param year      The value used to set the calendar's {@link #YEAR YEAR} field,\r
165      *                  in the era Heisei, the most current at the time this\r
166      *                  class was last updated.\r
167      *\r
168      * @param month     The value used to set the calendar's {@link #MONTH MONTH} field.\r
169      *                  The value is 0-based. e.g., 0 for January.\r
170      *\r
171      * @param date      The value used to set the calendar's {@link #DATE DATE} field.\r
172      * @stable ICU 2.8\r
173      */\r
174     public JapaneseCalendar(int year, int month, int date) {\r
175         super(year, month, date);\r
176         set(ERA, CURRENT_ERA);\r
177     }\r
178 \r
179     /**\r
180      * Constructs a <code>JapaneseCalendar</code> with the given date\r
181      * and time set for the default time zone with the default locale.\r
182      *\r
183      * @param year      The value used to set the calendar's {@link #YEAR YEAR} time field,\r
184      *                  in the era Heisei, the most current at the time of this\r
185      *                  writing.\r
186      *\r
187      * @param month     The value used to set the calendar's {@link #MONTH MONTH} time field.\r
188      *                  The value is 0-based. e.g., 0 for January.\r
189      *\r
190      * @param date      The value used to set the calendar's {@link #DATE DATE} time field.\r
191      *\r
192      * @param hour      The value used to set the calendar's {@link #HOUR_OF_DAY HOUR_OF_DAY} time field.\r
193      *\r
194      * @param minute    The value used to set the calendar's {@link #MINUTE MINUTE} time field.\r
195      *\r
196      * @param second    The value used to set the calendar's {@link #SECOND SECOND} time field.\r
197      * @stable ICU 2.8\r
198      */\r
199     public JapaneseCalendar(int year, int month, int date, int hour,\r
200                              int minute, int second)\r
201     {\r
202         super(year, month, date, hour, minute, second);\r
203         set(ERA, CURRENT_ERA);\r
204     }\r
205 \r
206     //-------------------------------------------------------------------------\r
207 \r
208     // Use 1970 as the default value of EXTENDED_YEAR\r
209     private static final int GREGORIAN_EPOCH = 1970;\r
210 \r
211     /**\r
212      * @stable ICU 2.8\r
213      */\r
214     protected int handleGetExtendedYear() {\r
215         // EXTENDED_YEAR in JapaneseCalendar is a Gregorian year\r
216         // The default value of EXTENDED_YEAR is 1970 (Showa 45)\r
217         int year;\r
218         if (newerField(EXTENDED_YEAR, YEAR) == EXTENDED_YEAR &&\r
219             newerField(EXTENDED_YEAR, ERA) == EXTENDED_YEAR) {\r
220             year = internalGet(EXTENDED_YEAR, GREGORIAN_EPOCH);\r
221         } else {\r
222             // extended year is a gregorian year, where 1 = 1AD,  0 = 1BC, -1 = 2BC, etc \r
223             year = internalGet(YEAR, 1)                       // pin to minimum of year 1 (first year)\r
224                     + ERAS[internalGet(ERA, CURRENT_ERA) * 3] // add gregorian starting year\r
225                     - 1;                                      // Subtract one because year starts at 1\r
226         }\r
227         return year;\r
228     }\r
229     \r
230     /**\r
231      * Called by handleComputeJulianDay.  Returns the default month (0-based) for the year,\r
232      * taking year and era into account.  Defaults to 0 (JANUARY) for Gregorian.\r
233      * @param extendedYear the extendedYear, as returned by handleGetExtendedYear\r
234      * @return the default month\r
235      * @provisional ICU 3.6\r
236      * @draft ICU 3.6 (retain)\r
237      * @see #MONTH\r
238      */\r
239     protected int getDefaultMonthInYear(int extendedYear)\r
240     {\r
241       int era = internalGet(ERA, CURRENT_ERA);\r
242       //computeFields(status); // No need to compute fields here - expect the caller already did so.\r
243 \r
244       // Find out if we are at the edge of an era\r
245       if(extendedYear == ERAS[era*3]) {\r
246         return ERAS[(era*3)+1] // month..\r
247             -1; // return 0-based month\r
248       } else {\r
249         return super.getDefaultMonthInYear(extendedYear);\r
250       }\r
251     }\r
252 \r
253     /**\r
254      * Called by handleComputeJulianDay.  Returns the default day (1-based) for the month,\r
255      * taking currently-set year and era into account.  Defaults to 1 for Gregorian.\r
256      * @param extendedYear the extendedYear, as returned by handleGetExtendedYear\r
257      * @param month the month, as returned by getDefaultMonthInYear\r
258      * @return the default day of the month\r
259      * @draft ICU 3.6 (retain)\r
260      * @provisional ICU 3.6\r
261      * @see #DAY_OF_MONTH\r
262      */\r
263     protected int getDefaultDayInMonth(int extendedYear, int month) {\r
264       int era = internalGet(ERA, CURRENT_ERA);\r
265           \r
266       if(extendedYear == ERAS[era*3]) { // if it is year 1..\r
267         if(month == ((ERAS[(era*3)+1])-1)) { // if it is the emperor's first month.. \r
268           return ERAS[(era*3)+2]; // return the D_O_M of acession\r
269         }\r
270       }\r
271 \r
272       return super.getDefaultDayInMonth(extendedYear, month);\r
273     }\r
274 \r
275     /**\r
276      * @stable ICU 2.8\r
277      */\r
278     protected void handleComputeFields(int julianDay) {\r
279         super.handleComputeFields(julianDay);\r
280         int year = internalGet(EXTENDED_YEAR);\r
281 \r
282         int low = 0;\r
283 \r
284         // Short circuit for recent years.  Most modern computations will\r
285         // occur in the current era and won't require the binary search.\r
286         // Note that if the year is == the current era year, then we use\r
287         // the binary search to handle the month/dom comparison.\r
288         if (year > ERAS[ERAS.length - 3]) {\r
289             low = CURRENT_ERA;\r
290         } else {\r
291             // Binary search\r
292             int high = ERAS.length / 3;\r
293         \r
294             while (low < high - 1) {\r
295                 int i = (low + high) / 2;\r
296                 int diff = year - ERAS[i*3];\r
297 \r
298                 // If years are the same, then compare the months, and if those\r
299                 // are the same, compare days of month.  In the ERAS array\r
300                 // months are 1-based for easier maintenance.\r
301                 if (diff == 0) {\r
302                     diff = internalGet(MONTH) - (ERAS[i*3 + 1] - 1);\r
303                     if (diff == 0) {\r
304                         diff = internalGet(DAY_OF_MONTH) - ERAS[i*3 + 2];\r
305                     }\r
306                 }\r
307                 if (diff >= 0) {\r
308                     low = i;\r
309                 } else {\r
310                     high = i;\r
311                 }\r
312             }\r
313         }\r
314 \r
315         // Now we've found the last era that starts before this date, so\r
316         // adjust the year to count from the start of that era.  Note that\r
317         // all dates before the first era will fall into the first era by\r
318         // the algorithm.\r
319         internalSet(ERA, low);\r
320         internalSet(YEAR, year - ERAS[low*3] + 1);\r
321     }\r
322 \r
323     private static final int[] ERAS = {\r
324     //  Gregorian date of each emperor's ascension\r
325     //  Years are AD, months are 1-based.\r
326     //  Year  Month Day\r
327          645,    6, 19,     // Taika\r
328          650,    2, 15,     // Hakuchi\r
329          672,    1,  1,     // Hakuho\r
330          686,    7, 20,     // Shucho\r
331          701,    3, 21,     // Taiho\r
332          704,    5, 10,     // Keiun\r
333          708,    1, 11,     // Wado\r
334          715,    9,  2,     // Reiki\r
335          717,   11, 17,     // Yoro\r
336          724,    2,  4,     // Jinki\r
337          729,    8,  5,     // Tempyo\r
338          749,    4, 14,     // Tempyo-kampo\r
339          749,    7,  2,     // Tempyo-shoho\r
340          757,    8, 18,     // Tempyo-hoji\r
341          765,    1,  7,     // Tempho-jingo\r
342          767,    8, 16,     // Jingo-keiun\r
343          770,   10,  1,     // Hoki\r
344          781,    1,  1,     // Ten-o\r
345          782,    8, 19,     // Enryaku\r
346          806,    5, 18,     // Daido\r
347          810,    9, 19,     // Konin\r
348          824,    1,  5,     // Tencho\r
349          834,    1,  3,     // Showa\r
350          848,    6, 13,     // Kajo\r
351          851,    4, 28,     // Ninju\r
352          854,   11, 30,     // Saiko\r
353          857,    2, 21,     // Tennan\r
354          859,    4, 15,     // Jogan\r
355          877,    4, 16,     // Genkei\r
356          885,    2, 21,     // Ninna\r
357          889,    4, 27,     // Kampyo\r
358          898,    4, 26,     // Shotai\r
359          901,    7, 15,     // Engi\r
360          923,    4, 11,     // Encho\r
361          931,    4, 26,     // Shohei\r
362          938,    5, 22,     // Tengyo\r
363          947,    4, 22,     // Tenryaku\r
364          957,   10, 27,     // Tentoku\r
365          961,    2, 16,     // Owa\r
366          964,    7, 10,     // Koho\r
367          968,    8, 13,     // Anna\r
368          970,    3, 25,     // Tenroku\r
369          973,   12, 20,     // Ten-en\r
370          976,    7, 13,     // Jogen\r
371          978,   11, 29,     // Tengen\r
372          983,    4, 15,     // Eikan\r
373          985,    4, 27,     // Kanna\r
374          987,    4,  5,     // Ei-en\r
375          989,    8,  8,     // Eiso\r
376          990,   11,  7,     // Shoryaku\r
377          995,    2, 22,     // Chotoku\r
378          999,    1, 13,     // Choho\r
379         1004,    7, 20,     // Kanko\r
380         1012,   12, 25,     // Chowa\r
381         1017,    4, 23,     // Kannin\r
382         1021,    2,  2,     // Jian\r
383         1024,    7, 13,     // Manju\r
384         1028,    7, 25,     // Chogen\r
385         1037,    4, 21,     // Choryaku\r
386         1040,   11, 10,     // Chokyu\r
387         1044,   11, 24,     // Kantoku\r
388         1046,    4, 14,     // Eisho\r
389         1053,    1, 11,     // Tengi\r
390         1058,    8, 29,     // Kohei\r
391         1065,    8,  2,     // Jiryaku\r
392         1069,    4, 13,     // Enkyu\r
393         1074,    8, 23,     // Shoho\r
394         1077,   11, 17,     // Shoryaku\r
395         1081,    2, 10,     // Eiho\r
396         1084,    2,  7,     // Otoku\r
397         1087,    4,  7,     // Kanji\r
398         1094,   12, 15,     // Kaho\r
399         1096,   12, 17,     // Eicho\r
400         1097,   11, 21,     // Shotoku\r
401         1099,    8, 28,     // Kowa\r
402         1104,    2, 10,     // Choji\r
403         1106,    4,  9,     // Kasho\r
404         1108,    8,  3,     // Tennin\r
405         1110,    7, 13,     // Ten-ei\r
406         1113,    7, 13,     // Eikyu\r
407         1118,    4,  3,     // Gen-ei\r
408         1120,    4, 10,     // Hoan\r
409         1124,    4,  3,     // Tenji\r
410         1126,    1, 22,     // Daiji\r
411         1131,    1, 29,     // Tensho\r
412         1132,    8, 11,     // Chosho\r
413         1135,    4, 27,     // Hoen\r
414         1141,    7, 10,     // Eiji\r
415         1142,    4, 28,     // Koji\r
416         1144,    2, 23,     // Tenyo\r
417         1145,    7, 22,     // Kyuan\r
418         1151,    1, 26,     // Ninpei\r
419         1154,   10, 28,     // Kyuju\r
420         1156,    4, 27,     // Hogen\r
421         1159,    4, 20,     // Heiji\r
422         1160,    1, 10,     // Eiryaku\r
423         1161,    9,  4,     // Oho\r
424         1163,    3, 29,     // Chokan\r
425         1165,    6,  5,     // Eiman\r
426         1166,    8, 27,     // Nin-an\r
427         1169,    4,  8,     // Kao\r
428         1171,    4, 21,     // Shoan\r
429         1175,    7, 28,     // Angen\r
430         1177,    8,  4,     // Jisho\r
431         1181,    7, 14,     // Yowa\r
432         1182,    5, 27,     // Juei\r
433         1184,    4, 16,     // Genryuku\r
434         1185,    8, 14,     // Bunji\r
435         1190,    4, 11,     // Kenkyu\r
436         1199,    4, 27,     // Shoji\r
437         1201,    2, 13,     // Kennin\r
438         1204,    2, 20,     // Genkyu\r
439         1206,    4, 27,     // Ken-ei\r
440         1207,   10, 25,     // Shogen\r
441         1211,    3,  9,     // Kenryaku\r
442         1213,   12,  6,     // Kenpo\r
443         1219,    4, 12,     // Shokyu\r
444         1222,    4, 13,     // Joo\r
445         1224,   11, 20,     // Gennin\r
446         1225,    4, 20,     // Karoku\r
447         1227,   12, 10,     // Antei\r
448         1229,    3,  5,     // Kanki\r
449         1232,    4,  2,     // Joei\r
450         1233,    4, 15,     // Tempuku\r
451         1234,   11,  5,     // Bunryaku\r
452         1235,    9, 19,     // Katei\r
453         1238,   11, 23,     // Ryakunin\r
454         1239,    2,  7,     // En-o\r
455         1240,    7, 16,     // Ninji\r
456         1243,    2, 26,     // Kangen\r
457         1247,    2, 28,     // Hoji\r
458         1249,    3, 18,     // Kencho\r
459         1256,   10,  5,     // Kogen\r
460         1257,    3, 14,     // Shoka\r
461         1259,    3, 26,     // Shogen\r
462         1260,    4, 13,     // Bun-o\r
463         1261,    2, 20,     // Kocho\r
464         1264,    2, 28,     // Bun-ei\r
465         1275,    4, 25,     // Kenji\r
466         1278,    2, 29,     // Koan\r
467         1288,    4, 28,     // Shoo\r
468         1293,    8, 55,     // Einin\r
469         1299,    4, 25,     // Shoan\r
470         1302,   11, 21,     // Kengen\r
471         1303,    8,  5,     // Kagen\r
472         1306,   12, 14,     // Tokuji\r
473         1308,   10,  9,     // Enkei\r
474         1311,    4, 28,     // Ocho\r
475         1312,    3, 20,     // Showa\r
476         1317,    2,  3,     // Bunpo\r
477         1319,    4, 28,     // Geno\r
478         1321,    2, 23,     // Genkyo\r
479         1324,   12,  9,     // Shochu\r
480         1326,    4, 26,     // Kareki\r
481         1329,    8, 29,     // Gentoku\r
482         1331,    8,  9,     // Genko\r
483         1334,    1, 29,     // Kemmu\r
484         1336,    2, 29,     // Engen\r
485         1340,    4, 28,     // Kokoku\r
486         1346,   12,  8,     // Shohei\r
487         1370,    7, 24,     // Kentoku\r
488         1372,    4,  1,     // Bunch\u0169\r
489         1375,    5, 27,     // Tenju\r
490         1379,    3, 22,     // Koryaku\r
491         1381,    2, 10,     // Kowa\r
492         1384,    4, 28,     // Gench\u0169\r
493         1384,    2, 27,     // Meitoku\r
494         1387,    8, 23,     // Kakei\r
495         1389,    2,  9,     // Koo\r
496         1390,    3, 26,     // Meitoku\r
497         1394,    7,  5,     // Oei\r
498         1428,    4, 27,     // Shocho\r
499         1429,    9,  5,     // Eikyo\r
500         1441,    2, 17,     // Kakitsu\r
501         1444,    2,  5,     // Bun-an\r
502         1449,    7, 28,     // Hotoku\r
503         1452,    7, 25,     // Kyotoku\r
504         1455,    7, 25,     // Kosho\r
505         1457,    9, 28,     // Choroku\r
506         1460,   12, 21,     // Kansho\r
507         1466,    2, 28,     // Bunsho\r
508         1467,    3,  3,     // Onin\r
509         1469,    4, 28,     // Bunmei\r
510         1487,    7, 29,     // Chokyo\r
511         1489,    8, 21,     // Entoku\r
512         1492,    7, 19,     // Meio\r
513         1501,    2, 29,     // Bunki\r
514         1504,    2, 30,     // Eisho\r
515         1521,    8, 23,     // Taiei\r
516         1528,    8, 20,     // Kyoroku\r
517         1532,    7, 29,     // Tenmon\r
518         1555,   10, 23,     // Koji\r
519         1558,    2, 28,     // Eiroku\r
520         1570,    4, 23,     // Genki\r
521         1573,    7, 28,     // Tensho\r
522         1592,   12,  8,     // Bunroku\r
523         1596,   10, 27,     // Keicho\r
524         1615,    7, 13,     // Genwa\r
525         1624,    2, 30,     // Kan-ei\r
526         1644,   12, 16,     // Shoho\r
527         1648,    2, 15,     // Keian\r
528         1652,    9, 18,     // Shoo\r
529         1655,    4, 13,     // Meiryaku\r
530         1658,    7, 23,     // Manji\r
531         1661,    4, 25,     // Kanbun\r
532         1673,    9, 21,     // Enpo\r
533         1681,    9, 29,     // Tenwa\r
534         1684,    2, 21,     // Jokyo\r
535         1688,    9, 30,     // Genroku\r
536         1704,    3, 13,     // Hoei\r
537         1711,    4, 25,     // Shotoku\r
538         1716,    6, 22,     // Kyoho\r
539         1736,    4, 28,     // Genbun\r
540         1741,    2, 27,     // Kanpo\r
541         1744,    2, 21,     // Enkyo\r
542         1748,    7, 12,     // Kan-en\r
543         1751,   10, 27,     // Horyaku\r
544         1764,    6,  2,     // Meiwa\r
545         1772,   11, 16,     // An-ei\r
546         1781,    4,  2,     // Tenmei\r
547         1789,    1, 25,     // Kansei\r
548         1801,    2,  5,     // Kyowa\r
549         1804,    2, 11,     // Bunka\r
550         1818,    4, 22,     // Bunsei\r
551         1830,   12, 10,     // Tenpo\r
552         1844,   12,  2,     // Koka\r
553         1848,    2, 28,     // Kaei\r
554         1854,   11, 27,     // Ansei\r
555         1860,    3, 18,     // Man-en\r
556         1861,    2, 19,     // Bunkyu\r
557         1864,    2, 20,     // Genji\r
558         1865,    4,  7,     // Keio\r
559         1868,    9,  8,     // Meiji\r
560         1912,    7, 30,     // Taisho\r
561         1926,   12, 25,     // Showa\r
562         1989,    1,  8,     // Heisei\r
563     };\r
564 \r
565     //-------------------------------------------------------------------------\r
566     // Public constants for some of the recent eras that folks might use...\r
567     //-------------------------------------------------------------------------\r
568 \r
569     // Constant for the current era.  This must be regularly updated.\r
570     /**\r
571      * @stable ICU 2.8\r
572      */\r
573     static public final int CURRENT_ERA = (ERAS.length / 3) - 1;\r
574     \r
575     /** \r
576      * Constant for the era starting on Sept. 8, 1868 AD.\r
577      * @stable  ICU 2.8 \r
578      */\r
579     static public final int MEIJI = CURRENT_ERA - 3;\r
580 \r
581     /** \r
582      * Constant for the era starting on July 30, 1912 AD. \r
583      * @stable ICU 2.8 \r
584      */\r
585     static public final int TAISHO = CURRENT_ERA - 2;\r
586     \r
587     /** \r
588      * Constant for the era starting on Dec. 25, 1926 AD. \r
589      * @stable ICU 2.8 \r
590      */\r
591     static public final int SHOWA = CURRENT_ERA - 1;\r
592 \r
593     /** \r
594      * Constant for the era starting on Jan. 7, 1989 AD. \r
595      * @stable ICU 2.8 \r
596      */\r
597     static public final int HEISEI = CURRENT_ERA;\r
598 \r
599     /**\r
600      * Override GregorianCalendar.  We should really handle YEAR_WOY and\r
601      * EXTENDED_YEAR here too to implement the 1..5000000 range, but it's\r
602      * not critical.\r
603      * @stable ICU 2.8\r
604      */\r
605     @SuppressWarnings("fallthrough")\r
606     protected int handleGetLimit(int field, int limitType) {\r
607         switch (field) {\r
608         case ERA:\r
609             if (limitType == MINIMUM || limitType == GREATEST_MINIMUM) {\r
610                 return 1;\r
611             }\r
612             return CURRENT_ERA;\r
613         case YEAR:\r
614         {\r
615             switch (limitType) {\r
616             case MINIMUM:\r
617             case GREATEST_MINIMUM:\r
618                 return 1;\r
619             case LEAST_MAXIMUM:\r
620                 return 1;\r
621             case MAXIMUM:\r
622                 return super.handleGetLimit(field, MAXIMUM) - ERAS[CURRENT_ERA*3];\r
623             }\r
624             //Fall through to the default if not handled above\r
625         }\r
626         default:\r
627             return super.handleGetLimit(field, limitType);\r
628         }\r
629     }\r
630 \r
631     /**\r
632      * {@inheritDoc}\r
633      * @stable ICU 3.8\r
634      */\r
635     public String getType() {\r
636         return "japanese";\r
637     }\r
638 \r
639     /**\r
640      * {@inheritDoc}\r
641      * @stable ICU 4.0\r
642      */\r
643     public int getActualMaximum(int field) {\r
644         if (field == YEAR) {\r
645             int era = get(Calendar.ERA);\r
646             if (era == CURRENT_ERA) {\r
647                 // TODO: Investigate what value should be used here - revisit after 4.0.\r
648                 return handleGetLimit(YEAR, MAXIMUM);\r
649             } else {\r
650                 int nextEraYear = ERAS[(era+1)*3];\r
651                 int nextEraMonth = ERAS[(era+1)*3 + 1];\r
652                 int nextEraDate = ERAS[(era+1)*3 + 2];\r
653 \r
654                 int maxYear = nextEraYear - ERAS[era*3] + 1; // 1-base\r
655                 if (nextEraMonth == 1 && nextEraDate == 1) {\r
656                     // Substract 1, because the next era starts at Jan 1\r
657                     maxYear--;\r
658                 }\r
659                 return maxYear;\r
660             }\r
661         }\r
662         return super.getActualMaximum(field);\r
663     }\r
664 }\r