class BusinessObjectDataKeyComparator implements Comparator<BusinessObjectDataKey>, Serializable {

    @Override
    public int compare(final BusinessObjectDataKey data1, final BusinessObjectDataKey data2)
    {
        if (data1 == null || data2 == null)
        {
            return data1 == null && data2 == null ? 0 : (data1 == null ? -1 : 1);
        }
        int result = ObjectUtils.compare(data1.getBusinessObjectDefinitionName(), data2.getBusinessObjectDefinitionName());
        if (result != 0)
        {
            return result;
        }
        result = ObjectUtils.compare(data1.getBusinessObjectFormatUsage(), data2.getBusinessObjectFormatUsage());
        if (result != 0)
        {
            return result;
        }
        result = ObjectUtils.compare(data1.getBusinessObjectFormatFileType(), data2.getBusinessObjectFormatFileType());
        if (result != 0)
        {
            return result;
        }
        result = ObjectUtils.compare(data1.getBusinessObjectFormatVersion(), data2.getBusinessObjectFormatVersion());
        if (result != 0)
        {
            return result;
        }
        result = ObjectUtils.compare(data1.getPartitionValue(), data2.getPartitionValue());
        if (result != 0)
        {
            return result;
        }
        return ObjectUtils.compare(data1.getBusinessObjectDataVersion(), data2.getBusinessObjectDataVersion());
    }

}

class BusinessObjectDataKeyComparatorTest {

    private BusinessObjectDataKeyComparator comparator;

    @Test
    public void testCompareBusinessObjectDataVersion() throws Exception
    {

        BusinessObjectDataKey businessObjectDataKey1 = new BusinessObjectDataKey();
        BusinessObjectDataKey businessObjectDataKey2 = new BusinessObjectDataKey();

        // "a" = "b"
        businessObjectDataKey1.setBusinessObjectDataVersion(0);
        businessObjectDataKey2.setBusinessObjectDataVersion(0);
        assertEquals(0, comparator.compare(businessObjectDataKey1, businessObjectDataKey2));

        // "a" < "b"
        businessObjectDataKey1.setBusinessObjectDataVersion(0);
        businessObjectDataKey2.setBusinessObjectDataVersion(1);
        assertEquals(-1, comparator.compare(businessObjectDataKey1, businessObjectDataKey2));

        // "b" > "a"
        assertEquals(1, comparator.compare(businessObjectDataKey2, businessObjectDataKey1));
    }

}