Skip to content

Commit

Permalink
perf(demo): initialize Faker as singleton
Browse files Browse the repository at this point in the history
Close #107
  • Loading branch information
javier-godoy committed Apr 4, 2024
1 parent c285e90 commit f277206
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.flowingcode.vaadin.addons.gridexporter;

import com.github.javafaker.Faker;

public class FakerInstance {

private static final Faker faker = new Faker();

public static Faker get() {
return faker;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
@SuppressWarnings("serial")
public class GridExporterBigDatasetDemo extends Div {

private static final Faker faker = FakerInstance.get();

public GridExporterBigDatasetDemo() throws EncryptedDocumentException, IOException {
Grid<Person> grid = new Grid<>(Person.class);
grid.removeAllColumns();
Expand All @@ -55,7 +57,6 @@ public GridExporterBigDatasetDemo() throws EncryptedDocumentException, IOExcepti
.asLongStream()
.mapToObj(
number -> {
Faker faker = new Faker();
Double budget = faker.number().randomDouble(2, 10000, 100000);
total[0] = total[0].add(BigDecimal.valueOf(budget));
budgetCol.setFooter("$" + total[0]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
@SuppressWarnings("serial")
public class GridExporterCustomColumnsDemo extends Div {

private static final Faker faker = FakerInstance.get();

public GridExporterCustomColumnsDemo() throws EncryptedDocumentException, IOException {
Grid<Person> grid = new Grid<>(Person.class);
grid.removeAllColumns();
Expand All @@ -58,7 +60,6 @@ public GridExporterCustomColumnsDemo() throws EncryptedDocumentException, IOExce
.asLongStream()
.mapToObj(
number -> {
Faker faker = new Faker();
Double budget = faker.number().randomDouble(2, 10000, 100000);
total[0] = total[0].add(BigDecimal.valueOf(budget));
budgetColumn.setFooter("$" + total[0]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
@SuppressWarnings("serial")
public class GridExporterCustomLinkDemo extends Div {

private static final Faker faker = FakerInstance.get();

public GridExporterCustomLinkDemo() throws EncryptedDocumentException, IOException {
Grid<Person> grid = new Grid<>(Person.class);
grid.removeAllColumns();
Expand All @@ -55,7 +57,6 @@ public GridExporterCustomLinkDemo() throws EncryptedDocumentException, IOExcepti
.asLongStream()
.mapToObj(
number -> {
Faker faker = new Faker();
Double budget = faker.number().randomDouble(2, 10000, 100000);
total[0] = total[0].add(BigDecimal.valueOf(budget));
c.setFooter("$" + total[0]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
@SuppressWarnings("serial")
public class GridExporterCustomTemplateDemo extends Div {

private static final Faker faker = FakerInstance.get();

public GridExporterCustomTemplateDemo() throws EncryptedDocumentException, IOException {
Grid<Person> grid = new Grid<>(Person.class);
DecimalFormat decimalFormat = new DecimalFormat("$#,###.##");
Expand All @@ -53,7 +55,7 @@ public GridExporterCustomTemplateDemo() throws EncryptedDocumentException, IOExc
LitRenderer.<Person>of("<b>${item.name}</b>").withProperty("name", Person::getName))
.setHeader("Name");
grid.addColumn("lastName").setHeader("Last Name");
grid.addColumn(item -> Faker.instance().lorem().characters(30, 50)).setHeader("Big column");
grid.addColumn(item -> faker.lorem().characters(30, 50)).setHeader("Big column");
Column<Person> budgetColumn =
grid.addColumn(item -> decimalFormat.format(item.getBudget()))
.setHeader("Budget")
Expand All @@ -65,7 +67,6 @@ public GridExporterCustomTemplateDemo() throws EncryptedDocumentException, IOExc
.asLongStream()
.mapToObj(
number -> {
Faker faker = new Faker();
Double budget = faker.number().randomDouble(2, 10000, 100000);
total[0] = total[0].add(BigDecimal.valueOf(budget));
budgetColumn.setFooter(new DecimalFormat("$#,###.##").format(total[0]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
@SuppressWarnings("serial")
public class GridExporterDemo extends Div {

private static final Faker faker = FakerInstance.get();

public GridExporterDemo() throws EncryptedDocumentException, IOException {
Grid<Person> grid = new Grid<>(Person.class);
grid.removeAllColumns();
Expand All @@ -63,7 +65,6 @@ public GridExporterDemo() throws EncryptedDocumentException, IOException {
.asLongStream()
.mapToObj(
number -> {
Faker faker = new Faker();
Double budget = faker.number().randomDouble(2, 10000, 100000);
total[0] = total[0].add(BigDecimal.valueOf(budget));
budgetCol.setFooter("$" + total[0]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
@SuppressWarnings("serial")
public class GridExporterHierarchicalDataDemo extends Div {

private static final Faker faker = FakerInstance.get();

private Map<Integer, PersonTreeEntry> ageToTreeEntryMap = new HashMap<>();
private List<PersonTreeEntry> people;

Expand Down Expand Up @@ -74,7 +76,6 @@ public GridExporterHierarchicalDataDemo() throws EncryptedDocumentException, IOE
.asLongStream()
.mapToObj(
number -> {
Faker faker = new Faker();
Double budget = faker.number().randomDouble(2, 10000, 100000);
total[0] = total[0].add(BigDecimal.valueOf(budget));
budgetCol.setFooter("$" + total[0]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@
@SuppressWarnings("serial")
public class GridExporterSimpleCustomTemplateDemo extends Div {

private static final Faker faker = FakerInstance.get();

public GridExporterSimpleCustomTemplateDemo() throws EncryptedDocumentException, IOException {
Faker faker = new Faker();
DecimalFormat decimalFormat = new DecimalFormat("$#,###.##");
Grid<Person> grid = new Grid<>(Person.class);
grid.removeAllColumns();
Expand Down

0 comments on commit f277206

Please sign in to comment.