ByteBufferComparator implements Comparator<ByteBuffer> { @Override public int compare( ByteBuffer v1, ByteBuffer v2 ) { if ( v1 == null && v2 != null ) return -1; if ( v1 != null && v2 == null ) return 1; if ( v1 == null && v2 == null ) return 0; return v1.compareTo( v2 ); }  @Override int compare( ByteBuffer v1, ByteBuffer v2 );  }
@Test public void testCompare() throws Exception { ByteBufferComparator byteBufferComparator = new ByteBufferComparator(); ByteBuffer hello0 = ByteBuffer.wrap( "hello0".getBytes() ); ByteBuffer hello1 = ByteBuffer.wrap( "hello1".getBytes() ); assertEquals( -1, byteBufferComparator.compare( null, hello0 ) ); assertEquals( 1, byteBufferComparator.compare( hello0, null ) ); assertEquals( 0, byteBufferComparator.compare( null, null ) ); assertEquals( 1, byteBufferComparator.compare( hello0, null ) ); assertEquals( 0, byteBufferComparator.compare( hello0, hello0 ) ); assertEquals( -1, byteBufferComparator.compare( hello0, hello1 ) ); }