Skip to content

Commit 53f2081

Browse files
committed
feat:stretch working;extra providers added; tests passing
1 parent bb8bc65 commit 53f2081

File tree

7 files changed

+265
-36
lines changed

7 files changed

+265
-36
lines changed

lesson_09/types/types_app/src/main/java/com/codedifferently/lesson9/Lesson9.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
package com.codedifferently.lesson9;
22

3+
import com.codedifferently.lesson9.dataprovider.DataProvider;
4+
import com.codedifferently.lesson9.generator.SampleFileGenerator;
35
import java.io.File;
46
import java.nio.file.Paths;
57
import java.util.List;
6-
78
import org.springframework.boot.CommandLineRunner;
89
import org.springframework.boot.SpringApplication;
910
import org.springframework.boot.autoconfigure.SpringBootApplication;
1011
import org.springframework.context.annotation.Configuration;
1112

12-
import com.codedifferently.lesson9.dataprovider.DataProvider;
13-
import com.codedifferently.lesson9.generator.SampleFileGenerator;
14-
1513
@Configuration
1614
@SpringBootApplication(scanBasePackages = "com.codedifferently")
1715
public class Lesson9 implements CommandLineRunner {
1816
private final List<DataProvider> providers;
17+
1918
public Lesson9(List<DataProvider> providers) {
2019
this.providers = providers;
2120
}
21+
2222
public static void main(String[] args) {
2323
var application = new SpringApplication(Lesson9.class);
2424
application.run(args);
@@ -33,10 +33,9 @@ public void run(String... args) throws Exception {
3333
if (option == null) {
3434
throw new IllegalArgumentException("Provider name is required");
3535
}
36-
if (option.equals("--all")){
37-
//TODO: change providers to search dynamically for all available providers
36+
if (option.equals("--bulk")) {
3837
for (DataProvider provider : providers) {
39-
String providerName = provider.getClass().getSimpleName().replace("Provider", "");
38+
String providerName = provider.getProviderName();
4039
String path = getDataPath();
4140
var fileGenerator = new SampleFileGenerator();
4241
fileGenerator.createProviderFile(path, providerName, provider);
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package com.codedifferently.lesson9.dataprovider;
22

33
import java.util.Map;
4-
import org.springframework.stereotype.Service;
54
import org.springframework.stereotype.Component;
5+
import org.springframework.stereotype.Service;
66

77
@Component
88
@Service
@@ -14,11 +14,11 @@ public String getProviderName() {
1414
public Map<String, Class> getColumnTypeByName() {
1515
return Map.of(
1616
"column1", Integer.class,
17-
"column2", Short.class,
18-
"column3", Long.class,
17+
"column2", Long.class,
18+
"column3", Double.class,
1919
"column4", Float.class,
20-
"column5", Boolean.class,
20+
"column5", Short.class,
2121
"column6", String.class,
22-
"column7", Double.class);
22+
"column7", Boolean.class);
2323
}
2424
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.codedifferently.lesson9.dataprovider;
2+
3+
import java.util.Map;
4+
import org.springframework.stereotype.Component;
5+
import org.springframework.stereotype.Service;
6+
7+
@Component
8+
@Service
9+
public class JohnDoeProvider extends DataProvider {
10+
public String getProviderName() {
11+
return "johndoe";
12+
}
13+
14+
public Map<String, Class> getColumnTypeByName() {
15+
return Map.of(
16+
"column1", String.class,
17+
"column2", Double.class,
18+
"column3", Float.class,
19+
"column4", Integer.class,
20+
"column5", Short.class,
21+
"column6", Boolean.class,
22+
"column7", Long.class);
23+
}
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.codedifferently.lesson9.dataprovider;
2+
3+
import java.util.Map;
4+
import org.springframework.stereotype.Component;
5+
import org.springframework.stereotype.Service;
6+
7+
@Component
8+
@Service
9+
public class MarySueProvider extends DataProvider {
10+
public String getProviderName() {
11+
return "marysue";
12+
}
13+
14+
public Map<String, Class> getColumnTypeByName() {
15+
return Map.of(
16+
"column1", Long.class,
17+
"column2", Integer.class,
18+
"column3", Short.class,
19+
"column4", String.class,
20+
"column5", Double.class,
21+
"column6", Boolean.class,
22+
"column7", Float.class);
23+
}
24+
}

lesson_09/types/types_app/src/main/java/com/codedifferently/lesson9/generator/SampleFileGenerator.java

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,16 @@ private List<ValueGenerator> getShuffledGenerators() {
4343
Collections.shuffle(generators);
4444
return generators;
4545
}
46-
private static final Map<Class<?>, ValueGenerator> TYPE_TO_GENERATOR = Map.of(
47-
Integer.class, new IntValueGenerator(),
48-
Short.class, new ShortValueGenerator(),
49-
Long.class, new LongValueGenerator(),
50-
Float.class, new FloatValueGenerator(),
51-
Boolean.class, new BooleanValueGenerator(),
52-
String.class, new StringValueGenerator(),
53-
Double.class, new DoubleValueGenerator()
54-
);
46+
47+
private static final Map<Class<?>, ValueGenerator> TYPE_TO_GENERATOR =
48+
Map.of(
49+
Integer.class, new IntValueGenerator(),
50+
Short.class, new ShortValueGenerator(),
51+
Long.class, new LongValueGenerator(),
52+
Float.class, new FloatValueGenerator(),
53+
Boolean.class, new BooleanValueGenerator(),
54+
String.class, new StringValueGenerator(),
55+
Double.class, new DoubleValueGenerator());
5556

5657
public void createProviderFile(String path, String providerName, DataProvider provider) {
5758
var generators = getGenerators(provider);
@@ -62,35 +63,32 @@ public void createProviderFile(String path, String providerName, DataProvider pr
6263
private List<ValueGenerator> getGenerators(DataProvider provider) {
6364
Map<String, Class> columnTypes = provider.getColumnTypeByName();
6465

65-
List<ValueGenerator> generators = new ArrayList<>();
66-
67-
// preserve the order of the map
68-
for (Class<?> type : columnTypes.values()) {
69-
ValueGenerator generator = TYPE_TO_GENERATOR.get(type);
70-
if (generator == null) {
71-
throw new IllegalArgumentException("No generator found for type: " + type);
72-
}
73-
generators.add(generator);
66+
ArrayList<ValueGenerator> generators = new ArrayList<>();
67+
for (int i = 1; i <= columnTypes.size(); i++) {
68+
String column = "column" + i;
69+
Class<?> type = columnTypes.get(column);
70+
ValueGenerator generator = TYPE_TO_GENERATOR.get(type);
71+
if (generator == null) {
72+
throw new IllegalArgumentException("No generator found for type: " + type);
73+
}
74+
generators.add(generator);
7475
}
75-
7676
return generators;
77-
}
78-
77+
}
7978

8079
private ArrayList<Map<String, String>> createSampleData(List<ValueGenerator> generators) {
8180
var rows = new ArrayList<Map<String, String>>();
8281
for (var i = 0; i < 10; ++i) {
83-
Map<String, String> row = createRow(generators);
8482
rows.add(createRow(generators));
8583
}
8684
return rows;
8785
}
8886

8987
private Map<String, String> createRow(List<ValueGenerator> generators) {
9088
var row = new LinkedHashMap<String, String>();
91-
for (int i = 0; i < GENERATORS.length; ++i) {
89+
for (int i = 0; i < generators.size(); ++i) {
9290
var columnIndex = i + 1;
93-
row.put("column" + columnIndex, GENERATORS[i].generateValue());
91+
row.put("column" + columnIndex, generators.get(i).generateValue());
9492
}
9593
return row;
9694
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
[
2+
{
3+
"column1": "g1js0nzd",
4+
"column2": "1.6606681429863535E308",
5+
"column3": "1.2805869E38",
6+
"column4": "1054728",
7+
"column5": "3129",
8+
"column6": "true",
9+
"column7": "703719617082371712"
10+
},
11+
{
12+
"column1": "h30rxny17e",
13+
"column2": "8.282815577198017E307",
14+
"column3": "1.0820827E38",
15+
"column4": "780108104",
16+
"column5": "6650",
17+
"column6": "false",
18+
"column7": "5454046321820867584"
19+
},
20+
{
21+
"column1": "s6np8hg",
22+
"column2": "2.8208962252116183E307",
23+
"column3": "2.3768544E38",
24+
"column4": "339850815",
25+
"column5": "16313",
26+
"column6": "true",
27+
"column7": "8453720971651134464"
28+
},
29+
{
30+
"column1": "bqne75",
31+
"column2": "8.373837106036268E307",
32+
"column3": "5.861436E37",
33+
"column4": "288100459",
34+
"column5": "30048",
35+
"column6": "false",
36+
"column7": "7679305292574085120"
37+
},
38+
{
39+
"column1": "hutbcs0xye36",
40+
"column2": "1.3842708486385358E308",
41+
"column3": "8.4233217E37",
42+
"column4": "779007889",
43+
"column5": "11556",
44+
"column6": "false",
45+
"column7": "2319260322728017408"
46+
},
47+
{
48+
"column1": "msjbnpf",
49+
"column2": "1.7243877401640865E308",
50+
"column3": "1.947562E38",
51+
"column4": "2104901001",
52+
"column5": "19434",
53+
"column6": "false",
54+
"column7": "934841370889226880"
55+
},
56+
{
57+
"column1": "dbkf9y",
58+
"column2": "4.798436305851196E307",
59+
"column3": "1.1582057E38",
60+
"column4": "1528993989",
61+
"column5": "7996",
62+
"column6": "false",
63+
"column7": "5801014611818378240"
64+
},
65+
{
66+
"column1": "o38xpdn9y4",
67+
"column2": "1.6665322356094382E308",
68+
"column3": "1.8127067E38",
69+
"column4": "1963091462",
70+
"column5": "32513",
71+
"column6": "true",
72+
"column7": "2780877838002517504"
73+
},
74+
{
75+
"column1": "ejhlwa7iqp5m",
76+
"column2": "1.4337186146423714E308",
77+
"column3": "5.339444E37",
78+
"column4": "1758943820",
79+
"column5": "26275",
80+
"column6": "false",
81+
"column7": "2980100409543326208"
82+
},
83+
{
84+
"column1": "1kbqpgao9u",
85+
"column2": "1.549097865099836E307",
86+
"column3": "5.2885714E37",
87+
"column4": "1949017496",
88+
"column5": "13939",
89+
"column6": "true",
90+
"column7": "6099495674264064000"
91+
}
92+
]
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
[
2+
{
3+
"column1": "8323401242976287744",
4+
"column2": "1925339329",
5+
"column3": "17786",
6+
"column4": "fz4y9u5c7ks",
7+
"column5": "1.4085358407272137E308",
8+
"column6": "true",
9+
"column7": "1.5423755E38"
10+
},
11+
{
12+
"column1": "1640893565135788032",
13+
"column2": "1840022839",
14+
"column3": "2222",
15+
"column4": "s8bnau",
16+
"column5": "1.6169953485867538E308",
17+
"column6": "true",
18+
"column7": "3.1250313E38"
19+
},
20+
{
21+
"column1": "6402496739894214656",
22+
"column2": "1236759895",
23+
"column3": "16791",
24+
"column4": "1xjte8sov",
25+
"column5": "1.70834073857316E307",
26+
"column6": "true",
27+
"column7": "1.7104834E37"
28+
},
29+
{
30+
"column1": "5926203096545441792",
31+
"column2": "1394213108",
32+
"column3": "16967",
33+
"column4": "9kg6mp",
34+
"column5": "2.8449263446709996E307",
35+
"column6": "false",
36+
"column7": "1.1814985E38"
37+
},
38+
{
39+
"column1": "4709712628913168384",
40+
"column2": "2112633226",
41+
"column3": "2665",
42+
"column4": "ulzigb1",
43+
"column5": "6.7220310987213086E305",
44+
"column6": "false",
45+
"column7": "1.9963256E38"
46+
},
47+
{
48+
"column1": "4404976585619377664",
49+
"column2": "794304081",
50+
"column3": "3409",
51+
"column4": "wtrgelpaxy",
52+
"column5": "4.3997162818255454E306",
53+
"column6": "false",
54+
"column7": "2.1994026E38"
55+
},
56+
{
57+
"column1": "3485178587998226432",
58+
"column2": "1773723922",
59+
"column3": "14476",
60+
"column4": "urvx4hdts",
61+
"column5": "2.2042412107745385E306",
62+
"column6": "true",
63+
"column7": "5.859355E37"
64+
},
65+
{
66+
"column1": "8749161736113519616",
67+
"column2": "1270074489",
68+
"column3": "7881",
69+
"column4": "szegra3",
70+
"column5": "3.9033024524326766E307",
71+
"column6": "true",
72+
"column7": "8.871395E37"
73+
},
74+
{
75+
"column1": "7650173425182467072",
76+
"column2": "831471465",
77+
"column3": "14126",
78+
"column4": "veusxbyf",
79+
"column5": "1.5255060830337515E308",
80+
"column6": "false",
81+
"column7": "2.9961802E38"
82+
},
83+
{
84+
"column1": "1021518763624020480",
85+
"column2": "276005754",
86+
"column3": "29256",
87+
"column4": "6lkhnrvfpe3",
88+
"column5": "1.15967298116037E308",
89+
"column6": "false",
90+
"column7": "1.0856294E38"
91+
}
92+
]

0 commit comments

Comments
 (0)