class IndexVersion {

    public static int compareSoftwareVersions(String firstVersion, String secondVersion)
            throws IOException
    {
        // Constants which represent our various return values for this comparison
        int GREATER_THAN = 1;
        int EQUAL = 0;
        int LESS_THAN = -1;
        
        // "null" is less than anything
        if(firstVersion==null)
            return LESS_THAN;
        // Anything is newer than "null"
        if(secondVersion==null)
            return GREATER_THAN;
            
        //Split the first version into it's parts (i.e. major & minor versions)
        String[] firstParts = firstVersion.split("\\.");
        String[] secondParts = secondVersion.split("\\.");
        
        // Get major / minor version numbers. Default to "0" if unspecified
        // NOTE: We are specifically IGNORING any sub-minor version numbers
        int firstMajor = firstParts.length>=1 ? Integer.parseInt(firstParts[0]) : 0;
        int firstMinor = firstParts.length>=2 ? Integer.parseInt(firstParts[1]) : 0;
        int secondMajor = secondParts.length>=1 ? Integer.parseInt(secondParts[0]) : 0;
        int secondMinor = secondParts.length>=2 ? Integer.parseInt(secondParts[1]) : 0;
        
        // Check for equality
        if(firstMajor==secondMajor && firstMinor==secondMinor)
        {
            return EQUAL;
        }
        // If first major version is greater than second
        else if(firstMajor > secondMajor)
        {
            return GREATER_THAN;
        }
        // If first major version is less than second
        else if(firstMajor < secondMajor)
        {
            return LESS_THAN;
        }
        // If we get here, major versions must be EQUAL. Now, time to check our minor versions
        else if(firstMinor > secondMinor)
        {
            return GREATER_THAN;
        }
        else if(firstMinor < secondMinor)
        {
            return LESS_THAN;
        }
        else
        {
            // This is an impossible scenario. 
            // This 'else' should never be triggered since we've checked for equality above already
            return EQUAL;
        }
    }

}