public static Comparator getComparator()

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


    public static Comparator<VersionReference> getComparator() {
        return (v1, v2) -> {
            if (v1.isWildcarded() || v2.isWildcarded()) {
                throw new IllegalArgumentException(
                    "Cannot compare wildcarded versions: "
                        + v1 + " & " + v2
                );
            }

            var v1Base = v1.getBase();
            var v2Base = v2.getBase();

            var result = Short.compare(v1Base.getMajor(), v2Base.getMajor());
            if (result != 0) {
                return result;
            }

            result = Short.compare(v1Base.getMinor(), v2Base.getMinor());
            if (result != 0) {
                return result;
            }

            if (v1Base.isLegacy() && v2Base.isLegacy()) {
                return 0;
            }

            if (!v1Base.isLegacy() && !v2Base.isLegacy()) {
                int patchComparingResult = Short.compare(v1Base.getPatch().get(), v2Base.getPatch().get());
                if (patchComparingResult != 0) {
                    return patchComparingResult;
                }
                if (v1Base.isStable() && v2Base.isStable() || !v1Base.isStable() && !v2Base.isStable()) {
                    return 0;
                }
                if (v1Base.isStable()) {
                    return 1;
                }
                return -1;
            } else {
                if (v2Base.isLegacy()) {
                    return 1;
                } else {
                    return -1;
                }
            }

        };
    }