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

com.nedap.archie.aom.primitives.COrdered Maven / Gradle / Ivy

package com.nedap.archie.aom.primitives;

import com.nedap.archie.aom.CObject;
import com.nedap.archie.aom.CPrimitiveObject;
import com.nedap.archie.aom.utils.ConformanceCheckResult;
import com.nedap.archie.archetypevalidator.ErrorType;
import com.nedap.archie.base.Interval;
import com.nedap.archie.rminfo.ModelInfoLookup;
import org.openehr.utils.message.I18n;

import java.util.function.BiFunction;

/**
 * Created by pieter.bos on 15/10/15.
 */
public abstract class COrdered extends CPrimitiveObject, T> {

    @Override
    public boolean isValidValue(T value) {
        if(getConstraint().isEmpty()) {
            return true;
        }
        for(Interval constraint:getConstraint()) {
            if(constraint.has(value)) {
                return true;
            }
        }
        return false;
    }

    @Override
    public ConformanceCheckResult cConformsTo(CObject other, BiFunction rmTypesConformant) {
        ConformanceCheckResult superResult = super.cConformsTo(other, rmTypesConformant);
        if (!superResult.doesConform()) {
            return superResult;
        }
        //now guaranteed to be the same class

        @SuppressWarnings("unchecked")
        COrdered otherOrdered = (COrdered) other;
        if(otherOrdered.getConstraint().isEmpty()) {
            return ConformanceCheckResult.conforms();
        }


        for(Interval constraint:getConstraint()) {
            boolean found = false;
            for(Interval otherConstraint:otherOrdered.getConstraint()) {
                if(otherConstraint.contains(constraint)) {
                    found = true;
                    break;
                }
            }
            if(!found) {
                return ConformanceCheckResult.fails(ErrorType.VPOV, I18n.t("Parent constraint contains no interval that fully contains {0}", constraint));
            }
        }
        return ConformanceCheckResult.conforms();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy