private void validate()

in SdmxBeans/src/main/java/org/sdmxsource/sdmx/sdmxbeans/model/beans/base/TextFormatBeanImpl.java [285:352]


    private void validate() throws SdmxSemmanticException {
        if (minLength != null) {
            if (minLength.intValue() == 0) {
                LOG.warn("Text format of 0 converted to 1");
                minLength = BigInteger.ONE;
            } else if (minLength.intValue() < 0) {
                throw new SdmxSemmanticException("Invalid Text Format, min length must be a positive integer - got " + minLength.intValue());
            }
        }
        if (maxLength != null) {
            if (maxLength.intValue() <= 0) {
                throw new SdmxSemmanticException("Invalid Text Format, max length must be a positive integer - got " + maxLength.intValue());
            }
        }
        if (minLength != null && maxLength != null) {
            if (minLength.compareTo(maxLength) > 0) {
                throw new SdmxSemmanticException("Invalid Text Format, min length can not be greater then max length");
            }
        }
        if (minValue != null && maxValue != null) {
            if (minValue.compareTo(maxValue) > 0) {
                throw new SdmxSemmanticException("Invalid Text Format, min value can not be greater then max value");
            }
        }
        if (decimals != null) {
            if (decimals.intValue() <= 0) {
                throw new SdmxSemmanticException("Invalid Text Format, decimals must be a positive integer - got " + decimals.intValue());
            }
        }
        if (startTime != null && endTime != null) {
            if (startTime.isLater(endTime)) {
                throw new SdmxSemmanticException("Invalid Text Format, start time can not be after end time");
            }
        }
        if (isSequence.isTrue()) {
            if (timeInterval == null && interval == null) {
                throw new SdmxSemmanticException("Invalid Text Format, time interval or interval must be set if isSequence is set to true");
            }
            if (ObjectUtil.validString(timeInterval) && startTime == null) {
                throw new SdmxSemmanticException("Invalid Text Format, start time must be set if time interval is set");
            }
            if (interval != null && startValue == null) {
                throw new SdmxSemmanticException("Invalid Text Format, start value must be set if interval is set");
            }
        } else {
            if (ObjectUtil.validString(timeInterval)) {
                throw new SdmxSemmanticException("Invalid Text Format, time interval can only be set if isSequence is set to true");
            }
            if (startTime != null) {
                throw new SdmxSemmanticException("Invalid Text Format, start time can only be set if isSequence is set to true");
            }
            if (interval != null) {
                throw new SdmxSemmanticException("Invalid Text Format, interval can only be set if isSequence is set to true");
            }
            if (startValue != null) {
                throw new SdmxSemmanticException("Invalid Text Format, start value can only be set if isSequence is set to true");
            }
        }
        if (ObjectUtil.validString(timeInterval)) {
            //Validate that the time interval matches the allowed xs:duration format PnYnMnDTnHnMnS - Use the RegEx, and make sure the string
            //is greater then length 1, as the regex does not ensure that there is any content after the P
            //The Regex ensures if there is anything after the P, it is of the valid type, example P5Y and P91DT12M are both valid formats
            Pattern timeIntervalPattern = Pattern.compile("P(([0-9]+Y)?([0-9]+M)?([0-9]+D)?)(T([0-9]+H)?([0-9]+M)?([0-9]+S)?)?");
            if (timeInterval.length() == 1 || !timeIntervalPattern.matcher(timeInterval).matches()) {
                throw new SdmxSemmanticException("Invalid time interval, pattern must be PnYnMnDTnHnMnS, where n=positive integer, and each section is optional after each n (example P5Y)");
            }
        }
    }