This repository has been archived by the owner on Apr 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(#1534): Use composition to control generation behaviour
- Loading branch information
Simon Laing
committed
Jan 31, 2020
1 parent
d0525de
commit c77df08
Showing
6 changed files
with
90 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...c/main/java/com/scottlogic/datahelix/generator/core/generation/LimitingDataGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.scottlogic.datahelix.generator.core.generation; | ||
|
||
import com.google.inject.Inject; | ||
import com.google.inject.name.Named; | ||
import com.scottlogic.datahelix.generator.common.output.GeneratedObject; | ||
import com.scottlogic.datahelix.generator.core.profile.Profile; | ||
|
||
import java.util.stream.Stream; | ||
|
||
public class LimitingDataGenerator implements DataGenerator { | ||
private final DataGenerator dataGenerator; | ||
private final long maxRows; | ||
|
||
//created by DataGeneratorProvider | ||
public LimitingDataGenerator( | ||
DataGenerator dataGenerator, | ||
long maxRows) { | ||
this.dataGenerator = dataGenerator; | ||
this.maxRows = maxRows; | ||
} | ||
|
||
@Override | ||
public Stream<GeneratedObject> generateData(Profile profile) { | ||
return dataGenerator.generateData(profile) | ||
.limit(maxRows); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...main/java/com/scottlogic/datahelix/generator/core/generation/MonitoringDataGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.scottlogic.datahelix.generator.core.generation; | ||
|
||
import com.google.inject.Inject; | ||
import com.scottlogic.datahelix.generator.common.output.GeneratedObject; | ||
import com.scottlogic.datahelix.generator.core.profile.Profile; | ||
|
||
import java.util.stream.Stream; | ||
|
||
public class MonitoringDataGenerator implements DataGenerator { | ||
private final DataGenerator dataGenerator; | ||
private final DataGeneratorMonitor monitor; | ||
|
||
//created by DataGeneratorProvider | ||
public MonitoringDataGenerator( | ||
DataGenerator dataGenerator, | ||
DataGeneratorMonitor monitor) { | ||
this.dataGenerator = dataGenerator; | ||
this.monitor = monitor; | ||
} | ||
|
||
@Override | ||
public Stream<GeneratedObject> generateData(Profile profile) { | ||
monitor.generationStarting(); | ||
|
||
return dataGenerator.generateData(profile) | ||
.peek(monitor::rowEmitted); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
core/src/main/java/com/scottlogic/datahelix/generator/core/guice/DataGeneratorProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.scottlogic.datahelix.generator.core.guice; | ||
|
||
import com.google.inject.Inject; | ||
import com.google.inject.Provider; | ||
import com.google.inject.name.Named; | ||
import com.scottlogic.datahelix.generator.core.generation.*; | ||
|
||
public class DataGeneratorProvider implements Provider<DataGenerator> { | ||
private final DataGenerator coreGenerator; | ||
private final long maxRows; | ||
private final DataGeneratorMonitor monitor; | ||
|
||
@Inject | ||
public DataGeneratorProvider( | ||
DecisionTreeDataGenerator coreGenerator, | ||
@Named("config:maxRows") long maxRows, | ||
DataGeneratorMonitor monitor) { | ||
this.coreGenerator = coreGenerator; | ||
this.maxRows = maxRows; | ||
this.monitor = monitor; | ||
} | ||
|
||
@Override | ||
public DataGenerator get() { | ||
return new MonitoringDataGenerator( | ||
new LimitingDataGenerator(coreGenerator, maxRows), | ||
monitor); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters