All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cdc.mf.checks.MfAbstractRuleChecker Maven / Gradle / Ivy

The newest version!
package cdc.mf.checks;

import java.util.Collection;
import java.util.List;

import cdc.issues.checks.AbstractRuleChecker;
import cdc.issues.checks.SnapshotManager;
import cdc.issues.rules.Rule;
import cdc.issues.rules.RuleDescription;
import cdc.mf.model.MfCardinalityItem;
import cdc.mf.model.MfConnector;
import cdc.mf.model.MfDocumentation;
import cdc.mf.model.MfElement;
import cdc.mf.model.MfNameItem;
import cdc.mf.model.MfTip;
import cdc.mf.model.MfTipRole;
import cdc.mf.model.MfUtils;

/**
 * Abstract leaf ({@link Rule}) checker.
 *
 * @author Damien Carbonne
 *
 * @param  The item type.
 */
public abstract class MfAbstractRuleChecker extends AbstractRuleChecker {
    protected static final String WS = " ";
    protected static final String DASH = "-";
    protected static final String DOT = ".";
    protected static final String S = "s";
    protected static final String ES = "es";

    protected static final String A = RuleDescription.A;
    protected static final String ALL = RuleDescription.ALL;
    protected static final String AN = RuleDescription.AN;
    protected static final String ANY = RuleDescription.ANY;
    protected static final String SOME = RuleDescription.SOME;
    protected static final String THE = RuleDescription.THE;

    protected static final String N_ABSTRACT = "abstract";
    protected static final String N_AGGREGATION = "aggregation";
    protected static final String N_ASSOCIATION = "association";
    protected static final String N_ATTRIBUTE = "attribute";
    protected static final String N_BOUND = "bound";
    protected static final String N_CARDINALITIES = "cardinalities";
    protected static final String N_CARDINALITY = "cardinality";
    protected static final String N_CLASS = "class";
    protected static final String N_COMPOSITION = "composition";
    protected static final String N_CONCRETE = "concrete";
    protected static final String N_CONNECTOR = "connector";
    protected static final String N_DIRECTED = "directed";
    protected static final String N_DOCUMENTATION = "documentation";
    protected static final String N_GENERALIZATION = "generalization";
    protected static final String N_GENERALIZED = "generalized";
    protected static final String N_ID = "id";
    protected static final String N_IMPLEMENTATION = "implementation";
    protected static final String N_INTERFACE = "interface";
    protected static final String N_KEY = "key";
    protected static final String N_LOWER = "lower";
    protected static final String N_MODEL = "model";
    protected static final String N_NAME = "name";
    protected static final String N_NOTES = "notes";
    protected static final String N_PACKAGE = "package";
    protected static final String N_PART = "part";
    protected static final String N_ROLE = "role";
    protected static final String N_SIBLING = "sibling";
    protected static final String N_SOURCE = "source";
    protected static final String N_SPECIALIZED = "specialized";
    protected static final String N_STEREOTYPE = "stereotype";
    protected static final String N_TAG = "tag";
    protected static final String N_TARGET = "target";
    protected static final String N_TIP = "tip";
    protected static final String N_TEXT = "text";
    protected static final String N_TYPE = "type";
    protected static final String N_UPPER = "upper";
    protected static final String N_VALUE = "value";
    protected static final String N_VISIBILITY = "visibility";
    protected static final String N_WHOLE = "whole";

    protected static final String THE_CARDINALITY_OF = RuleDescription.wrap(RuleDescription.THE, true, N_CARDINALITY) + " of ";
    protected static final String THE_NAME_OF = RuleDescription.wrap(RuleDescription.THE, true, N_NAME) + " of ";
    protected static final String THE_NOTES_OF = RuleDescription.wrap(THE, true, N_NOTES) + " of ";
    protected static final String THE_ROLE_OF = RuleDescription.wrap(RuleDescription.THE, true, N_ROLE) + " of ";
    protected static final String SOME_STEREOTYPES_OF = RuleDescription.wrap(RuleDescription.SOME, true, N_STEREOTYPE + S) + " of ";
    protected static final String THE_STEREOTYPES_OF = RuleDescription.wrap(RuleDescription.THE, true, N_STEREOTYPE + S) + " of ";
    protected static final String THE_TEXT_OF = RuleDescription.wrap(RuleDescription.THE, true, N_TEXT) + " of ";
    protected static final String THE_TYPE_OF = RuleDescription.wrap(RuleDescription.THE, true, N_TYPE) + " of ";
    protected static final String THE_VALUE_OF = RuleDescription.wrap(RuleDescription.THE, true, N_VALUE) + " of ";

    protected MfAbstractRuleChecker(SnapshotManager manager,
                                    Class objectClass,
                                    Rule rule) {
        super(manager,
              objectClass,
              rule);
    }

    protected static List sortUsingId(Collection elements) {
        return elements.stream()
                       .sorted(MfElement.ID_COMPARATOR)
                       .map(MfElement.class::cast)
                       .toList();
    }

    private static String getHeader(String prefix,
                                    MfElement object) {
        return prefix == null ? MfUtils.identify(object) : prefix + MfUtils.identify(object);
    }

    protected static String getTheItemHeader(MfElement item) {
        return getHeader("The ", item);
    }

    protected static String getTheCardinalityOfHeader(MfCardinalityItem object) {
        return getHeader(THE_CARDINALITY_OF, object);
    }

    protected static String getTheNameOfHeader(MfNameItem object) {
        return getHeader(THE_NAME_OF, object);
    }

    public static String getTheNotesOfHeader(MfElement object) {
        return getHeader(THE_NOTES_OF, object);
    }

    protected static String getTheRoleOfHeader(MfElement object) {
        return getHeader(THE_ROLE_OF, object);
    }

    protected static String getSomeStereotypesOfHeader(MfElement object) {
        return getHeader(SOME_STEREOTYPES_OF, object);
    }

    protected static String getTheStereotypesOfHeader(MfElement object) {
        return getHeader(THE_STEREOTYPES_OF, object);
    }

    protected static String getTheTextOfHeader(MfDocumentation object) {
        return getHeader(THE_TEXT_OF, object);
    }

    protected static String getTheTipOfHeader(MfConnector item,
                                              MfTipRole role) {
        final MfTip tip = item.getTip(role);
        return getTheItemHeader(tip);
    }

    protected static String getTheTypeOfHeader(MfElement object) {
        return getHeader(THE_TYPE_OF, object);
    }

    protected static String getTheValueOfHeader(MfElement object) {
        return getHeader(THE_VALUE_OF, object);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy