下面列出了java.util.Calendar#getDisplayNames ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Get the short and long values displayed for a field
* @param cal The calendar to obtain the short and long values
* @param locale The locale of display names
* @param field The field of interest
* @param regex The regular expression to build
* @return The map of string display names to field values
*/
private static Map<String, Integer> appendDisplayNames(final Calendar cal, final Locale locale, final int field, final StringBuilder regex) {
final Map<String, Integer> values = new HashMap<>();
final Map<String, Integer> displayNames = cal.getDisplayNames(field, Calendar.ALL_STYLES, locale);
final TreeSet<String> sorted = new TreeSet<>(LONGER_FIRST_LOWERCASE);
for (final Map.Entry<String, Integer> displayName : displayNames.entrySet()) {
final String key = displayName.getKey().toLowerCase(locale);
if (sorted.add(key)) {
values.put(key, displayName.getValue());
}
}
for (final String symbol : sorted) {
simpleQuote(regex, symbol).append('|');
}
return values;
}
/**
* Get the short and long values displayed for a field
* @param field The field of interest
* @param definingCalendar The calendar to obtain the short and long values
* @param locale The locale of display names
* @return A Map of the field key / value pairs
*/
private static Map<String, Integer> getDisplayNames(int field, Calendar definingCalendar, Locale locale) {
return definingCalendar.getDisplayNames(field, Calendar.ALL_STYLES, locale);
}
/**
* Get the short and long values displayed for a field
* @param field The field of interest
* @param definingCalendar The calendar to obtain the short and long values
* @param locale The locale of display names
* @return A Map of the field key / value pairs
*/
private static Map<String, Integer> getDisplayNames(final int field, final Calendar definingCalendar, final Locale locale) {
return definingCalendar.getDisplayNames(field, Calendar.ALL_STYLES, locale);
}
/**
* Get the short and long values displayed for a field
* @param field The field of interest
* @param definingCalendar The calendar to obtain the short and long values
* @param locale The locale of display names
* @return A Map of the field key / value pairs
*/
private static Map<String, Integer> getDisplayNames(int field, Calendar definingCalendar, Locale locale) {
return definingCalendar.getDisplayNames(field, Calendar.ALL_STYLES, locale);
}