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.
Merge pull request #1481 from finos/1430-custom-generator-interface
1430 custom generator interface
- Loading branch information
Showing
69 changed files
with
882 additions
and
65 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
build/ | ||
out/ | ||
bin/ |
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,15 @@ | ||
plugins { | ||
id 'java' | ||
} | ||
|
||
group 'com.scottlogic.deg' | ||
|
||
sourceCompatibility = 1.8 | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
testCompile group: 'junit', name: 'junit', version: '4.12' | ||
} |
87 changes: 87 additions & 0 deletions
87
custom/src/main/java/com/scottlogic/deg/custom/CustomGenerator.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,87 @@ | ||
/* | ||
* Copyright 2019 Scott Logic Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.scottlogic.deg.custom; | ||
|
||
import java.util.stream.Stream; | ||
|
||
public interface CustomGenerator<T> { | ||
|
||
/*** | ||
* REQUIRED! used in profile reading | ||
* @return the name of the custom generator | ||
*/ | ||
String generatorName(); | ||
|
||
/** | ||
* STRING for Strings | ||
* NUMERIC for BigDecimals | ||
* DATETIME for OffsetDateTimes | ||
* @return accepted field type | ||
*/ | ||
CustomGeneratorFieldType fieldType(); | ||
|
||
/** | ||
* the part of the generator to be used during random generation | ||
* | ||
* Required if you want your custom generator to support random generation | ||
* | ||
* @return your stream of random values | ||
*/ | ||
Stream<T> generateRandom(); | ||
|
||
/** | ||
* the part of the generator to be used when the generator constraint is negated during random generation | ||
* - this should be implemented as the values that your regular generator should not be outputting | ||
* | ||
* Required if you want your custom generator to support being negated in random mode | ||
* Required if you want your custom generator to support used in the IF part of IF THEN constraints | ||
* | ||
* @return your stream of random values that are not what would be produced by the generator if it were not negated | ||
*/ | ||
Stream<T> generateNegatedRandom(); | ||
|
||
/** | ||
* the part of the generator to be used during sequential generation | ||
* | ||
* Required if you want your custom generator to support sequential generation | ||
* Required if you want your custom generator to support unique keys generation | ||
* | ||
* @return your stream of random values | ||
*/ | ||
Stream<T> generateSequential(); | ||
|
||
/** | ||
* the part of the generator to be used when the generator constraint is negated during sequential generation | ||
* | ||
* Required if you want your custom generator to support being negated in sequential mode | ||
* should not be used with unique keys generation | ||
* | ||
* @return your stream of sequential values that are not what would be produced by the generator if it were not negated | ||
*/ | ||
Stream<T> generateNegatedSequential(); | ||
|
||
/** | ||
* The function to check whether a value from a set can be generated from this generator | ||
* | ||
* Required if you want your custom generator to support being combined with inSet and equalTo constraints | ||
* | ||
* @param value the value from the set to be tested against | ||
* | ||
* @return true if the generator would be able to produce the value | ||
*/ | ||
boolean setMatchingFunction(T value); | ||
} |
23 changes: 23 additions & 0 deletions
23
custom/src/main/java/com/scottlogic/deg/custom/CustomGeneratorFieldType.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,23 @@ | ||
/* | ||
* Copyright 2019 Scott Logic Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.scottlogic.deg.custom; | ||
|
||
public enum CustomGeneratorFieldType { | ||
NUMERIC, | ||
STRING, | ||
DATETIME | ||
} |
30 changes: 30 additions & 0 deletions
30
custom/src/main/java/com/scottlogic/deg/custom/CustomGeneratorList.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,30 @@ | ||
/* | ||
* Copyright 2019 Scott Logic Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.scottlogic.deg.custom; | ||
|
||
import com.scottlogic.deg.custom.example.LoremIpsumGeneratorCreator; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public class CustomGeneratorList { | ||
public List<CustomGenerator> get() { | ||
return Arrays.asList( | ||
LoremIpsumGeneratorCreator.create() | ||
); | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
custom/src/main/java/com/scottlogic/deg/custom/builder/BuiltCustomGenerator.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,87 @@ | ||
/* | ||
* Copyright 2019 Scott Logic Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
|
||
package com.scottlogic.deg.custom.builder; | ||
|
||
import com.scottlogic.deg.custom.CustomGenerator; | ||
import com.scottlogic.deg.custom.CustomGeneratorFieldType; | ||
|
||
import java.util.function.Function; | ||
import java.util.function.Supplier; | ||
import java.util.stream.Stream; | ||
|
||
public class BuiltCustomGenerator<T> implements CustomGenerator<T> { | ||
|
||
private final CustomGeneratorFieldType fieldType; | ||
private final String name; | ||
private final Function<T, Boolean> matchingFunction; | ||
private final Supplier<Stream<T>> randomGenerator; | ||
private final Supplier<Stream<T>> negatedRandomGenerator; | ||
private final Supplier<Stream<T>> sequentialGenerator; | ||
private final Supplier<Stream<T>> negatedSequentialGenerator; | ||
|
||
public BuiltCustomGenerator(CustomGeneratorFieldType fieldType, | ||
String name, | ||
Function<T, Boolean> matchingFunction, | ||
Supplier<Stream<T>> randomGenerator, | ||
Supplier<Stream<T>> negatedRandomGenerator, | ||
Supplier<Stream<T>> sequentialGenerator, | ||
Supplier<Stream<T>> negatedSequentialGenerator) { | ||
this.fieldType = fieldType; | ||
this.name = name; | ||
this.matchingFunction = matchingFunction; | ||
this.randomGenerator = randomGenerator; | ||
this.negatedRandomGenerator = negatedRandomGenerator; | ||
this.sequentialGenerator = sequentialGenerator; | ||
this.negatedSequentialGenerator = negatedSequentialGenerator; | ||
} | ||
|
||
@Override | ||
public String generatorName() { | ||
return name; | ||
} | ||
|
||
@Override | ||
public CustomGeneratorFieldType fieldType() { | ||
return fieldType; | ||
} | ||
|
||
@Override | ||
public Stream<T> generateRandom() { | ||
return randomGenerator.get(); | ||
} | ||
|
||
@Override | ||
public Stream<T> generateNegatedRandom() { | ||
return negatedRandomGenerator.get(); | ||
} | ||
|
||
@Override | ||
public Stream<T> generateSequential() { | ||
return sequentialGenerator.get(); | ||
} | ||
|
||
@Override | ||
public Stream<T> generateNegatedSequential() { | ||
return negatedSequentialGenerator.get(); | ||
} | ||
|
||
@Override | ||
public boolean setMatchingFunction(T value) { | ||
return matchingFunction.apply(value); | ||
} | ||
} |
Oops, something went wrong.