Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

Commit

Permalink
Merge pull request #1679 from sl-slaing/poc/relational-data
Browse files Browse the repository at this point in the history
841- Relational data - beta feature
  • Loading branch information
Simon Laing authored May 31, 2020
2 parents 811d925 + 577c27b commit c441840
Show file tree
Hide file tree
Showing 69 changed files with 1,984 additions and 226 deletions.
10 changes: 10 additions & 0 deletions .idea/runConfigurations/Example_generation__relational_.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@
/** A set of values representing one complete, discrete output (eg, this could be used to make a full CSV row) */
public interface GeneratedObject {
Object getFormattedValue(Field field);
Object getValue(Field field);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.scottlogic.datahelix.generator.output.guice;
package com.scottlogic.datahelix.generator.common.output;

public enum OutputFormat {
CSV,
Expand Down
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();
}
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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,62 +16,13 @@

package com.scottlogic.datahelix.generator.common.profile;



import java.util.Iterator;
import java.util.List;
import java.util.stream.Stream;

public class Fields implements Iterable<Field> {
private final List<Field> fields;

public Fields(List<Field> fields) {
this.fields = fields;
}

public Field getByName(String fieldName) {
return this.fields.stream()
.filter(f -> f.getName().equals(fieldName))
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("Profile fields do not contain " + fieldName));
}

public int size() {
return this.fields.size();
}

@Override
public Iterator<Field> iterator() {
return fields.iterator();
}

public Stream<Field> stream() {
return this.fields.stream();
}

public Stream<Field> getExternalStream() {
return this.stream().filter(f -> !f.isInternal());
}

public List<Field> asList() {
return fields;
}

@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (obj.getClass() != getClass()) {
return false;
}

Fields fields = (Fields) obj;
return this.fields.equals(fields.fields);
}

@Override
public int hashCode() {
return fields.hashCode();
}
}
public interface Fields extends Iterable<Field> {
Field getByName(String fieldName);
int size();
Stream<Field> stream();
Stream<Field> getExternalStream();
List<Field> asList();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* 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.profile;

import java.util.Iterator;
import java.util.List;
import java.util.stream.Stream;

public class ProfileFields implements Fields {
private final List<Field> fields;

public ProfileFields(List<Field> fields) {
this.fields = fields;
}

public Field getByName(String fieldName) {
return this.fields.stream()
.filter(f -> f.getName().equals(fieldName))
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("Profile fields do not contain " + fieldName));
}

public int size() {
return this.fields.size();
}

@Override
public Iterator<Field> iterator() {
return fields.iterator();
}

public Stream<Field> stream() {
return this.fields.stream();
}

public Stream<Field> getExternalStream() {
return this.stream().filter(f -> !f.isInternal());
}

public List<Field> asList() {
return fields;
}

@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (obj.getClass() != getClass()) {
return false;
}

ProfileFields fields = (ProfileFields) obj;
return this.fields.equals(fields.fields);
}

