polish
This commit is contained in:
parent
2381452e9a
commit
db40e15a3e
|
|
@ -22,7 +22,7 @@ import java.lang.annotation.RetentionPolicy;
|
||||||
import java.lang.annotation.Target;
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A type that can be formatted as a String for display in a UI.
|
* A type that can be formatted as a String for display in a user interface.
|
||||||
* @author Keith Donald
|
* @author Keith Donald
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,7 @@ public interface FormatterRegistry {
|
||||||
* Get the Formatter for the type.
|
* Get the Formatter for the type.
|
||||||
* @return the Formatter, or <code>null</code> if none is registered
|
* @return the Formatter, or <code>null</code> if none is registered
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
Formatter getFormatter(TypeDescriptor type);
|
Formatter getFormatter(TypeDescriptor type);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,8 @@ public class GenericFormatterRegistry implements FormatterRegistry {
|
||||||
|
|
||||||
private Map<Class, AnnotationFormatterFactory> annotationFormatters = new HashMap<Class, AnnotationFormatterFactory>();
|
private Map<Class, AnnotationFormatterFactory> annotationFormatters = new HashMap<Class, AnnotationFormatterFactory>();
|
||||||
|
|
||||||
|
// implementing FormatterRegistry
|
||||||
|
|
||||||
public <T> void add(Formatter<T> formatter) {
|
public <T> void add(Formatter<T> formatter) {
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,13 +26,13 @@ import org.apache.commons.logging.LogFactory;
|
||||||
import org.springframework.ui.format.Formatter;
|
import org.springframework.ui.format.Formatter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A formatter for {@link Date} types.
|
* A formatter for {@link java.util.Date} types.
|
||||||
* Allows the configuration of an explicit date pattern and locale.
|
* Allows the configuration of an explicit date pattern and locale.
|
||||||
* @author Keith Donald
|
* @author Keith Donald
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
* @see SimpleDateFormat
|
* @see SimpleDateFormat
|
||||||
*/
|
*/
|
||||||
public class DateFormatter implements Formatter<Date> {
|
public final class DateFormatter implements Formatter<Date> {
|
||||||
|
|
||||||
private static Log logger = LogFactory.getLog(DateFormatter.class);
|
private static Log logger = LogFactory.getLog(DateFormatter.class);
|
||||||
|
|
||||||
|
|
@ -66,9 +66,9 @@ public class DateFormatter implements Formatter<Date> {
|
||||||
return getDateFormat(locale).parse(formatted);
|
return getDateFormat(locale).parse(formatted);
|
||||||
}
|
}
|
||||||
|
|
||||||
// subclassing hookings
|
// internal helpers
|
||||||
|
|
||||||
protected DateFormat getDateFormat(Locale locale) {
|
private DateFormat getDateFormat(Locale locale) {
|
||||||
DateFormat format = DateFormat.getDateInstance(DateFormat.SHORT, locale);
|
DateFormat format = DateFormat.getDateInstance(DateFormat.SHORT, locale);
|
||||||
format.setLenient(false);
|
format.setLenient(false);
|
||||||
if (format instanceof SimpleDateFormat) {
|
if (format instanceof SimpleDateFormat) {
|
||||||
|
|
@ -81,8 +81,6 @@ public class DateFormatter implements Formatter<Date> {
|
||||||
return format;
|
return format;
|
||||||
}
|
}
|
||||||
|
|
||||||
// internal helpers
|
|
||||||
|
|
||||||
private String determinePattern(String pattern) {
|
private String determinePattern(String pattern) {
|
||||||
return pattern != null ? pattern : DEFAULT_PATTERN;
|
return pattern != null ? pattern : DEFAULT_PATTERN;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ import org.springframework.ui.format.Formatter;
|
||||||
* @author Keith Donald
|
* @author Keith Donald
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
*/
|
*/
|
||||||
public class CurrencyFormatter implements Formatter<BigDecimal> {
|
public final class CurrencyFormatter implements Formatter<BigDecimal> {
|
||||||
|
|
||||||
private CurrencyNumberFormatFactory currencyFormatFactory = new CurrencyNumberFormatFactory();
|
private CurrencyNumberFormatFactory currencyFormatFactory = new CurrencyNumberFormatFactory();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ import org.springframework.ui.format.Formatter;
|
||||||
* @author Keith Donald
|
* @author Keith Donald
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
*/
|
*/
|
||||||
public class DecimalFormatter implements Formatter<BigDecimal> {
|
public final class DecimalFormatter implements Formatter<BigDecimal> {
|
||||||
|
|
||||||
private DefaultNumberFormatFactory formatFactory = new DefaultNumberFormatFactory();
|
private DefaultNumberFormatFactory formatFactory = new DefaultNumberFormatFactory();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ import org.springframework.ui.format.Formatter;
|
||||||
* @author Keith Donald
|
* @author Keith Donald
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
*/
|
*/
|
||||||
public class IntegerFormatter implements Formatter<Long> {
|
public final class IntegerFormatter implements Formatter<Long> {
|
||||||
|
|
||||||
private IntegerNumberFormatFactory formatFactory = new IntegerNumberFormatFactory();
|
private IntegerNumberFormatFactory formatFactory = new IntegerNumberFormatFactory();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ import org.springframework.ui.format.Formatter;
|
||||||
* @author Keith Donald
|
* @author Keith Donald
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
*/
|
*/
|
||||||
public class PercentFormatter implements Formatter<BigDecimal> {
|
public final class PercentFormatter implements Formatter<BigDecimal> {
|
||||||
|
|
||||||
private PercentNumberFormatFactory percentFormatFactory = new PercentNumberFormatFactory();
|
private PercentNumberFormatFactory percentFormatFactory = new PercentNumberFormatFactory();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue