- java.lang.Object
-
- java.util.spi.LocaleServiceProvider
-
- java.util.spi.CalendarNameProvider
-
public abstract class CalendarNameProvider extends LocaleServiceProvider
An abstract class for service providers that provide localized string representations (display names) ofCalendar
field values.Calendar types are used to specify calendar systems for which the
getDisplayName
andgetDisplayNames
methods provide calendar field value names. SeeCalendar.getCalendarType()
for details.Calendar Fields
Calendar fields are specified with the constants defined in
Calendar
. The following are calendar-common fields and their values to be supported for each calendar system.Field Value Description Calendar.MONTH
Calendar.JANUARY
toCalendar.UNDECIMBER
Month numbering is 0-based (e.g., 0 - January, ..., 11 - December). Some calendar systems have 13 months. Month names need to be supported in both the formatting and stand-alone forms if required by the supported locales. If there's no distinction in the two forms, the same names should be returned in both of the forms. Calendar.DAY_OF_WEEK
Calendar.SUNDAY
toCalendar.SATURDAY
Day-of-week numbering is 1-based starting from Sunday (i.e., 1 - Sunday, ..., 7 - Saturday). Calendar.AM_PM
Calendar.AM
toCalendar.PM
0 - AM, 1 - PM The following are calendar-specific fields and their values to be supported.
Calendar Type Field Value Description "gregory"
Calendar.ERA
0 GregorianCalendar.BC
(BCE)1 GregorianCalendar.AD
(CE)"buddhist"
Calendar.ERA
0 BC (BCE) 1 B.E. (Buddhist Era) "japanese"
Calendar.ERA
0 Seireki (Before Meiji) 1 Meiji 2 Taisho 3 Showa 4 Heisei Calendar.YEAR
1 the first year in each era. It should be returned when a long style ( Calendar.LONG_FORMAT
orCalendar.LONG_STANDALONE
) is specified. See also the Year representation inSimpleDateFormat
."roc"
Calendar.ERA
0 Before R.O.C. 1 R.O.C. "islamic"
Calendar.ERA
0 Before AH 1 Anno Hijrah (AH) Calendar field value names for
"gregory"
must be consistent with the date-time symbols provided byDateFormatSymbolsProvider
.Time zone names are supported by
TimeZoneNameProvider
.- Since:
- 1.8
- See Also:
CalendarDataProvider
,Locale.getUnicodeLocaleType(String)
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
CalendarNameProvider()
Sole constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description abstract String
getDisplayName(String calendarType, int field, int value, int style, Locale locale)
Returns the string representation (display name) of the calendarfield value
in the givenstyle
andlocale
.abstract Map<String,Integer>
getDisplayNames(String calendarType, int field, int style, Locale locale)
Returns aMap
containing all string representations (display names) of theCalendar
field
in the givenstyle
andlocale
and their corresponding field values.-
Methods declared in class java.util.spi.LocaleServiceProvider
getAvailableLocales, isSupportedLocale
-
-
-
-
Method Detail
-
getDisplayName
public abstract String getDisplayName(String calendarType, int field, int value, int style, Locale locale)
Returns the string representation (display name) of the calendarfield value
in the givenstyle
andlocale
. If no string representation is applicable,null
is returned.field
is aCalendar
field index, such asCalendar.MONTH
. The time zone fields,Calendar.ZONE_OFFSET
andCalendar.DST_OFFSET
, are not supported by this method.null
must be returned if any time zone fields are specified.value
is the numeric representation of thefield
value. For example, iffield
isCalendar.DAY_OF_WEEK
, the valid values areCalendar.SUNDAY
toCalendar.SATURDAY
(inclusive).style
gives the style of the string representation. It is one ofCalendar.SHORT_FORMAT
(SHORT
),Calendar.SHORT_STANDALONE
,Calendar.LONG_FORMAT
(LONG
),Calendar.LONG_STANDALONE
,Calendar.NARROW_FORMAT
, orCalendar.NARROW_STANDALONE
.For example, the following call will return
"Sunday"
.getDisplayName("gregory", Calendar.DAY_OF_WEEK, Calendar.SUNDAY, Calendar.LONG_STANDALONE, Locale.ENGLISH);
- Parameters:
calendarType
- the calendar type. (Any calendar type given bylocale
is ignored.)field
- theCalendar
field index, such asCalendar.DAY_OF_WEEK
value
- the value of theCalendar field
, such asCalendar.MONDAY
style
- the string representation style: one ofCalendar.SHORT_FORMAT
(SHORT
),Calendar.SHORT_STANDALONE
,Calendar.LONG_FORMAT
(LONG
),Calendar.LONG_STANDALONE
,Calendar.NARROW_FORMAT
, orCalendar.NARROW_STANDALONE
locale
- the desired locale- Returns:
- the string representation of the
field value
, ornull
if the string representation is not applicable or the given calendar type is unknown - Throws:
IllegalArgumentException
- iffield
orstyle
is invalidNullPointerException
- iflocale
isnull
- See Also:
TimeZoneNameProvider
,Calendar.get(int)
,Calendar.getDisplayName(int, int, Locale)
-
getDisplayNames
public abstract Map<String,Integer> getDisplayNames(String calendarType, int field, int style, Locale locale)
Returns aMap
containing all string representations (display names) of theCalendar
field
in the givenstyle
andlocale
and their corresponding field values.field
is aCalendar
field index, such asCalendar.MONTH
. The time zone fields,Calendar.ZONE_OFFSET
andCalendar.DST_OFFSET
, are not supported by this method.null
must be returned if any time zone fields are specified.style
gives the style of the string representation. It must be one ofCalendar.ALL_STYLES
,Calendar.SHORT_FORMAT
(SHORT
),Calendar.SHORT_STANDALONE
,Calendar.LONG_FORMAT
(LONG
),Calendar.LONG_STANDALONE
,Calendar.NARROW_FORMAT
, orCalendar.NARROW_STANDALONE
. Note that narrow names may not be unique due to use of single characters, such as "S" for Sunday and Saturday, and that no narrow names are included in that case.For example, the following call will return a
Map
containing"January"
toCalendar.JANUARY
,"Jan"
toCalendar.JANUARY
,"February"
toCalendar.FEBRUARY
,"Feb"
toCalendar.FEBRUARY
, and so on.getDisplayNames("gregory", Calendar.MONTH, Calendar.ALL_STYLES, Locale.ENGLISH);
- Parameters:
calendarType
- the calendar type. (Any calendar type given bylocale
is ignored.)field
- the calendar field for which the display names are returnedstyle
- the style applied to the display names; one ofCalendar.ALL_STYLES
,Calendar.SHORT_FORMAT
(SHORT
),Calendar.SHORT_STANDALONE
,Calendar.LONG_FORMAT
(LONG
),Calendar.LONG_STANDALONE
,Calendar.NARROW_FORMAT
, orCalendar.NARROW_STANDALONE
locale
- the desired locale- Returns:
- a
Map
containing all display names offield
instyle
andlocale
and theirfield
values, ornull
if no display names are defined forfield
- Throws:
NullPointerException
- iflocale
isnull
- See Also:
Calendar.getDisplayNames(int, int, Locale)
-
-