@Override
public int hashCode() {
return fields.hashCode();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
import java.util.Arrays;
import static com.scottlogic.datahelix.generator.common.profile.FieldBuilder.createField;

class FieldsTests
class ProfileFieldsTests
{
@Test
void equals_objIsNull_returnsFalse() {
Fields fields = new Fields(
Fields fields = new ProfileFields(
Arrays.asList(
createField("Test")
)
Expand All @@ -43,7 +43,7 @@ void equals_objIsNull_returnsFalse() {

@Test
void equals_objTypeIsNotProfileFields_returnsFalse() {
Fields fields = new Fields(
Fields fields = new ProfileFields(
Arrays.asList(
createField("Test")
)
Expand All @@ -59,15 +59,15 @@ void equals_objTypeIsNotProfileFields_returnsFalse() {

@Test
void equals_rowSpecFieldsLengthNotEqualToOtherObjectFieldsLength_returnsFalse() {
Fields fields = new Fields(
Fields fields = new ProfileFields(
Arrays.asList(
createField("First Field"),
createField("Second Field")
)
);

boolean result = fields.equals(
new Fields(
new ProfileFields(
Arrays.asList(
createField("First Field")
)
Expand All @@ -82,15 +82,15 @@ void equals_rowSpecFieldsLengthNotEqualToOtherObjectFieldsLength_returnsFalse()

@Test
void equals_rowSpecFieldsLengthEqualToOterObjectFieldsLengthButValuesDiffer_returnsFalse() {
Fields fields = new Fields(
Fields fields = new ProfileFields(
Arrays.asList(
createField("First Field"),
createField("Second Field")
)
);

boolean result = fields.equals(
new Fields(
new ProfileFields(
Arrays.asList(
createField("First Field"),
createField("Third Field")
Expand All @@ -106,15 +106,15 @@ void equals_rowSpecFieldsLengthEqualToOterObjectFieldsLengthButValuesDiffer_retu

@Test
void equals_rowSpecFieldsAreEqualToTheFieldsOfTheOtherObject_returnsTrue() {
Fields fields = new Fields(
Fields fields = new ProfileFields(
Arrays.asList(
createField("First Field"),
createField("Second Field")
)
);

boolean result = fields.equals(
new Fields(
new ProfileFields(
Arrays.asList(
createField("First Field"),
createField("Second Field")
Expand All @@ -130,13 +130,13 @@ void equals_rowSpecFieldsAreEqualToTheFieldsOfTheOtherObject_returnsTrue() {

@Test
void hashCode_valuesinFieldsDifferInSize_returnsDifferentHashCodes() {
Fields firstFields = new Fields(
Fields firstFields = new ProfileFields(
Arrays.asList(
createField("First Field"),
createField("Second Field")
)
);
Fields secondFields = new Fields(
Fields secondFields = new ProfileFields(
Arrays.asList(
createField("First Field"),
createField("Second Field"),
Expand All @@ -156,13 +156,13 @@ void hashCode_valuesinFieldsDifferInSize_returnsDifferentHashCodes() {

@Test
void hashCode_valuesInFieldsAreEqualSizeButValuesDiffer_returnsDifferentHashCodes() {
Fields firstFields = new Fields(
Fields firstFields = new ProfileFields(
Arrays.asList(
createField("First Field"),
createField("Second Field")
)
);
Fields secondFields = new Fields(
Fields secondFields = new ProfileFields(
Arrays.asList(
createField("First Field"),
createField("Third Field")
Expand All @@ -181,13 +181,13 @@ void hashCode_valuesInFieldsAreEqualSizeButValuesDiffer_returnsDifferentHashCode

@Test
void hashCode_valuesInFieldsAreEqual_identicalHashCodesAreReturned() {
Fields firstFields = new Fields(
Fields firstFields = new ProfileFields(
Arrays.asList(
createField("First Field"),
createField("Second Field")
)
);
Fields secondFields = new Fields(
Fields secondFields = new ProfileFields(
Arrays.asList(
createField("First Field"),
createField("Second Field")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.scottlogic.datahelix.generator.common.profile.Field;
import com.scottlogic.datahelix.generator.common.profile.Fields;
import com.scottlogic.datahelix.generator.common.profile.ProfileFields;
import com.scottlogic.datahelix.generator.core.decisiontree.ConstraintNodeBuilder;
import com.scottlogic.datahelix.generator.core.decisiontree.DecisionNode;
import com.scottlogic.datahelix.generator.core.fieldspecs.relations.FieldSpecRelation;
Expand Down Expand Up @@ -88,12 +89,12 @@ public Stream<DecisionTree> splitTreeIntoPartitions(DecisionTree decisionTree) {
.addRelations(partition.getRelations())
.setDecisions(partition.getDecisionNodes())
.build(),
new Fields(new ArrayList<>(partition.fields))
new ProfileFields(new ArrayList<>(partition.fields))
)),
unpartitionedFields
.map(field -> new DecisionTree(
new ConstraintNodeBuilder().build(),
new Fields(Collections.singletonList(field))
new ProfileFields(Collections.singletonList(field))
))
);
}
Expand Down
Loading

0 comments on commit c441840

Please sign in to comment.