private static VersionReference parse()

in sdmx30-infomodel/src/main/java/com/epam/jsdmx/infomodel/sdmx30/VersionReference.java [31:120]


    private static VersionReference parse(String version) {
        WildcardScope scope = NONE;
        int majorUntil = -1;
        int minorFrom = -1;
        int minorUntil = -1;
        int patchFrom = -1;
        int patchUntil = -1;
        int extensionFrom = -1;
        Position position = Position.IN_MAJOR;
        final int inputLength = version.length();
        for (int i = 0; i < inputLength; i++) {
            char c = version.charAt(i);
            if (c >= '0' & c <= '9') {
                switch (position) {
                    case IN_MAJOR:
                        majorUntil = i;
                        break;
                    case IN_MINOR:
                        minorUntil = i;
                        break;
                    case IN_PATCH:
                        patchUntil = i;
                        break;
                    default:
                        throw new IllegalArgumentException();
                }
            } else if (c == '+') {
                switch (position) {
                    case IN_MAJOR:
                        scope = WildcardScope.MAJOR;
                        break;
                    case IN_MINOR:
                        scope = WildcardScope.MINOR;
                        break;
                    case IN_PATCH:
                        scope = WildcardScope.PATCH;
                        break;
                    default:
                        throw new IllegalArgumentException();
                }
            } else if (c == '.') {
                switch (position) {
                    case IN_MAJOR:
                        position = Position.IN_MINOR;
                        minorFrom = i + 1;
                        break;
                    case IN_MINOR:
                        position = Position.IN_PATCH;
                        patchFrom = i + 1;
                        break;
                    default:
                        throw new IllegalArgumentException();
                }
            } else if (c == '-') {
                extensionFrom = i + 1;
                break;
            } else {
                throw new IllegalArgumentException();
            }
        }
        short major = Short.parseShort(version.substring(0, majorUntil + 1));

        if (minorFrom == -1 || minorFrom >= inputLength || minorFrom > minorUntil || minorUntil < 0) {
            throw new IllegalArgumentException();
        }

        short minor = Short.parseShort(version.substring(minorFrom, minorUntil + 1));

        if (patchFrom > 0 && patchFrom >= inputLength || patchFrom > patchUntil) {
            throw new IllegalArgumentException();
        }

        short patch = patchFrom > 0 ? Short.parseShort(version.substring(patchFrom, patchUntil + 1)) : -1;

        if (extensionFrom > 0 && patchFrom == -1) {
            throw new IllegalArgumentException();
        }
        if (extensionFrom > 0 && extensionFrom >= inputLength) {
            throw new IllegalArgumentException();
        }

        String extension = extensionFrom == -1 ? null : version.substring(extensionFrom);

        return new VersionReference(
            patchFrom > 0
                ? Version.createFromComponents(major, minor, patch, extension)
                : Version.createFromComponents(major, minor),
            scope
        );
    }