/** * {@inheritDoc} */ @Override public void setFormat(int formatElementIndex, Format newFormat) { super.setFormat(formatElementIndex, newFormat); }
/** * {@inheritDoc} */ @Override public void setFormat(int formatElementIndex, Format newFormat) { super.setFormat(formatElementIndex, newFormat); }
/** * Sets the format to use for the format element with the given * format element index within the previously set pattern string. * The format element index is the zero-based number of the format * element counting from the start of the pattern string. * <p> * Since the order of format elements in a pattern string often * changes during localization, it is generally better to use the * {@link #setFormatByArgumentIndex setFormatByArgumentIndex} * method, which accesses format elements based on the argument * index they specify. * * @param formatElementIndex the index of a format element within the pattern * @param newFormat the format to use for the specified format element * @exception ArrayIndexOutOfBoundsException if formatElementIndex is equal to or * larger than the number of format elements in the pattern string * @stable ICU 3.0 */ public void setFormat(int formatElementIndex, Format newFormat) { messageFormat.setFormat(formatElementIndex, newFormat); savedPattern = null; }
/** * Sets the format to use for the format element with the given * format element index within the previously set pattern string. * The format element index is the zero-based number of the format * element counting from the start of the pattern string. * <p> * Since the order of format elements in a pattern string often * changes during localization, it is generally better to use the * {@link #setFormatByArgumentIndex setFormatByArgumentIndex} * method, which accesses format elements based on the argument * index they specify. * * @param formatElementIndex the index of a format element within the pattern * @param newFormat the format to use for the specified format element * @exception ArrayIndexOutOfBoundsException if formatElementIndex is equal to or * larger than the number of format elements in the pattern string * @stable ICU 3.0 */ public void setFormat(int formatElementIndex, Format newFormat) { messageFormat.setFormat(formatElementIndex, newFormat); savedPattern = null; }
static public String formatISO8601(Calendar cal) { MessageFormat format = new MessageFormat("{0,time}{1,number,+00;-00}:{2,number,00}"); DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); df.setTimeZone(cal.getTimeZone()); format.setFormat(0, df); long zoneOff = cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET) / 60000L; int zoneHrs = (int) (zoneOff / 60L); int zoneMins = (int) (zoneOff % 60L); if (zoneMins < 0) zoneMins = -zoneMins; return (format.format(new Object[] { cal.getTime(), new Integer(zoneHrs), new Integer(zoneMins) })); }
/** * Format the specified pattern with parameters * * @param prefix * The prefix to add * @param pattern * The format pattern * @param args * The parameters of pattern * @return a formatted string */ protected String format(final CharSequence prefix, final String pattern, final Object...args) { final MessageFormat mf = new MessageFormat(pattern); final StringBuffer buffer = new StringBuffer(prefix).append(" "); for (int i = 0, n = args.length; i < n; i++) { if (args[i] instanceof Throwable) { mf.setFormat(i, ThrowableFormat.getInstance()); } } return mf.format(args, buffer, new FieldPosition(0)).toString(); }
public VarFormatter(String format, Locale l) { logger.trace("new format: {}", format); this.format = format; locale = l; List<String> formats = new ArrayList<>(); // Convert the pattern to a MessageFormat which is compiled and be reused String pattern = findVariables(new StringBuilder(), format, 0, formats).toString(); mf = new MessageFormat(pattern, l); for(int i = 0; i < mf.getFormats().length; i++) { mf.setFormat(i, resolveFormat(formats.get(i))); } if (mapper.size() != 0) { mapper.keySet().stream().reduce((i,j) -> { if (i.getClass() != j.getClass()) { throw new IllegalArgumentException("Can't mix indexed with object resolution"); } else { return j; } }); } }
protected String formatWithTimeZone( String template, Object[] arguments, Locale locale, TimeZone timezone) { MessageFormat mf = new MessageFormat(" "); mf.setLocale(locale); mf.applyPattern(template); if (!timezone.equals(TimeZone.getDefault())) { Format[] formats = mf.getFormats(); for (int i = 0; i < formats.length; i++) { if (formats[i] instanceof DateFormat) { DateFormat temp = (DateFormat) formats[i]; temp.setTimeZone(timezone); mf.setFormat(i,temp); } } } return mf.format(arguments); }
protected String formatWithTimeZone( String template, Object[] arguments, Locale locale, TimeZone timezone) { MessageFormat mf = new MessageFormat(" "); mf.setLocale(locale); mf.applyPattern(template); if (!timezone.equals(TimeZone.getDefault())) { Format[] formats = mf.getFormats(); for (int i = 0; i < formats.length; i++) { if (formats[i] instanceof DateFormat) { DateFormat temp = (DateFormat) formats[i]; temp.setTimeZone(timezone); mf.setFormat(i,temp); } } } return mf.format(arguments); }
protected String formatWithTimeZone( String template, Object[] arguments, Locale locale, TimeZone timezone) { MessageFormat mf = new MessageFormat(" "); mf.setLocale(locale); mf.applyPattern(template); if (!timezone.equals(TimeZone.getDefault())) { Format[] formats = mf.getFormats(); for (int i = 0; i < formats.length; i++) { if (formats[i] instanceof DateFormat) { DateFormat temp = (DateFormat) formats[i]; temp.setTimeZone(timezone); mf.setFormat(i,temp); } } } return mf.format(arguments); }
protected String formatWithTimeZone( String template, Object[] arguments, Locale locale, TimeZone timezone) { MessageFormat mf = new MessageFormat(" "); mf.setLocale(locale); mf.applyPattern(template); if (!timezone.equals(TimeZone.getDefault())) { Format[] formats = mf.getFormats(); for (int i = 0; i < formats.length; i++) { if (formats[i] instanceof DateFormat) { DateFormat temp = (DateFormat) formats[i]; temp.setTimeZone(timezone); mf.setFormat(i,temp); } } } return mf.format(arguments); }
MessageFormat messageFormat = new MessageFormat( "Failed to resolve MavenResource: {0}. Configured remote {1}: {2}"); messageFormat.setFormat(1, pluralizer); String repos = properties.getRemoteRepositories().isEmpty() ? "none"