code: @SuppressWarnings("unchecked")
     public static <A, B> int compare(Comparable<A> c1, Comparable<B> c2)
     {
        if (c1 == c2) // NOSONAR
        {
           return 0;
        }
        else if (c1 == null)
        {
           return -1;
        }
        else if (c2 == null)
        {
           return 1;
        }
        else if (c1.getClass() == c2.getClass())
        {
           return c1.compareTo((A)c2);
        }
        else
        {
           // differing types -> compare class names
           String name1 = c1.getClass().getName();
           String name2 = c2.getClass().getName();
           return name1.compareTo(name2);
        }
     }
docs: Compares values <code>c1</code> and <code>c2</code>. If the
  values have differing types, then the order is defined on
  the type itself by calling <code>compareTo()</code> on the respective
  type class names.
  
  @param c1 the first value.
  @param c2 the second value.
  @return a negative integer if <code>c1</code> should come before
  <code>c2</code><br> a positive integer if <code>c1</code>
  should come after <code>c2</code><br> <code>0</code> if they
  are equal.