From f0d21510f56243f5c0b12649c059fe791b3decf1 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Mon, 30 Dec 2013 19:13:04 +0100 Subject: [PATCH] Polishing Issue: SPR-11259 --- .../format/datetime/DateFormatterRegistrar.java | 10 +++++----- .../datetime/joda/JodaTimeFormatterRegistrar.java | 2 +- ...Jsr310DateTimeFormatAnnotationFormatterFactory.java | 6 +++--- .../core/convert/support/GenericConversionService.java | 9 ++++----- .../core/convert/support/DefaultConversionTests.java | 4 ++-- 5 files changed, 15 insertions(+), 16 deletions(-) diff --git a/spring-context/src/main/java/org/springframework/format/datetime/DateFormatterRegistrar.java b/spring-context/src/main/java/org/springframework/format/datetime/DateFormatterRegistrar.java index 8dfb7365ae..9e9b20a455 100644 --- a/spring-context/src/main/java/org/springframework/format/datetime/DateFormatterRegistrar.java +++ b/spring-context/src/main/java/org/springframework/format/datetime/DateFormatterRegistrar.java @@ -60,7 +60,7 @@ public class DateFormatterRegistrar implements FormatterRegistrar { // In order to retain back compatibility we only register Date/Calendar // types when a user defined formatter is specified (see SPR-10105) - if(this.dateFormatter != null) { + if (this.dateFormatter != null) { registry.addFormatter(this.dateFormatter); registry.addFormatterForFieldType(Calendar.class, this.dateFormatter); } @@ -113,7 +113,7 @@ public class DateFormatterRegistrar implements FormatterRegistrar { @Override public Long convert(Calendar source) { - return source.getTime().getTime(); + return source.getTimeInMillis(); } } @@ -129,11 +129,11 @@ public class DateFormatterRegistrar implements FormatterRegistrar { private static class LongToCalendarConverter implements Converter { - private final DateToCalendarConverter dateToCalendarConverter = new DateToCalendarConverter(); - @Override public Calendar convert(Long source) { - return this.dateToCalendarConverter.convert(new Date(source)); + Calendar calendar = Calendar.getInstance(); + calendar.setTimeInMillis(source); + return calendar; } } diff --git a/spring-context/src/main/java/org/springframework/format/datetime/joda/JodaTimeFormatterRegistrar.java b/spring-context/src/main/java/org/springframework/format/datetime/joda/JodaTimeFormatterRegistrar.java index 04e45fe316..d3e809afa4 100644 --- a/spring-context/src/main/java/org/springframework/format/datetime/joda/JodaTimeFormatterRegistrar.java +++ b/spring-context/src/main/java/org/springframework/format/datetime/joda/JodaTimeFormatterRegistrar.java @@ -187,7 +187,7 @@ public class JodaTimeFormatterRegistrar implements FormatterRegistrar { // In order to retain backwards compatibility we only register Date/Calendar // types when a user defined formatter is specified (see SPR-10105) - if( this.formatters.containsKey(Type.DATE_TIME)) { + if (this.formatters.containsKey(Type.DATE_TIME)) { addFormatterForFields(registry, new ReadableInstantPrinter(dateTimeFormatter), new DateTimeParser(dateTimeFormatter), diff --git a/spring-context/src/main/java/org/springframework/format/datetime/standard/Jsr310DateTimeFormatAnnotationFormatterFactory.java b/spring-context/src/main/java/org/springframework/format/datetime/standard/Jsr310DateTimeFormatAnnotationFormatterFactory.java index 0b3597ede1..de02cb390d 100644 --- a/spring-context/src/main/java/org/springframework/format/datetime/standard/Jsr310DateTimeFormatAnnotationFormatterFactory.java +++ b/spring-context/src/main/java/org/springframework/format/datetime/standard/Jsr310DateTimeFormatAnnotationFormatterFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 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. @@ -92,10 +92,10 @@ public class Jsr310DateTimeFormatAnnotationFormatterFactory } /** - * Factory method used to create a {@link org.joda.time.format.DateTimeFormatter}. + * Factory method used to create a {@link DateTimeFormatter}. * @param annotation the format annotation for the field * @param fieldType the type of field - * @return a {@link org.joda.time.format.DateTimeFormatter} instance + * @return a {@link DateTimeFormatter} instance */ protected DateTimeFormatter getFormatter(DateTimeFormat annotation, Class fieldType) { DateTimeFormatterFactory factory = new DateTimeFormatterFactory(); diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java b/spring-core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java index 6dc363b8a2..bd6b5dbc1c 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java @@ -456,6 +456,7 @@ public class GenericConversionService implements ConfigurableConversionService { } } + /** * Manages all converters registered with the service. */ @@ -614,12 +615,10 @@ public class GenericConversionService implements ConfigurableConversionService { this.converters.addFirst(converter); } - public GenericConverter getConverter(TypeDescriptor sourceType, - TypeDescriptor targetType) { + public GenericConverter getConverter(TypeDescriptor sourceType, TypeDescriptor targetType) { for (GenericConverter converter : this.converters) { - if (!(converter instanceof ConditionalGenericConverter) - || ((ConditionalGenericConverter) converter).matches(sourceType, - targetType)) { + if (!(converter instanceof ConditionalGenericConverter) || + ((ConditionalGenericConverter) converter).matches(sourceType, targetType)) { return converter; } } diff --git a/spring-core/src/test/java/org/springframework/core/convert/support/DefaultConversionTests.java b/spring-core/src/test/java/org/springframework/core/convert/support/DefaultConversionTests.java index 03ff8c13b1..8f98b475d2 100644 --- a/spring-core/src/test/java/org/springframework/core/convert/support/DefaultConversionTests.java +++ b/spring-core/src/test/java/org/springframework/core/convert/support/DefaultConversionTests.java @@ -209,7 +209,7 @@ public class DefaultConversionTests { } @Test - public void testStringToEnumWithSubclss() throws Exception { + public void testStringToEnumWithSubclass() throws Exception { assertEquals(SubFoo.BAZ, conversionService.convert("BAZ", SubFoo.BAR.getClass())); } @@ -224,7 +224,7 @@ public class DefaultConversionTests { } public static enum Foo { - BAR, BAZ; + BAR, BAZ } public static enum SubFoo {