Chose ThreadLocal instead the recommended java.time.format.DateTimeFormatter to keep public method getFormatter() intact
This commit is contained in:
@@ -2,23 +2,24 @@ package org.mustangproject.ZUGFeRD;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.mustangproject.ZUGFeRD.model.DateTimeTypeConstants;
|
||||
|
||||
public enum ZUGFeRDDateFormat {
|
||||
|
||||
MONTH_OF_YEAR(DateTimeTypeConstants.MONTH, new SimpleDateFormat("yyyyMM")),
|
||||
WEEK_OF_YEAR(DateTimeTypeConstants.WEEK, new SimpleDateFormat("yyyyww")),
|
||||
DATE(DateTimeTypeConstants.DATE, new SimpleDateFormat("yyyyMMdd"));
|
||||
MONTH_OF_YEAR(DateTimeTypeConstants.MONTH, () -> new SimpleDateFormat("yyyyMM")),
|
||||
WEEK_OF_YEAR(DateTimeTypeConstants.WEEK, () -> new SimpleDateFormat("yyyyww")),
|
||||
DATE(DateTimeTypeConstants.DATE, () -> new SimpleDateFormat("yyyyMMdd"));
|
||||
|
||||
private String dateTimeType;
|
||||
private SimpleDateFormat formatter;
|
||||
private ThreadLocal<SimpleDateFormat> formatter;
|
||||
private static final String QDT_FORMAT = "<qdt:DateTimeString format=\"%s\">%s</qdt:DateTimeString>";
|
||||
private static final String UDT_FORMAT = "<udt:DateTimeString format=\"%s\">%s</udt:DateTimeString>";
|
||||
|
||||
private ZUGFeRDDateFormat(String dateTimeType, SimpleDateFormat formatter) {
|
||||
private ZUGFeRDDateFormat(String dateTimeType, Supplier<SimpleDateFormat> formatter) {
|
||||
this.dateTimeType = dateTimeType;
|
||||
this.formatter = formatter;
|
||||
this.formatter = ThreadLocal.withInitial(formatter);
|
||||
}
|
||||
|
||||
public String getDateTimeType() {
|
||||
@@ -26,7 +27,7 @@ public enum ZUGFeRDDateFormat {
|
||||
}
|
||||
|
||||
public SimpleDateFormat getFormatter() {
|
||||
return formatter;
|
||||
return formatter.get();
|
||||
}
|
||||
|
||||
public String simpleFormat(Date date){
|
||||
|
||||
Reference in New Issue
Block a user