cdc.mf.checks.atts.cardinality.AbstractCardinalityLowerBoundMustBeAmong Maven / Gradle / Ivy
The newest version!
package cdc.mf.checks.atts.cardinality;
import java.util.List;
import cdc.issues.IssueSeverity;
import cdc.issues.checks.CheckContext;
import cdc.issues.checks.CheckResult;
import cdc.issues.checks.SnapshotManager;
import cdc.issues.locations.Location;
import cdc.issues.rules.Rule;
import cdc.issues.rules.RuleDescription;
import cdc.mf.checks.FormatUtils;
import cdc.mf.checks.IssueDescription;
import cdc.mf.checks.MfAbstractRuleChecker;
import cdc.mf.model.MfCardinality;
import cdc.mf.model.MfCardinalityItem;
public abstract class AbstractCardinalityLowerBoundMustBeAmong extends MfAbstractRuleChecker {
public static final IssueSeverity SEVERITY = IssueSeverity.MAJOR;
protected static String describe(String article,
String item,
List values) {
return RuleDescription.format("When the effective {%wrap} of {%lower}{%wrap} is valid, its {%wrap} must be "
+ FormatUtils.chooseBound(values) + ".",
N_CARDINALITY,
article,
item,
N_LOWER + WS + N_BOUND);
}
protected static String describe(String article,
String item,
int value) {
return describe(article, item, List.of(value));
}
private final List values;
protected AbstractCardinalityLowerBoundMustBeAmong(SnapshotManager manager,
Class objectClass,
Rule rule,
List values) {
super(manager,
objectClass,
rule);
this.values = List.copyOf(values);
}
protected AbstractCardinalityLowerBoundMustBeAmong(SnapshotManager manager,
Class objectClass,
Rule rule,
int value) {
this(manager,
objectClass,
rule,
List.of(value));
}
private boolean isOneOf(int value) {
return values.contains(value);
}
@Override
protected final String getHeader(O object) {
return getTheCardinalityOfHeader(object);
}
@Override
public CheckResult check(CheckContext context,
O object,
Location location) {
final MfCardinality cardinality = object.getEffectiveCardinality();
if (cardinality.isValid()
&& !isOneOf(cardinality.getMin())) {
final IssueDescription.Builder description = IssueDescription.builder();
description.header(getHeader(object))
.value(cardinality.getText())
.violation("is unexpected");
add(issue().description(description)
.location(location)
.build());
return CheckResult.FAILURE;
} else {
return CheckResult.SUCCESS;
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy