001 package org.apache.jcs.utils.date;
002
003 import java.text.DateFormatSymbols;
004 import java.text.FieldPosition;
005 import java.text.ParsePosition;
006 import java.text.SimpleDateFormat;
007 import java.util.Date;
008 import java.util.Locale;
009
010 /**
011 * Thread Safe version of SimpleDateFormat
012 * <p>
013 * This class simply synchronizes format and parse for SimpleDateFormat.
014 */
015 public class ThreadSafeSimpleDateFormat
016 extends SimpleDateFormat
017 {
018 /**
019 * Generated Serial Version ID
020 */
021 private static final long serialVersionUID = -6394173605134585999L;
022
023 /**
024 * Empty Constructor
025 */
026 public ThreadSafeSimpleDateFormat()
027 {
028 super();
029 }
030
031 /**
032 * @param pattern the pattern describing the date and time format
033 */
034 public ThreadSafeSimpleDateFormat( String pattern )
035 {
036 super( pattern );
037 }
038
039 /**
040 * @param pattern the pattern describing the date and time format
041 * @param lenient leniency option - if false, strictly valid dates are enforced
042 */
043 public ThreadSafeSimpleDateFormat( String pattern, boolean lenient )
044 {
045 super( pattern );
046 this.setLenient( lenient );
047 }
048
049 /**
050 * @param pattern the pattern describing the date and time format
051 * @param locale the locale whose date format symbols should be used.
052 */
053 public ThreadSafeSimpleDateFormat( String pattern, Locale locale )
054 {
055 super( pattern, locale );
056 }
057
058 /**
059 * @param pattern the pattern describing the date and time format
060 * @param formatSymbols the date format symbols to be used for formatting.
061 */
062 public ThreadSafeSimpleDateFormat( String pattern, DateFormatSymbols formatSymbols )
063 {
064 super( pattern, formatSymbols );
065 }
066
067 /**
068 * @param date date
069 * @param toAppendTo buffer to append to
070 * @param fieldPosition field position
071 * @return a string buffer with more data in it
072 */
073 @Override
074 public synchronized StringBuffer format( Date date, StringBuffer toAppendTo, FieldPosition fieldPosition )
075 {
076 return super.format( date, toAppendTo, fieldPosition );
077 }
078
079 /**
080 * @param source source
081 * @param pos parse position
082 * @return date
083 */
084 @Override
085 public synchronized Date parse( String source, ParsePosition pos )
086 {
087 return super.parse( source, pos );
088 }
089 }