Skip to content

Commit

Permalink
Merge pull request #1332 from datafaker-net/refactoring/simplify-en-file
Browse files Browse the repository at this point in the history
simplify EnFile: don't collect a static list that is needed only once
  • Loading branch information
kingthorin authored Aug 22, 2024
2 parents b5b1bdc + 7dbe3e1 commit 74e02a8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/main/java/net/datafaker/service/FakeValuesGrouping.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ public class FakeValuesGrouping implements FakeValuesInterface {
private final Map<String, Collection<FakeValuesInterface>> fakeValues = new HashMap<>();

static {
for (EnFile file : EnFile.getFiles()) {
EnFile.getFiles().forEach(file -> {
ENGLISH_FAKE_VALUE_GROUPING.add(FakeValues.of(FakeValuesContext.of(Locale.ENGLISH, file.getFile(), file.getPath())));
}
});
}

public void add(FakeValuesInterface fakeValue) {
Expand Down
17 changes: 4 additions & 13 deletions src/main/java/net/datafaker/service/files/EnFile.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package net.datafaker.service.files;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;

public class EnFile {
public static final String YML = ".yml";
private static final String YML = ".yml";
private final String file;
private final String path;

Expand Down Expand Up @@ -260,7 +258,7 @@ public String getPath() {
"zodiac.yml").map(EnFile::new).toList();

// files where the search path can't be derived from the filename
private static final List<EnFile> FILES_WITH_A_DIFFERENT_PATH = Arrays.asList(
private static final List<EnFile> FILES_WITH_A_DIFFERENT_PATH = List.of(
new EnFile("animal.yml", "creature"),
new EnFile("cat.yml", "creature"),
new EnFile("dog.yml", "creature"),
Expand Down Expand Up @@ -294,14 +292,7 @@ public String getPath() {
new EnFile("observation.yml", "healthcare")
);

private static final List<EnFile> ALL_FILES;

static {
ALL_FILES = new ArrayList<>(FILES);
ALL_FILES.addAll(FILES_WITH_A_DIFFERENT_PATH);
}

public static List<EnFile> getFiles() {
return ALL_FILES;
public static Stream<EnFile> getFiles() {
return Stream.concat(FILES.stream(), FILES_WITH_A_DIFFERENT_PATH.stream());
}
}

0 comments on commit 74e02a8

Please sign in to comment.