Java Code Examples for java.util.Calendar#getDisplayNames()

The following examples show how to use java.util.Calendar#getDisplayNames() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FastDateParser.java    From logging-log4j2 with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 2
Source File: FastDateParser.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * 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);
}
 
Example 3
Source File: FastDateParser.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * 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);
}
 
Example 4
Source File: FastDateParser.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * 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);
}