public static int versionCompare(String fromVersion, String toVersion) {
        if (fromVersion == null || toVersion == null) {
            return -1;
        }
        String[] fromArr = fromVersion.split("\\.");
        String[] toArr = toVersion.split("\\.");
        if (fromArr.length != 3 || toArr.length != 3) {
            return -1;
        }
        try {
            int fromFirst = Integer.parseInt(fromArr[0]);
            int fromMiddle = Integer.parseInt(fromArr[1]);
            int fromEnd = Integer.parseInt(fromArr[2]);
            int toFirst = Integer.parseInt(toArr[0]);
            int toMiddle = Integer.parseInt(toArr[1]);
            int toEnd = Integer.parseInt(toArr[2]);
            if (fromFirst - toFirst != 0) {
                return fromFirst - toFirst;
            } else if (fromMiddle - toMiddle != 0) {
                return fromMiddle - toMiddle;
            } else {
                return fromEnd - toEnd;
            }
        } catch (NumberFormatException nfe) {
            return -1;
        }
    }
@Test
    public void testVersionCompare() {
        assertThat(VersionUtil.versionCompare("1.2.3", null), lessThan(0));
        assertThat(VersionUtil.versionCompare(null, "1.2.3"), lessThan(0));

        assertThat(VersionUtil.versionCompare("1.2.x", "1.2.3"), lessThan(0));
        assertThat(VersionUtil.versionCompare("1.2.3", "1.2.y"), lessThan(0));

        assertThat(VersionUtil.versionCompare("1", "1.2.3"), lessThan(0));
        assertThat(VersionUtil.versionCompare("1.2", "1.2.3"), lessThan(0));
        assertThat(VersionUtil.versionCompare("1.2.3.4", "1.2.3"), lessThan(0));

        assertThat(VersionUtil.versionCompare("1.2.3", "1.2.3"), is(0));
        assertThat(VersionUtil.versionCompare("2.2.3", "1.2.3"), greaterThan(0));
        assertThat(VersionUtil.versionCompare("1.2.3", "2.2.3"), lessThan(0));
    }