@Override
    public int compareTo(@NotNull DependencyVersion version) {
        if (version == null) {
            return 1;
        }
        final List<String> left = this.getVersionParts();
        final List<String> right = version.getVersionParts();
        final int max = Math.min(left.size(), right.size());

        for (int i = 0; i < max; i++) {
            final String lStr = left.get(i);
            final String rStr = right.get(i);
            if (lStr.equals(rStr)) {
                continue;
            }
            try {
                final int l = Integer.parseInt(lStr);
                final int r = Integer.parseInt(rStr);
                if (l < r) {
                    return -1;
                } else if (l > r) {
                    return 1;
                }
            } catch (NumberFormatException ex) {
                final int comp = left.get(i).compareTo(right.get(i));
                if (comp < 0) {
                    return -1;
                } else if (comp > 0) {
                    return 1;
                }
            }
        }
        return Integer.compare(left.size(), right.size());
    }
@Test
    public void testCompareTo() {
        DependencyVersion instance = new DependencyVersion("1.2.3");
        DependencyVersion version = new DependencyVersion("1.2.3");
        assertEquals(0, instance.compareTo(version));
        version = new DependencyVersion("1.1");
        assertEquals(1, instance.compareTo(version));
        version = new DependencyVersion("1.2");
        assertEquals(1, instance.compareTo(version));
        version = new DependencyVersion("1.3");
        assertEquals(-1, instance.compareTo(version));
        version = new DependencyVersion("1.2.3.1");
        assertEquals(-1, instance.compareTo(version));

        instance = new DependencyVersion("1.0.1n");
        version = new DependencyVersion("1.0.1m");
        assertEquals(1, instance.compareTo(version));
        version = new DependencyVersion("1.0.1n");
        assertEquals(0, instance.compareTo(version));
        version = new DependencyVersion("1.0.1o");
        assertEquals(-1, instance.compareTo(version));

        DependencyVersion[] dv = new DependencyVersion[7];
        dv[0] = new DependencyVersion("2.1.3");
        dv[1] = new DependencyVersion("2.1.3.r2");
        dv[2] = new DependencyVersion("2.1.3.r1");
        dv[3] = new DependencyVersion("1.2.3.1");
        dv[4] = new DependencyVersion("1.2.3");
        dv[5] = new DependencyVersion("2");
        dv[6] = new DependencyVersion("-");

        DependencyVersion[] expected = new DependencyVersion[7];
        expected[0] = new DependencyVersion("-");
        expected[1] = new DependencyVersion("1.2.3");
        expected[2] = new DependencyVersion("1.2.3.1");
        expected[3] = new DependencyVersion("2");
        expected[4] = new DependencyVersion("2.1.3");
        expected[5] = new DependencyVersion("2.1.3.r1");
        expected[6] = new DependencyVersion("2.1.3.r2");
        Arrays.sort(dv);

        assertArrayEquals(expected, dv);
    }