/** * Creates a DateFormat with the given time and/or date style in the given * locale. * @param timeStyle a value from 0 to 3 indicating the time format, * ignored if flags is 2 * @param dateStyle a value from 0 to 3 indicating the time format, * ignored if flags is 1 * @param flags either 1 for a time format, 2 for a date format, * or 3 for a date/time format * @param loc the locale for the format */ private static DateFormat get(int timeStyle, int dateStyle, int flags, Locale loc) { if ((flags & 1) != 0) { if (timeStyle < 0 || timeStyle > 3) { throw new IllegalArgumentException("Illegal time style " + timeStyle); } } else { timeStyle = -1; } if ((flags & 2) != 0) { if (dateStyle < 0 || dateStyle > 3) { throw new IllegalArgumentException("Illegal date style " + dateStyle); } } else { dateStyle = -1; } LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(DateFormatProvider.class, loc); DateFormat dateFormat = get(adapter, timeStyle, dateStyle, loc); if (dateFormat == null) { dateFormat = get(LocaleProviderAdapter.forJRE(), timeStyle, dateStyle, loc); } return dateFormat; }
@Override public DateFormatProvider getDateFormatProvider() { if (dateFormatProvider == null) { DateFormatProvider provider = AccessController.doPrivileged( (PrivilegedAction<DateFormatProvider>) () -> new DateFormatProviderImpl( getAdapterType(), getLanguageTagSet("FormatData"))); synchronized (this) { if (dateFormatProvider == null) { dateFormatProvider = provider; } } } return dateFormatProvider; }
public DateFormat getObject(DateFormatProvider dateFormatProvider, Locale locale, String key, Object... params) { assert params.length == 3; int timeStyle = (Integer)params[0]; int dateStyle = (Integer)params[1]; int flags = (Integer)params[2]; switch (flags) { case 1: return dateFormatProvider.getTimeInstance(timeStyle, locale); case 2: return dateFormatProvider.getDateInstance(dateStyle, locale); case 3: return dateFormatProvider.getDateTimeInstance(dateStyle, timeStyle, locale); default: assert false : "should not happen"; } return null; }
private static DateFormat get(LocaleProviderAdapter adapter, int timeStyle, int dateStyle, Locale loc) { DateFormatProvider provider = adapter.getDateFormatProvider(); DateFormat dateFormat; if (timeStyle == -1) { dateFormat = provider.getDateInstance(dateStyle, loc); } else { if (dateStyle == -1) { dateFormat = provider.getTimeInstance(timeStyle, loc); } else { dateFormat = provider.getDateTimeInstance(dateStyle, timeStyle, loc); } } return dateFormat; }
@Override public DateFormatProvider getDateFormatProvider() { if (dateFormatProvider == null) { DateFormatProvider provider = new DateFormatProviderImpl(getAdapterType(), getLanguageTagSet("FormatData")); synchronized (this) { if (dateFormatProvider == null) { dateFormatProvider = provider; } } } return dateFormatProvider; }
private static String getDefaultPattern(Locale loc) { LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(DateFormatProvider.class, loc); LocaleResources lr = adapter.getLocaleResources(loc); if (lr == null) { lr = LocaleProviderAdapter.forJRE().getLocaleResources(loc); } return lr.getDateTimePattern(DateFormat.SHORT, DateFormat.SHORT, null); }
public TestThread() { int which = count++ % 3; switch (which) { case 0 : cls = LocaleNameProvider.class; break; case 1 : cls = TimeZoneNameProvider.class; break; case 2 : cls = DateFormatProvider.class; break; default : throw new AssertionError("Should not reach here"); } }