Polish whitespace and formatting
This commit is contained in:
parent
409b533281
commit
a75b6ee5b6
|
|
@ -26,7 +26,7 @@ import java.lang.annotation.Target;
|
|||
* Supports formatting by style pattern, ISO date time pattern, or custom format pattern string.
|
||||
* Can be applied to <code>java.util.Date</code>, <code>java.util.Calendar</code>, <code>java.long.Long</code>, or Joda Time fields.
|
||||
* <p>
|
||||
* For style-based formatting, set the {@link #style()} attribute to be the style pattern code.
|
||||
* For style-based formatting, set the {@link #style()} attribute to be the style pattern code.
|
||||
* The first character of the code is the date style, and the second character is the time style.
|
||||
* Specify a character of 'S' for short style, 'M' for medium, 'L' for long, and 'F' for full.
|
||||
* A date or time may be omitted by specifying the style character '-'.
|
||||
|
|
@ -39,7 +39,7 @@ import java.lang.annotation.Target;
|
|||
* When the pattern attribute is specified, it takes precedence over both the style and ISO attribute.
|
||||
* When the iso attribute is specified, if takes precedence over the style attribute.
|
||||
* When no annotation attributes are specified, the default format applied is style-based with a style code of 'SS' (short date, short time).
|
||||
*
|
||||
*
|
||||
* @author Keith Donald
|
||||
* @author Juergen Hoeller
|
||||
* @since 3.0
|
||||
|
|
@ -76,8 +76,8 @@ public @interface DateTimeFormat {
|
|||
* Common ISO date time format patterns.
|
||||
*/
|
||||
public enum ISO {
|
||||
|
||||
/**
|
||||
|
||||
/**
|
||||
* The most common ISO Date Format <code>yyyy-MM-dd</code> e.g. 2000-10-31.
|
||||
*/
|
||||
DATE,
|
||||
|
|
@ -92,7 +92,7 @@ public @interface DateTimeFormat {
|
|||
* The default if no annotation value is specified.
|
||||
*/
|
||||
DATE_TIME,
|
||||
|
||||
|
||||
/**
|
||||
* Indicates that no ISO-based format pattern should be applied.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -52,17 +52,17 @@ public class JodaDateTimeFormatAnnotationFormatterFactory
|
|||
private final Set<Class<?>> fieldTypes;
|
||||
|
||||
private StringValueResolver embeddedValueResolver;
|
||||
|
||||
|
||||
|
||||
public JodaDateTimeFormatAnnotationFormatterFactory() {
|
||||
this.fieldTypes = createFieldTypes();
|
||||
}
|
||||
|
||||
|
||||
public final Set<Class<?>> getFieldTypes() {
|
||||
return this.fieldTypes;
|
||||
}
|
||||
|
||||
|
||||
public void setEmbeddedValueResolver(StringValueResolver resolver) {
|
||||
this.embeddedValueResolver = resolver;
|
||||
}
|
||||
|
|
@ -71,9 +71,8 @@ public class JodaDateTimeFormatAnnotationFormatterFactory
|
|||
return (this.embeddedValueResolver != null ? this.embeddedValueResolver.resolveStringValue(value) : value);
|
||||
}
|
||||
|
||||
|
||||
public Printer<?> getPrinter(DateTimeFormat annotation, Class<?> fieldType) {
|
||||
DateTimeFormatter formatter = configureDateTimeFormatterFrom(annotation);
|
||||
DateTimeFormatter formatter = configureDateTimeFormatterFrom(annotation);
|
||||
if (ReadableInstant.class.isAssignableFrom(fieldType)) {
|
||||
return new ReadableInstantPrinter(formatter);
|
||||
}
|
||||
|
|
@ -82,21 +81,21 @@ public class JodaDateTimeFormatAnnotationFormatterFactory
|
|||
}
|
||||
else if (Calendar.class.isAssignableFrom(fieldType)) {
|
||||
// assumes Calendar->ReadableInstant converter is registered
|
||||
return new ReadableInstantPrinter(formatter);
|
||||
return new ReadableInstantPrinter(formatter);
|
||||
}
|
||||
else {
|
||||
// assumes Date->Long converter is registered
|
||||
return new MillisecondInstantPrinter(formatter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Parser<DateTime> getParser(DateTimeFormat annotation, Class<?> fieldType) {
|
||||
return new DateTimeParser(configureDateTimeFormatterFrom(annotation));
|
||||
return new DateTimeParser(configureDateTimeFormatterFrom(annotation));
|
||||
}
|
||||
|
||||
// internal helpers
|
||||
|
||||
/**
|
||||
/**
|
||||
* Create the set of field types that may be annotated with @DateTimeFormat.
|
||||
* Note: the 3 ReadablePartial concrete types are registered explicitly since addFormatterForFieldType rules exist for each of these types
|
||||
* (if we did not do this, the default byType rules for LocalDate, LocalTime, and LocalDateTime would take precedence over the annotation rule, which is not what we want)
|
||||
|
|
@ -111,9 +110,9 @@ public class JodaDateTimeFormatAnnotationFormatterFactory
|
|||
rawFieldTypes.add(Date.class);
|
||||
rawFieldTypes.add(Calendar.class);
|
||||
rawFieldTypes.add(Long.class);
|
||||
return Collections.unmodifiableSet(rawFieldTypes);
|
||||
return Collections.unmodifiableSet(rawFieldTypes);
|
||||
}
|
||||
|
||||
|
||||
private DateTimeFormatter configureDateTimeFormatterFrom(DateTimeFormat annotation) {
|
||||
if (StringUtils.hasLength(annotation.pattern())) {
|
||||
return forPattern(resolveEmbeddedValue(annotation.pattern()));
|
||||
|
|
@ -143,7 +142,7 @@ public class JodaDateTimeFormatAnnotationFormatterFactory
|
|||
}
|
||||
else {
|
||||
return org.joda.time.format.ISODateTimeFormat.dateTime();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -59,7 +59,7 @@ final class JodaTimeConverters {
|
|||
|
||||
/**
|
||||
* Used when binding a parsed DateTime to a LocalDate field.
|
||||
* @see DateTimeParser
|
||||
* @see DateTimeParser
|
||||
**/
|
||||
private static class DateTimeToLocalDateConverter implements Converter<DateTime, LocalDate> {
|
||||
public LocalDate convert(DateTime source) {
|
||||
|
|
@ -67,9 +67,9 @@ final class JodaTimeConverters {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Used when binding a parsed DateTime to a LocalTime field.
|
||||
* @see DateTimeParser
|
||||
/**
|
||||
* Used when binding a parsed DateTime to a LocalTime field.
|
||||
* @see DateTimeParser
|
||||
*/
|
||||
private static class DateTimeToLocalTimeConverter implements Converter<DateTime, LocalTime> {
|
||||
public LocalTime convert(DateTime source) {
|
||||
|
|
@ -77,9 +77,9 @@ final class JodaTimeConverters {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Used when binding a parsed DateTime to a LocalDateTime field.
|
||||
* @see DateTimeParser
|
||||
/**
|
||||
* Used when binding a parsed DateTime to a LocalDateTime field.
|
||||
* @see DateTimeParser
|
||||
*/
|
||||
private static class DateTimeToLocalDateTimeConverter implements Converter<DateTime, LocalDateTime> {
|
||||
public LocalDateTime convert(DateTime source) {
|
||||
|
|
@ -87,9 +87,9 @@ final class JodaTimeConverters {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Used when binding a parsed DateTime to a DateMidnight field.
|
||||
* @see DateTimeParser
|
||||
/**
|
||||
* Used when binding a parsed DateTime to a DateMidnight field.
|
||||
* @see DateTimeParser
|
||||
*/
|
||||
private static class DateTimeToDateMidnightConverter implements Converter<DateTime, DateMidnight> {
|
||||
public DateMidnight convert(DateTime source) {
|
||||
|
|
@ -97,9 +97,9 @@ final class JodaTimeConverters {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Used when binding a parsed DateTime to an Instant field.
|
||||
* @see DateTimeParser
|
||||
/**
|
||||
* Used when binding a parsed DateTime to an Instant field.
|
||||
* @see DateTimeParser
|
||||
*/
|
||||
private static class DateTimeToInstantConverter implements Converter<DateTime, Instant> {
|
||||
public Instant convert(DateTime source) {
|
||||
|
|
@ -107,19 +107,19 @@ final class JodaTimeConverters {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Used when binding a parsed DateTime to a MutableDateTime field.
|
||||
* @see DateTimeParser
|
||||
/**
|
||||
* Used when binding a parsed DateTime to a MutableDateTime field.
|
||||
* @see DateTimeParser
|
||||
*/
|
||||
private static class DateTimeToMutableDateTimeConverter implements Converter<DateTime, MutableDateTime> {
|
||||
public MutableDateTime convert(DateTime source) {
|
||||
return source.toMutableDateTime();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Used when binding a parsed DateTime to a java.util.Date field.
|
||||
* @see DateTimeParser
|
||||
|
||||
/**
|
||||
* Used when binding a parsed DateTime to a java.util.Date field.
|
||||
* @see DateTimeParser
|
||||
*/
|
||||
private static class DateTimeToDateConverter implements Converter<DateTime, Date> {
|
||||
public Date convert(DateTime source) {
|
||||
|
|
@ -127,9 +127,9 @@ final class JodaTimeConverters {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Used when binding a parsed DateTime to a java.util.Calendar field.
|
||||
* @see DateTimeParser
|
||||
/**
|
||||
* Used when binding a parsed DateTime to a java.util.Calendar field.
|
||||
* @see DateTimeParser
|
||||
*/
|
||||
private static class DateTimeToCalendarConverter implements Converter<DateTime, Calendar> {
|
||||
public Calendar convert(DateTime source) {
|
||||
|
|
@ -137,9 +137,9 @@ final class JodaTimeConverters {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Used when binding a parsed DateTime to a java.lang.Long field.
|
||||
* @see DateTimeParser
|
||||
/**
|
||||
* Used when binding a parsed DateTime to a java.lang.Long field.
|
||||
* @see DateTimeParser
|
||||
*/
|
||||
private static class DateTimeToLongConverter implements Converter<DateTime, Long> {
|
||||
public Long convert(DateTime source) {
|
||||
|
|
@ -162,7 +162,7 @@ final class JodaTimeConverters {
|
|||
* Used when printing a java.util.Calendar field with a ReadableInstantPrinter.
|
||||
* @see MillisecondInstantPrinter
|
||||
* @see JodaDateTimeFormatAnnotationFormatterFactory
|
||||
*/
|
||||
*/
|
||||
private static class CalendarToReadableInstantConverter implements Converter<Calendar, ReadableInstant> {
|
||||
public ReadableInstant convert(Calendar source) {
|
||||
return new DateTime(source);
|
||||
|
|
|
|||
Loading…
Reference in New Issue