Skip to content

Commit c06643b

Browse files
committed
Fix PMD / Cache DTF
1 parent 35b8311 commit c06643b

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 2.1.3
2+
* Cache `DateTimeFormatter` if possible
3+
* Updated dependencies
4+
15
# 2.1.2
26
* Migrated deployment to _Sonatype Maven Central Portal_ [#155](https://github.com/xdev-software/standard-maven-template/issues/155)
37
* Updated dependencies

vaadin-editable-label/src/main/java/software/xdev/vaadin/editable_label/predefined/EditableLabelDatePicker.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818
import java.time.LocalDate;
1919
import java.time.format.DateTimeFormatter;
20+
import java.util.Collections;
21+
import java.util.Map;
22+
import java.util.WeakHashMap;
2023
import java.util.function.Consumer;
2124

2225
import com.vaadin.flow.component.datepicker.DatePicker;
@@ -33,6 +36,8 @@
3336
public class EditableLabelDatePicker
3437
extends AbstractEditableLabel<EditableLabelDatePicker, DatePicker, LocalDate>
3538
{
39+
protected static final Map<String, DateTimeFormatter> CACHE_DTF = Collections.synchronizedMap(new WeakHashMap<>());
40+
3641
public EditableLabelDatePicker()
3742
{
3843
this(new DatePicker());
@@ -60,7 +65,9 @@ public EditableLabelDatePicker withTryUseI18NFormat()
6065
final DatePicker.DatePickerI18n i18n = this.editor.getI18n();
6166
if(i18n != null && !i18n.getDateFormats().isEmpty())
6267
{
63-
this.withLabelGenerator(DateTimeFormatter.ofPattern(i18n.getDateFormats().get(0))::format);
68+
final DateTimeFormatter dtf =
69+
CACHE_DTF.computeIfAbsent(i18n.getDateFormats().get(0), DateTimeFormatter::ofPattern);
70+
this.withLabelGenerator(dtf::format);
6471
}
6572
return this.self();
6673
}

0 commit comments

Comments
 (0)