Value implements Comparable<Value> { @Override public int compareTo(final Value value) { if (comparable == null && value.comparable == null) { return 0; } else if (comparable == null) { return -1; } else if (value.comparable == null) { return 1; } else { try { return this.comparable.compareTo(value.comparable); } catch (final ClassCastException cce) { return this.comparable.toString().compareTo(value.comparable.toString()); } } } Value(final Comparable comparable); Comparable getComparable(); @Override String toString(); @Override int compareTo(final Value value);  }
@Test public void testIntegerVSInteger() throws Exception { final Value nroZero = new Value( 0 ); final Value nroOne = new Value( 1 ); assertTrue( nroZero.compareTo( nroOne ) < 0 ); assertTrue( nroOne.compareTo( nroZero ) > 0 ); }
@Test public void testStringVSInteger() throws Exception { final Value hello = new Value( "hello" ); final Value nroOne = new Value( 1 ); assertTrue( hello.compareTo( nroOne ) > 0 ); assertTrue( nroOne.compareTo( hello ) < 0 ); }
@Test public void testStringVSIntegerString() throws Exception { final Value hello = new Value( "hello" ); final Value nroOne = new Value( "1" ); assertTrue( hello.compareTo( nroOne ) > 0 ); assertTrue( nroOne.compareTo( hello ) < 0 ); }
@Test public void testStringVSString() throws Exception { final Value a = new Value( "a" ); final Value b = new Value( "b" ); assertTrue( a.compareTo( b ) < 0 ); assertTrue( b.compareTo( a ) > 0 ); }