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 #1404 from finos/paul/refactor/packages
Browse files Browse the repository at this point in the history
Replace FieldSpecFactory with polymorphism
  • Loading branch information
pdaulbyscottlogic authored Oct 3, 2019
2 parents b9f7238 + 62114f6 commit 81d1ebd
Show file tree
Hide file tree
Showing 134 changed files with 1,005 additions and 916 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,6 @@

package com.scottlogic.deg.common.profile.constraints;

import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.scottlogic.deg.common.profile.constraints.atomic.*;
import com.scottlogic.deg.common.profile.RuleInformation;

import java.util.Set;
/*
* The following JsonTypeInfo is needed for the utility program GenTreeJson.java
* (invoked via the mode of `genTreeJson`), which produces a JSON for the decision
* tree in memory.
*/
@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
property = "type"
)
@JsonSubTypes({
@JsonSubTypes.Type(value = IsInSetConstraint.class, name = "IsInSetConstraint"),
@JsonSubTypes.Type(value = IsStringShorterThanConstraint.class, name = "IsStringShorterThanConstraint"),
@JsonSubTypes.Type(value = NotConstraint.class, name = "NotConstraint"),
@JsonSubTypes.Type(value = IsNullConstraint.class, name = "IsNullConstraint"),
@JsonSubTypes.Type(value = IsLessThanConstantConstraint.class, name = "IsLessThanConstantConstraint")
})
public interface Constraint
{
Constraint negate();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,7 @@ public int hashCode() {

@Override
public String toString() {
return "DistributedSet{" +
"underlyingWeights=" + underlyingWeights +
'}';
return list().toString();
}

public Stream<T> stream() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@

package com.scottlogic.deg.generator.decisiontree;

import com.scottlogic.deg.common.profile.constraints.atomic.AtomicConstraint;
import com.scottlogic.deg.common.profile.constraints.delayed.DelayedAtomicConstraint;
import com.scottlogic.deg.generator.profile.constraints.atomic.AtomicConstraint;
import com.scottlogic.deg.generator.profile.constraints.delayed.DelayedAtomicConstraint;
import com.scottlogic.deg.generator.fieldspecs.RowSpec;

import java.util.*;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class ConstraintNode implements Node {
private final Collection<AtomicConstraint> atomicConstraints;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.scottlogic.deg.generator.decisiontree;

import com.scottlogic.deg.common.profile.constraints.atomic.AtomicConstraint;
import com.scottlogic.deg.common.profile.constraints.delayed.DelayedAtomicConstraint;
import com.scottlogic.deg.generator.profile.constraints.atomic.AtomicConstraint;
import com.scottlogic.deg.generator.profile.constraints.delayed.DelayedAtomicConstraint;
import com.scottlogic.deg.common.util.FlatMappingSpliterator;

import java.util.Arrays;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@

package com.scottlogic.deg.generator.decisiontree;

import com.scottlogic.deg.common.profile.Profile;
import com.scottlogic.deg.common.profile.Rule;
import com.scottlogic.deg.common.profile.constraints.Constraint;
import com.scottlogic.deg.common.profile.constraints.atomic.AtomicConstraint;
import com.scottlogic.deg.common.profile.constraints.delayed.DelayedAtomicConstraint;
import com.scottlogic.deg.common.profile.constraints.grammatical.AndConstraint;
import com.scottlogic.deg.common.profile.constraints.grammatical.ConditionalConstraint;
import com.scottlogic.deg.common.profile.constraints.grammatical.NegatedGrammaticalConstraint;
import com.scottlogic.deg.common.profile.constraints.grammatical.OrConstraint;
import com.scottlogic.deg.generator.profile.Profile;
import com.scottlogic.deg.generator.profile.Rule;
import com.scottlogic.deg.generator.profile.constraints.Constraint;
import com.scottlogic.deg.generator.profile.constraints.atomic.AtomicConstraint;
import com.scottlogic.deg.generator.profile.constraints.delayed.DelayedAtomicConstraint;
import com.scottlogic.deg.generator.profile.constraints.grammatical.AndConstraint;
import com.scottlogic.deg.generator.profile.constraints.grammatical.ConditionalConstraint;
import com.scottlogic.deg.generator.profile.constraints.grammatical.NegatedGrammaticalConstraint;
import com.scottlogic.deg.generator.profile.constraints.grammatical.OrConstraint;

import java.util.Collection;
import java.util.Collections;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@

package com.scottlogic.deg.generator.decisiontree;

import com.scottlogic.deg.common.profile.constraints.atomic.AtomicConstraint;
import com.scottlogic.deg.common.profile.constraints.atomic.NotConstraint;
import com.scottlogic.deg.generator.profile.constraints.atomic.AtomicConstraint;

import java.util.*;
import java.util.function.Function;
Expand Down Expand Up @@ -113,10 +112,6 @@ private ConstraintNode addOptionsAsDecisionUnderConstraintNode(
return newNode.builder().addDecision(new DecisionNode(optionsToAdd)).build();
}

private int disfavourNotConstraints(Map.Entry<AtomicConstraint, List<AtomicConstraint>> entry){
return entry.getKey() instanceof NotConstraint ? 1 : 0;
}

private AtomicConstraint getMostProlificAtomicConstraint(Collection<DecisionNode> decisions) {
Map<AtomicConstraint, List<AtomicConstraint>> decisionConstraints =
decisions.stream()
Expand All @@ -127,7 +122,6 @@ private AtomicConstraint getMostProlificAtomicConstraint(Collection<DecisionNode
Comparator<Map.Entry<AtomicConstraint, List<AtomicConstraint>>> comparator = Comparator
.comparing(entry -> entry.getValue().size());
comparator = comparator.reversed()
.thenComparing(this::disfavourNotConstraints)
.thenComparing(entry -> entry.getKey().toString());

return decisionConstraints.entrySet()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

package com.scottlogic.deg.generator.decisiontree.treepartitioning;

import com.scottlogic.deg.common.profile.constraints.atomic.AtomicConstraint;
import com.scottlogic.deg.common.profile.constraints.delayed.DelayedAtomicConstraint;
import com.scottlogic.deg.generator.profile.constraints.atomic.AtomicConstraint;
import com.scottlogic.deg.generator.profile.constraints.delayed.DelayedAtomicConstraint;
import com.scottlogic.deg.generator.decisiontree.DecisionNode;

import java.util.Objects;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

import com.scottlogic.deg.common.profile.Field;
import com.scottlogic.deg.common.profile.ProfileFields;
import com.scottlogic.deg.common.profile.constraints.atomic.AtomicConstraint;
import com.scottlogic.deg.common.profile.constraints.delayed.DelayedAtomicConstraint;
import com.scottlogic.deg.generator.profile.constraints.atomic.AtomicConstraint;
import com.scottlogic.deg.generator.profile.constraints.delayed.DelayedAtomicConstraint;
import com.scottlogic.deg.common.util.FlatMappingSpliterator;
import com.scottlogic.deg.generator.decisiontree.ConstraintNodeBuilder;
import com.scottlogic.deg.generator.decisiontree.DecisionNode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.scottlogic.deg.generator.decisiontree.visualisation;

import com.scottlogic.deg.common.profile.constraints.atomic.AtomicConstraint;
import com.scottlogic.deg.generator.profile.constraints.atomic.AtomicConstraint;
import com.scottlogic.deg.generator.decisiontree.*;

import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@

package com.scottlogic.deg.generator.fieldspecs;

import com.scottlogic.deg.common.profile.constraints.delayed.*;
import com.scottlogic.deg.generator.fieldspecs.relations.*;
import com.scottlogic.deg.generator.profile.constraints.delayed.DelayedAtomicConstraint;
import com.scottlogic.deg.generator.profile.constraints.delayed.DelayedDateAtomicConstraint;

public class FieldRelationsFactory {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public String toString() {
if (whitelist.isEmpty()) {
return "Null only";
}
return (nullable ? "" : "Not Null") + String.format("IN %s", whitelist);
return (nullable ? "" : "Not Null ") + String.format("IN %s", whitelist);
}

return String.format("%s%s",
Expand Down
Loading

0 comments on commit 81d1ebd

Please sign in to comment.