Skip to content
Snippets Groups Projects
Commit ba7f4b24 authored by Jonas Blatt's avatar Jonas Blatt :ant:
Browse files

Merge branch 'feature-string-creater' into develop

parents 8a10164f d5299908
No related branches found
No related tags found
No related merge requests found
...@@ -32,11 +32,16 @@ public class BiCreaterStringIntersection extends AbstractBoundaryBiCreater<Strin ...@@ -32,11 +32,16 @@ public class BiCreaterStringIntersection extends AbstractBoundaryBiCreater<Strin
if (b1.checkWith(IS_NOT_IN_CONTACT, b2)) { if (b1.checkWith(IS_NOT_IN_CONTACT, b2)) {
return Optional.empty(); return Optional.empty();
} }
if (b1.matchesAny() && b2.matchesAny() if (b1.matchesAny() && b2.matchesAny()) {
|| b1.matchesAny() && !b2.matchesNoneOfValues()
|| b2.matchesAny() && !b1.matchesNoneOfValues()) {
return Optional.of(StringBoundary.getBuilder().matchesAny(true).build()); return Optional.of(StringBoundary.getBuilder().matchesAny(true).build());
} }
if (b1.matchesAny() && !b2.matchesNoneOfValues()
|| b2.matchesAny() && !b1.matchesNoneOfValues()) {
return Optional.of(
StringBoundary.getBuilder()
.addValues(b1.matchesAny() ? b2.getValues() : b1.getValues())
.build());
}
if (b1.matchesAny() && b2.matchesNoneOfValues()) { if (b1.matchesAny() && b2.matchesNoneOfValues()) {
return Optional.of( return Optional.of(
StringBoundary.getBuilder().matchesNoneOfValues(true).addValues(b2.getValues()).build()); StringBoundary.getBuilder().matchesNoneOfValues(true).addValues(b2.getValues()).build());
...@@ -76,15 +81,11 @@ public class BiCreaterStringIntersection extends AbstractBoundaryBiCreater<Strin ...@@ -76,15 +81,11 @@ public class BiCreaterStringIntersection extends AbstractBoundaryBiCreater<Strin
} }
if (b1.matchesNoneOfValues()) { if (b1.matchesNoneOfValues()) {
return Optional.of( return Optional.of(
StringBoundary.getBuilder() StringBoundary.getBuilder().addValues(getIntersectionStrings(b2, b1)).build());
.addValues(getIntersectionStrings(b2, b1))
.build());
} }
if (b2.matchesNoneOfValues()) { if (b2.matchesNoneOfValues()) {
return Optional.of( return Optional.of(
StringBoundary.getBuilder() StringBoundary.getBuilder().addValues(getIntersectionStrings(b1, b2)).build());
.addValues(getIntersectionStrings(b1, b2))
.build());
} }
return Optional.empty(); return Optional.empty();
} }
......
package de.unikoblenz.fgbks.base.utils.boundary.bicreater; package de.unikoblenz.fgbks.base.utils.boundary.bicreater;
import static de.unikoblenz.fgbks.base.utils.boundary.checker.BoundaryCheckType.IS_EQUAL;
import static de.unikoblenz.fgbks.base.utils.boundary.checker.BoundaryCheckType.IS_NOT_IN_CONTACT;
import de.unikoblenz.fgbks.base.utils.boundary.impl.StringBoundary; import de.unikoblenz.fgbks.base.utils.boundary.impl.StringBoundary;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Optional; import java.util.Optional;
import java.util.Set;
public class BiCreaterStringLowerBounds extends AbstractBoundaryBiCreater<StringBoundary> { public class BiCreaterStringLowerBounds extends AbstractBoundaryBiCreater<StringBoundary> {
...@@ -22,8 +28,19 @@ public class BiCreaterStringLowerBounds extends AbstractBoundaryBiCreater<String ...@@ -22,8 +28,19 @@ public class BiCreaterStringLowerBounds extends AbstractBoundaryBiCreater<String
@Override @Override
public Optional<StringBoundary> create(StringBoundary b1, StringBoundary b2) { public Optional<StringBoundary> create(StringBoundary b1, StringBoundary b2) {
// Not supported for String Boundary if (b1.checkWith(IS_NOT_IN_CONTACT, b2) || b1.checkWith(IS_EQUAL, b2)) {
// Check BiCreaterStringBetween. return Optional.empty();
return Optional.empty(); }
if (b1.matchesAny() || b1.matchesNoneOfValues()) {
return Optional.of(
StringBoundary.getBuilder()
.addValues(b1.getValues())
.addValues(b2.getValues())
.matchesNoneOfValues(!b2.matchesNoneOfValues())
.build());
}
Set<String> values = new HashSet<>(Arrays.asList(b1.getValues()));
values.removeAll(Arrays.asList(b2.getValues()));
return Optional.of(StringBoundary.getBuilder().addValues(values).build());
} }
} }
...@@ -44,13 +44,29 @@ public class CheckStringInContact extends AbstractBoundaryCheck<StringBoundary> ...@@ -44,13 +44,29 @@ public class CheckStringInContact extends AbstractBoundaryCheck<StringBoundary>
return false; return false;
} }
// one is matching non values "not("a")" // one is matching non values "not("a")"
if (b1h.length != b2h.length) { if (b1.matchesNoneOfValues()) {
return true; outer:
for (int i : b2h) {
for (int u : b1h) {
if (i == u) {
continue outer;
}
}
return true;
}
return false;
} }
for (int i = 0; i < b1h.length; i++) { if (b2.matchesNoneOfValues()) {
if (b1h[i] != b2h[i]) { outer:
for (int i : b1h) {
for (int u : b2h) {
if (i == u) {
continue outer;
}
}
return true; return true;
} }
return false;
} }
return false; return false;
} }
......
...@@ -100,12 +100,19 @@ public class MissingRuleVerifier extends AbstractVerifier { ...@@ -100,12 +100,19 @@ public class MissingRuleVerifier extends AbstractVerifier {
List<VDmnRuleChangeableImpl> missingRules) { List<VDmnRuleChangeableImpl> missingRules) {
// search the missing rules, which are in contact with the current rule // search the missing rules, which are in contact with the current rule
List<VDmnRuleChangeableImpl> inContactRules = new LinkedList<>(); List<VDmnRuleChangeableImpl> inContactRules = new LinkedList<>();
List<VDmnRuleChangeableImpl> inEqualRules = new LinkedList<>();
for (VDmnRuleChangeableImpl missingRule : missingRules) { for (VDmnRuleChangeableImpl missingRule : missingRules) {
if (isInContact(missingRule, currentRule)) { if (isInContact(missingRule, currentRule)) {
inContactRules.add(missingRule); // dont add equal rules
if (isEqualRule(missingRule, currentRule)) {
inEqualRules.add(missingRule);
} else {
inContactRules.add(missingRule);
}
} }
} }
// remove found rules from current missingRules // remove found rules from current missingRules
missingRules.removeAll(inEqualRules);
missingRules.removeAll(inContactRules); missingRules.removeAll(inContactRules);
// Build new missing rules from in contact rules // Build new missing rules from in contact rules
List<VDmnRuleChangeableImpl> newMissingRules = new LinkedList<>(); List<VDmnRuleChangeableImpl> newMissingRules = new LinkedList<>();
...@@ -114,7 +121,21 @@ public class MissingRuleVerifier extends AbstractVerifier { ...@@ -114,7 +121,21 @@ public class MissingRuleVerifier extends AbstractVerifier {
} }
// mergeRules(newMissingRules); // mergeRules(newMissingRules);
missingRules.addAll(newMissingRules); missingRules.addAll(newMissingRules);
mergeRules(missingRules); // mergeRules(missingRules);
}
private boolean isEqualRule(VDmnRule missingRule, VDmnRule currentRule) {
List<VDmnInputValue> inValsMissingRule = missingRule.getDmnInputValues();
List<VDmnInputValue> inValsCurrentRule = currentRule.getDmnInputValues();
for (int i = 0; i < inValsMissingRule.size(); i++) {
if (!inValsMissingRule
.get(i)
.getBoundary()
.checkWith(BoundaryCheckType.IS_EQUAL, inValsCurrentRule.get(i).getBoundary())) {
return false;
}
}
return true;
} }
private List<VDmnRuleChangeableImpl> constructNewMissingRules( private List<VDmnRuleChangeableImpl> constructNewMissingRules(
......
...@@ -39,16 +39,16 @@ class BiCreaterStringIntersectionTest { ...@@ -39,16 +39,16 @@ class BiCreaterStringIntersectionTest {
sb1 = StringBoundary.getBuilder().matchesAny(true).build(); sb1 = StringBoundary.getBuilder().matchesAny(true).build();
sb2 = StringBoundary.getBuilder().addValue("a").build(); sb2 = StringBoundary.getBuilder().addValue("a").build();
sbR = (StringBoundary) sb1.createBi(INTERSECTION, sb2).get(); sbR = (StringBoundary) sb1.createBi(INTERSECTION, sb2).get();
assertArrayEquals(new String[]{}, sbR.getValues()); assertArrayEquals(new String[]{"a"}, sbR.getValues());
assertFalse(sbR.matchesNoneOfValues()); assertFalse(sbR.matchesNoneOfValues());
assertTrue(sbR.matchesAny()); assertFalse(sbR.matchesAny());
sb1 = StringBoundary.getBuilder().addValue("a").build(); sb1 = StringBoundary.getBuilder().addValue("a").build();
sb2 = StringBoundary.getBuilder().matchesAny(true).build(); sb2 = StringBoundary.getBuilder().matchesAny(true).build();
sbR = (StringBoundary) sb1.createBi(INTERSECTION, sb2).get(); sbR = (StringBoundary) sb1.createBi(INTERSECTION, sb2).get();
assertArrayEquals(new String[]{}, sbR.getValues()); assertArrayEquals(new String[]{"a"}, sbR.getValues());
assertFalse(sbR.matchesNoneOfValues()); assertFalse(sbR.matchesNoneOfValues());
assertTrue(sbR.matchesAny()); assertFalse(sbR.matchesAny());
sb1 = StringBoundary.getBuilder().matchesAny(true).build(); sb1 = StringBoundary.getBuilder().matchesAny(true).build();
sb2 = StringBoundary.getBuilder().matchesNoneOfValues(true).addValue("a").build(); sb2 = StringBoundary.getBuilder().matchesNoneOfValues(true).addValue("a").build();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment