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

Commit

Permalink
Merge pull request #1030 from ScottLogic/update-fieldspec-tostring
Browse files Browse the repository at this point in the history
update fieldspec toStrings to help debugging.
  • Loading branch information
pdaulbyscottlogic authored Jun 11, 2019
2 parents 41d1e7b + d3080b2 commit 6288cce
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,13 @@ public String toString() {
.filter(Objects::nonNull)
.map(Object::toString)
.collect(Collectors.toList());

if (!nullable){
propertyStrings.add(0, "Not Null");
}

if (propertyStrings.isEmpty()) {
return "<empty>";
return "<all values>";
}

return String.join(" & ", propertyStrings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public BlacklistRestrictions(Set<Object> blacklist) {
}

public Set<Object> getBlacklist() {
return this.blacklist;
return blacklist;
}

@Override
Expand All @@ -22,4 +22,9 @@ public boolean match(Object o) {
public boolean isInstanceOf(Object o) {
return true;
}

@Override
public String toString() {
return String.format("NOT %s", blacklist);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ public Timescale getGranularity() {
return granularity;
}

@Override
public String toString() {
return "min=" + min + ", max=" + max + " " + granularity.name();
}

@Override
protected IsOfTypeConstraint.Types getType() {
Expand Down Expand Up @@ -76,6 +80,12 @@ public int hashCode() {

public static class DateTimeLimit {
private final OffsetDateTime limit;

@Override
public String toString() {
return String.format("%s%s",limit, inclusive ? " inclusive" : "");
}

private final boolean inclusive;

public DateTimeLimit(OffsetDateTime limit, boolean inclusive) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,12 @@ private int getCodeLength(StandardConstraintTypes type) {
throw new UnsupportedOperationException(String.format("Unable to check string restrictions for: %s", type));
}
}

@Override
public String toString() {
if (negated){
return "not " + type.name();
}
return type.name();
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package com.scottlogic.deg.generator.restrictions;

import com.scottlogic.deg.generator.utils.SetUtils;
import org.jetbrains.annotations.NotNull;

import java.util.Collections;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;

public class SetRestrictions implements Restrictions {
private static final SetRestrictions neutral = new SetRestrictions(null);

@NotNull
private final Set<Object> whitelist;

public Set<Object> getWhitelist() {
Expand All @@ -21,24 +18,20 @@ public SetRestrictions(Set<Object> whitelist) {
this.whitelist = whitelist;
}

private boolean isEmpty(){
return (this.whitelist == null || this.whitelist.isEmpty());
}

public static SetRestrictions allowNoValues() {
return fromWhitelist(Collections.emptySet());
}

public static SetRestrictions fromWhitelist(@NotNull Set<Object> whitelist) {
public static SetRestrictions fromWhitelist(Set<Object> whitelist) {
return new SetRestrictions(whitelist);
}

@Override
public String toString() {
if (isEmpty()) {
return "<empty>";
if (whitelist.isEmpty()) {
return "<No Values>";
}
return String.format("IN %s", Objects.toString(whitelist));
return String.format("IN %s", whitelist);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,14 +316,14 @@ private String restrictStringLength(int min, Integer max){

@Override
public String toString() {
return String.format("Strings: %d..%s (not: %s)\nmatching: %s\ncontaining: %s\nnotMatching: %s\nnotContaining: %s",
return String.format("Strings: %d..%s%s%s%s%s%s",
minLength != null ? minLength : 0,
maxLength != null ? maxLength.toString() : "",
excludedLengths.toString(),
patternsAsString(matchingRegex),
patternsAsString(containingRegex),
patternsAsString(notMatchingRegex),
patternsAsString(notContainingRegex));
excludedLengths.isEmpty() ? "" : " not lengths " + excludedLengths,
matchingRegex.isEmpty() ? "" : " matching: " + patternsAsString(matchingRegex),
containingRegex.isEmpty() ? "" : " containing: " + patternsAsString(containingRegex),
notMatchingRegex.isEmpty() ? "" : " not matching: " + patternsAsString(notMatchingRegex),
notContainingRegex.isEmpty() ? "" : " not containing: " + patternsAsString(notContainingRegex));
}

private String patternsAsString(Set<Pattern> patterns) {
Expand Down

0 comments on commit 6288cce

Please sign in to comment.