This repository was 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.
- Loading branch information
Simon Laing
committed
May 15, 2020
1 parent
811d925
commit 53425fc
Showing
48 changed files
with
1,527 additions
and
73 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
.idea/runConfigurations/Example_generation__relational_.xml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
23 changes: 23 additions & 0 deletions
23
...main/java/com/scottlogic/datahelix/generator/common/output/RelationalGeneratedObject.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.datahelix.generator.common.output; | ||
|
||
import java.util.Map; | ||
|
||
public interface RelationalGeneratedObject { | ||
Map<String, SubGeneratedObject> getSubObjects(); | ||
} |
27 changes: 27 additions & 0 deletions
27
...on/src/main/java/com/scottlogic/datahelix/generator/common/output/SubGeneratedObject.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 @@ | ||
/* | ||
* 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.datahelix.generator.common.output; | ||
|
||
import com.scottlogic.datahelix.generator.common.profile.Field; | ||
|
||
import java.util.List; | ||
|
||
public interface SubGeneratedObject { | ||
List<Field> getFields(); | ||
List<GeneratedObject> getData(); | ||
boolean isArray(); | ||
} |
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
48 changes: 48 additions & 0 deletions
48
...m/scottlogic/datahelix/generator/core/generation/relationships/ExtentAugmentedFields.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,48 @@ | ||
/* | ||
* 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.datahelix.generator.core.generation.relationships; | ||
|
||
import com.scottlogic.datahelix.generator.common.profile.Field; | ||
import com.scottlogic.datahelix.generator.common.profile.FieldType; | ||
import com.scottlogic.datahelix.generator.common.profile.Fields; | ||
import com.scottlogic.datahelix.generator.common.profile.SpecificFieldType; | ||
|
||
public class ExtentAugmentedFields extends Fields { | ||
private static final SpecificFieldType integer = new SpecificFieldType("integer", FieldType.NUMERIC, null); | ||
|
||
public static final String minField = "min"; | ||
public static final String maxField = "max"; | ||
public static final Field min = new Field(minField, integer, false, null, false, true, null); | ||
public static final Field max = new Field(maxField, integer, false, null, false, true, null); | ||
|
||
public ExtentAugmentedFields(Fields fields) { | ||
super(fields.asList()); | ||
} | ||
|
||
@Override | ||
public Field getByName(String fieldName) { | ||
if (fieldName.equals(minField)) { | ||
return min; | ||
} | ||
|
||
if (fieldName.equals(maxField)) { | ||
return max; | ||
} | ||
|
||
return super.getByName(fieldName); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
...scottlogic/datahelix/generator/core/generation/relationships/GeneratedRelationalData.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,58 @@ | ||
/* | ||
* 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.datahelix.generator.core.generation.relationships; | ||
|
||
import com.scottlogic.datahelix.generator.common.output.GeneratedObject; | ||
import com.scottlogic.datahelix.generator.common.output.RelationalGeneratedObject; | ||
import com.scottlogic.datahelix.generator.common.output.SubGeneratedObject; | ||
import com.scottlogic.datahelix.generator.common.profile.Field; | ||
import com.scottlogic.datahelix.generator.core.profile.relationships.Relationship; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class GeneratedRelationalData implements GeneratedObject, RelationalGeneratedObject { | ||
private final GeneratedObject underlyingObject; | ||
private final Map<String, SubGeneratedObject> subObjects = new HashMap<>(); | ||
|
||
public GeneratedRelationalData(GeneratedObject underlyingObject) { | ||
this.underlyingObject = underlyingObject; | ||
} | ||
|
||
@Override | ||
public Object getFormattedValue(Field field) { | ||
return underlyingObject.getFormattedValue(field); | ||
} | ||
|
||
@Override | ||
public Object getValue(Field field) { | ||
return underlyingObject.getValue(field); | ||
} | ||
|
||
@Override | ||
public Map<String, SubGeneratedObject> getSubObjects() { | ||
return subObjects; | ||
} | ||
|
||
public void addSubObject(Relationship relationship, SubGeneratedObject subObject) { | ||
if (!subObjects.containsKey(relationship.getName())) { | ||
subObjects.put(relationship.getName(), subObject); | ||
} else { | ||
throw new RuntimeException("Sub-object for this relationship already exists"); | ||
} | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
...java/com/scottlogic/datahelix/generator/core/generation/relationships/OneToManyRange.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,64 @@ | ||
/* | ||
* 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.datahelix.generator.core.generation.relationships; | ||
|
||
public class OneToManyRange { | ||
private final int min; | ||
private final Integer max; | ||
|
||
public OneToManyRange(int min, Integer max) { | ||
this.min = min; | ||
this.max = max; | ||
} | ||
|
||
public int getMin() { | ||
return min; | ||
} | ||
|
||
public Integer getMax() { | ||
return max; | ||
} | ||
|
||
public OneToManyRange withMin(int min) { | ||
if (min > this.min) { | ||
return new OneToManyRange(min, max); | ||
} | ||
|
||
return this; | ||
} | ||
|
||
public OneToManyRange withMax(int max) { | ||
if (this.max == null || max < this.max) { | ||
return new OneToManyRange(min, max); | ||
} | ||
|
||
return this; | ||
} | ||
|
||
public boolean isEmpty() { | ||
return this.max != null && this.min >= this.max; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
if (max == null) { | ||
return min + ".."; | ||
} | ||
|
||
return min + ".." + max; | ||
} | ||
} |
Oops, something went wrong.