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
if (b1.checkWith(IS_NOT_IN_CONTACT, b2)) {
return Optional.empty();
}
if (b1.matchesAny() && b2.matchesAny()
|| b1.matchesAny() && !b2.matchesNoneOfValues()
|| b2.matchesAny() && !b1.matchesNoneOfValues()) {
if (b1.matchesAny() && b2.matchesAny()) {
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()) {
return Optional.of(
StringBoundary.getBuilder().matchesNoneOfValues(true).addValues(b2.getValues()).build());
......@@ -76,15 +81,11 @@ public class BiCreaterStringIntersection extends AbstractBoundaryBiCreater<Strin
}
if (b1.matchesNoneOfValues()) {
return Optional.of(
StringBoundary.getBuilder()
.addValues(getIntersectionStrings(b2, b1))
.build());
StringBoundary.getBuilder().addValues(getIntersectionStrings(b2, b1)).build());
}
if (b2.matchesNoneOfValues()) {
return Optional.of(
StringBoundary.getBuilder()
.addValues(getIntersectionStrings(b1, b2))
.build());
StringBoundary.getBuilder().addValues(getIntersectionStrings(b1, b2)).build());
}
return Optional.empty();
}
......
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 java.util.Arrays;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
public class BiCreaterStringLowerBounds extends AbstractBoundaryBiCreater<StringBoundary> {
......@@ -22,8 +28,19 @@ public class BiCreaterStringLowerBounds extends AbstractBoundaryBiCreater<String
@Override
public Optional<StringBoundary> create(StringBoundary b1, StringBoundary b2) {
// Not supported for String Boundary
// Check BiCreaterStringBetween.
return Optional.empty();
if (b1.checkWith(IS_NOT_IN_CONTACT, b2) || b1.checkWith(IS_EQUAL, b2)) {
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>
return false;
}
// one is matching non values "not("a")"
if (b1h.length != b2h.length) {
return true;
if (b1.matchesNoneOfValues()) {
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 (b1h[i] != b2h[i]) {
if (b2.matchesNoneOfValues()) {
outer:
for (int i : b1h) {
for (int u : b2h) {
if (i == u) {
continue outer;
}
}
return true;
}
return false;
}
return false;
}
......
......@@ -100,12 +100,19 @@ public class MissingRuleVerifier extends AbstractVerifier {
List<VDmnRuleChangeableImpl> missingRules) {
// search the missing rules, which are in contact with the current rule
List<VDmnRuleChangeableImpl> inContactRules = new LinkedList<>();
List<VDmnRuleChangeableImpl> inEqualRules = new LinkedList<>();
for (VDmnRuleChangeableImpl missingRule : missingRules) {
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
missingRules.removeAll(inEqualRules);
missingRules.removeAll(inContactRules);
// Build new missing rules from in contact rules
List<VDmnRuleChangeableImpl> newMissingRules = new LinkedList<>();
......@@ -114,7 +121,21 @@ public class MissingRuleVerifier extends AbstractVerifier {
}
// mergeRules(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(
......
......@@ -39,16 +39,16 @@ class BiCreaterStringIntersectionTest {
sb1 = StringBoundary.getBuilder().matchesAny(true).build();
sb2 = StringBoundary.getBuilder().addValue("a").build();
sbR = (StringBoundary) sb1.createBi(INTERSECTION, sb2).get();
assertArrayEquals(new String[]{}, sbR.getValues());
assertArrayEquals(new String[]{"a"}, sbR.getValues());
assertFalse(sbR.matchesNoneOfValues());
assertTrue(sbR.matchesAny());
assertFalse(sbR.matchesAny());
sb1 = StringBoundary.getBuilder().addValue("a").build();
sb2 = StringBoundary.getBuilder().matchesAny(true).build();
sbR = (StringBoundary) sb1.createBi(INTERSECTION, sb2).get();
assertArrayEquals(new String[]{}, sbR.getValues());
assertArrayEquals(new String[]{"a"}, sbR.getValues());
assertFalse(sbR.matchesNoneOfValues());
assertTrue(sbR.matchesAny());
assertFalse(sbR.matchesAny());
sb1 = StringBoundary.getBuilder().matchesAny(true).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