From 5fdc29f1524836d914a8a4f9d4cd5a6148c8ff25 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Mon, 7 Dec 2009 20:33:33 +0000 Subject: [PATCH] polishing --- .../format/annotation/DateTimeFormat.java | 2 -- .../format/datetime/joda/DateTimeParser.java | 6 ++++- .../format/datetime/joda/JodaTimeContext.java | 24 ++++++++++------- .../datetime/joda/JodaTimeContextHolder.java | 26 +++++++++++-------- .../datetime/joda/JodaTimeConverters.java | 18 ++++++------- .../joda/MillisecondInstantPrinter.java | 6 ++++- .../datetime/joda/ReadableInstantPrinter.java | 7 +++-- .../datetime/joda/ReadablePartialPrinter.java | 8 ++++-- 8 files changed, 58 insertions(+), 39 deletions(-) diff --git a/org.springframework.context/src/main/java/org/springframework/format/annotation/DateTimeFormat.java b/org.springframework.context/src/main/java/org/springframework/format/annotation/DateTimeFormat.java index e95f4d46c06..f68382fde82 100644 --- a/org.springframework.context/src/main/java/org/springframework/format/annotation/DateTimeFormat.java +++ b/org.springframework.context/src/main/java/org/springframework/format/annotation/DateTimeFormat.java @@ -73,8 +73,6 @@ public @interface DateTimeFormat { /** * Common ISO date time format patterns. - * @author Keith Donald - * @since 3.0 */ public enum ISO { diff --git a/org.springframework.context/src/main/java/org/springframework/format/datetime/joda/DateTimeParser.java b/org.springframework.context/src/main/java/org/springframework/format/datetime/joda/DateTimeParser.java index 671084e7991..48f8d46c429 100644 --- a/org.springframework.context/src/main/java/org/springframework/format/datetime/joda/DateTimeParser.java +++ b/org.springframework.context/src/main/java/org/springframework/format/datetime/joda/DateTimeParser.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.format.datetime.joda; import java.text.ParseException; @@ -20,10 +21,12 @@ import java.util.Locale; import org.joda.time.DateTime; import org.joda.time.format.DateTimeFormatter; + import org.springframework.format.Parser; /** * Parses Joda Time {@link DateTime} instances using a {@link DateTimeFormatter}. + * * @author Keith Donald * @since 3.0 */ @@ -32,7 +35,7 @@ public final class DateTimeParser implements Parser { private final DateTimeFormatter formatter; /** - * Creates a new DateTimeParser. + * Create a new DateTimeParser. * @param formatter the Joda DateTimeFormatter instance */ public DateTimeParser(DateTimeFormatter formatter) { @@ -42,4 +45,5 @@ public final class DateTimeParser implements Parser { public DateTime parse(String text, Locale locale) throws ParseException { return JodaTimeContextHolder.getFormatter(this.formatter, locale).parseDateTime(text); } + } diff --git a/org.springframework.context/src/main/java/org/springframework/format/datetime/joda/JodaTimeContext.java b/org.springframework.context/src/main/java/org/springframework/format/datetime/joda/JodaTimeContext.java index ab3a2ec6f9e..2e8cf234351 100644 --- a/org.springframework.context/src/main/java/org/springframework/format/datetime/joda/JodaTimeContext.java +++ b/org.springframework.context/src/main/java/org/springframework/format/datetime/joda/JodaTimeContext.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.format.datetime.joda; import org.joda.time.Chronology; @@ -22,6 +23,7 @@ import org.joda.time.format.DateTimeFormatter; /** * A context that holds user-specific Joda Time settings such as the user's Chronology (calendar system) and time zone. * A null property value indicate the user has not specified a setting. + * * @author Keith Donald * @since 3.0 * @see JodaTimeContextHolder @@ -32,19 +34,27 @@ public class JodaTimeContext { private DateTimeZone timeZone; + + /** + * Set the user's chronology. + */ + public void setChronology(Chronology chronology) { + this.chronology = chronology; + } + /** * The user's chronology (calendar system). * Null if not specified. */ public Chronology getChronology() { - return chronology; + return this.chronology; } /** - * Sets the user's chronology. + * Set the user's timezone. */ - public void setChronology(Chronology chronology) { - this.chronology = chronology; + public void setTimeZone(DateTimeZone timeZone) { + this.timeZone = timeZone; } /** @@ -55,12 +65,6 @@ public class JodaTimeContext { return timeZone; } - /** - * Sets the user's timezone. - */ - public void setTimeZone(DateTimeZone timeZone) { - this.timeZone = timeZone; - } /** * Gets the Formatter with the this context's settings applied to the base formatter. diff --git a/org.springframework.context/src/main/java/org/springframework/format/datetime/joda/JodaTimeContextHolder.java b/org.springframework.context/src/main/java/org/springframework/format/datetime/joda/JodaTimeContextHolder.java index e6d2fd8cf24..cb13e720771 100644 --- a/org.springframework.context/src/main/java/org/springframework/format/datetime/joda/JodaTimeContextHolder.java +++ b/org.springframework.context/src/main/java/org/springframework/format/datetime/joda/JodaTimeContextHolder.java @@ -13,30 +13,26 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.format.datetime.joda; import java.util.Locale; import org.joda.time.format.DateTimeFormatter; + import org.springframework.core.NamedInheritableThreadLocal; /** * A holder for a thread-local user {@link JodaTimeContext}. + * * @since 3.0 * @author Keith Donald */ public final class JodaTimeContextHolder { - private static final ThreadLocal jodaTimeContextHolder = new NamedInheritableThreadLocal( - "Joda Time Context"); + private static final ThreadLocal jodaTimeContextHolder = + new NamedInheritableThreadLocal("JodaTime Context"); - /** - * Return the JodaTimeContext associated with the current thread, if any. - * @return the current JodaTimeContext, or null if none - */ - public static JodaTimeContext getJodaTimeContext() { - return jodaTimeContextHolder.get(); - } /** * Associate the given JodaTimeContext with the current thread. @@ -46,7 +42,15 @@ public final class JodaTimeContextHolder { public static void setJodaTimeContext(JodaTimeContext context) { jodaTimeContextHolder.set(context); } - + + /** + * Return the JodaTimeContext associated with the current thread, if any. + * @return the current JodaTimeContext, or null if none + */ + public static JodaTimeContext getJodaTimeContext() { + return jodaTimeContextHolder.get(); + } + /** * Gets the Formatter with the user-specific settings applied to thefrom the base formatter. * @param formatter the base formatter that establishes default formatting rules, generally user independent @@ -58,7 +62,7 @@ public final class JodaTimeContextHolder { formatter = formatter.withLocale(locale); } JodaTimeContext context = getJodaTimeContext(); - return context != null ? context.getFormatter(formatter) : formatter; + return (context != null ? context.getFormatter(formatter) : formatter); } } diff --git a/org.springframework.context/src/main/java/org/springframework/format/datetime/joda/JodaTimeConverters.java b/org.springframework.context/src/main/java/org/springframework/format/datetime/joda/JodaTimeConverters.java index da7c9d0cacd..b8840c7cdad 100644 --- a/org.springframework.context/src/main/java/org/springframework/format/datetime/joda/JodaTimeConverters.java +++ b/org.springframework.context/src/main/java/org/springframework/format/datetime/joda/JodaTimeConverters.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.format.datetime.joda; import java.util.Calendar; @@ -24,22 +25,20 @@ import org.joda.time.LocalDate; import org.joda.time.LocalDateTime; import org.joda.time.LocalTime; import org.joda.time.ReadableInstant; + import org.springframework.core.convert.converter.Converter; import org.springframework.core.convert.converter.ConverterRegistry; /** * Installs lower-level type converters required to integrate Joda Time support into Spring's field formatting system. + * * @author Keith Donald * @since 3.0 */ final class JodaTimeConverters { - private JodaTimeConverters() { - - } - /** - * Installs the converters into the converter registry. + * Install the converters into the converter registry. * @param registry the converter registry */ public static void registerConverters(ConverterRegistry registry) { @@ -54,9 +53,8 @@ final class JodaTimeConverters { registry.addConverter(new CalendarToReadableInstantConverter()); } - // internal helpers - - /** + + /** * Used when binding a parsed DateTime to a LocalDate field. * @see DateTimeParser **/ @@ -129,7 +127,7 @@ final class JodaTimeConverters { /** * Used when printing a java.util.Date field with a MillisecondInstantPrinter. * @see MillisecondInstantPrinter - * @see DateTimeFormatAnnotationFormatterFactory + * @see JodaDateTimeFormatAnnotationFormatterFactory */ private static class DateToLongConverter implements Converter { public Long convert(Date source) { @@ -140,7 +138,7 @@ final class JodaTimeConverters { /** * Used when printing a java.util.Calendar field with a ReadableInstantPrinter. * @see MillisecondInstantPrinter - * @see DateTimeFormatAnnotationFormatterFactory + * @see JodaDateTimeFormatAnnotationFormatterFactory */ private static class CalendarToReadableInstantConverter implements Converter { public ReadableInstant convert(Calendar source) { diff --git a/org.springframework.context/src/main/java/org/springframework/format/datetime/joda/MillisecondInstantPrinter.java b/org.springframework.context/src/main/java/org/springframework/format/datetime/joda/MillisecondInstantPrinter.java index dbce3f320eb..d7b22e71f0d 100644 --- a/org.springframework.context/src/main/java/org/springframework/format/datetime/joda/MillisecondInstantPrinter.java +++ b/org.springframework.context/src/main/java/org/springframework/format/datetime/joda/MillisecondInstantPrinter.java @@ -13,15 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.format.datetime.joda; import java.util.Locale; import org.joda.time.format.DateTimeFormatter; + import org.springframework.format.Printer; /** * Prints Long instances using a {@link DateTimeFormatter}. + * * @author Keith Donald * @since 3.0 */ @@ -30,7 +33,7 @@ public final class MillisecondInstantPrinter implements Printer { private final DateTimeFormatter formatter; /** - * Creates a new ReadableInstantPrinter. + * Create a new ReadableInstantPrinter. * @param formatter the Joda DateTimeFormatter instance */ public MillisecondInstantPrinter(DateTimeFormatter formatter) { @@ -40,4 +43,5 @@ public final class MillisecondInstantPrinter implements Printer { public String print(Long instant, Locale locale) { return JodaTimeContextHolder.getFormatter(this.formatter, locale).print(instant); } + } diff --git a/org.springframework.context/src/main/java/org/springframework/format/datetime/joda/ReadableInstantPrinter.java b/org.springframework.context/src/main/java/org/springframework/format/datetime/joda/ReadableInstantPrinter.java index 7a7c541ef10..8cf404fcadd 100644 --- a/org.springframework.context/src/main/java/org/springframework/format/datetime/joda/ReadableInstantPrinter.java +++ b/org.springframework.context/src/main/java/org/springframework/format/datetime/joda/ReadableInstantPrinter.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.format.datetime.joda; import java.util.Locale; @@ -22,7 +23,8 @@ import org.joda.time.format.DateTimeFormatter; import org.springframework.format.Printer; /** - * Prints Joda Time {@link ReadableInstant} instances using a {@link DateTimeFormatter}. + * Prints JodaTime {@link ReadableInstant} instances using a {@link DateTimeFormatter}. + * * @author Keith Donald * @since 3.0 */ @@ -31,7 +33,7 @@ public final class ReadableInstantPrinter implements Printer { private final DateTimeFormatter formatter; /** - * Creates a new ReadableInstantPrinter. + * Create a new ReadableInstantPrinter. * @param formatter the Joda DateTimeFormatter instance */ public ReadableInstantPrinter(DateTimeFormatter formatter) { @@ -41,4 +43,5 @@ public final class ReadableInstantPrinter implements Printer { public String print(ReadableInstant instant, Locale locale) { return JodaTimeContextHolder.getFormatter(this.formatter, locale).print(instant); } + } diff --git a/org.springframework.context/src/main/java/org/springframework/format/datetime/joda/ReadablePartialPrinter.java b/org.springframework.context/src/main/java/org/springframework/format/datetime/joda/ReadablePartialPrinter.java index 152b255ef78..9ad97c20581 100644 --- a/org.springframework.context/src/main/java/org/springframework/format/datetime/joda/ReadablePartialPrinter.java +++ b/org.springframework.context/src/main/java/org/springframework/format/datetime/joda/ReadablePartialPrinter.java @@ -13,16 +13,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.format.datetime.joda; import java.util.Locale; import org.joda.time.ReadablePartial; import org.joda.time.format.DateTimeFormatter; + import org.springframework.format.Printer; /** - * Prints Joda Time {@link ReadablePartial} instances using a {@link DateTimeFormatter}. + * Prints JodaTime {@link ReadablePartial} instances using a {@link DateTimeFormatter}. + * * @author Keith Donald * @since 3.0 */ @@ -31,7 +34,7 @@ public final class ReadablePartialPrinter implements Printer { private final DateTimeFormatter formatter; /** - * Creates a new ReadableInstantPrinter. + * Create a new ReadableInstantPrinter. * @param formatter the Joda DateTimeFormatter instance */ public ReadablePartialPrinter(DateTimeFormatter formatter) { @@ -41,4 +44,5 @@ public final class ReadablePartialPrinter implements Printer { public String print(ReadablePartial partial, Locale locale) { return JodaTimeContextHolder.getFormatter(this.formatter, locale).print(partial); } + }