diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2011-12-12 11:09:39 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2011-12-12 11:09:39 +0100 |
commit | 5c1cabf8355199f03924bbabf34f98b315a01f51 (patch) | |
tree | 57cf0c89c94139985a6f3d620b67403f390b06c9 /sonar-plugin-api/src/main/java/org/sonar/api/utils/DateUtils.java | |
parent | 8c8024942b66f19af710e8ff17534cb8dbe9fc42 (diff) | |
download | sonarqube-5c1cabf8355199f03924bbabf34f98b315a01f51.tar.gz sonarqube-5c1cabf8355199f03924bbabf34f98b315a01f51.zip |
Improve DateUtils by using generics in ThreadLocal + rename some unit tests of DateUtilsTest
Diffstat (limited to 'sonar-plugin-api/src/main/java/org/sonar/api/utils/DateUtils.java')
-rw-r--r-- | sonar-plugin-api/src/main/java/org/sonar/api/utils/DateUtils.java | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/DateUtils.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/DateUtils.java index 12cdfa47eb6..836169d5880 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/DateUtils.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/DateUtils.java @@ -21,13 +21,16 @@ package org.sonar.api.utils; import java.lang.ref.Reference; import java.lang.ref.SoftReference; -import java.text.*; +import java.text.DateFormat; +import java.text.FieldPosition; +import java.text.ParsePosition; +import java.text.SimpleDateFormat; import java.util.Date; /** * Parses and formats <a href="http://en.wikipedia.org/wiki/ISO_8601">ISO 8601</a> dates. * This class is thread-safe. - * + * * @since 2.7 */ public final class DateUtils { @@ -82,11 +85,11 @@ public final class DateUtils { this.format = format; } - private final transient ThreadLocal cache = new ThreadLocal() { - public Object get() { - Reference softRef = (Reference) super.get(); + private final transient ThreadLocal<Reference<DateFormat>> cache = new ThreadLocal<Reference<DateFormat>>() { + public Reference<DateFormat> get() { + Reference<DateFormat> softRef = super.get(); if (softRef == null || softRef.get() == null) { - softRef = new SoftReference(new SimpleDateFormat(format)); + softRef = new SoftReference<DateFormat>(new SimpleDateFormat(format)); super.set(softRef); } return softRef; |