@Test public void testNullBitString() { assertEquals( 0, comparator.compare( null, null ) ); assertEquals( -1, comparator.compare( null, "0101B" ) ); assertEquals( -1, comparator.compare( null, "000B" ) ); assertEquals( 1, comparator.compare( "0101B", null ) ); assertEquals( 1, comparator.compare( "111B", null ) ); }
public int compare( String bs1, String bs2 ) { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13743_COMPARING_BITSTRING, bs1, bs2 ) ); } if ( bs1 == bs2 ) { return 0; } if ( ( bs1 == null ) || ( bs2 == null ) ) { return bs1 == null ? -1 : 1; } char[] array1 = bs1.toCharArray(); char[] array2 = bs2.toCharArray(); int pos1 = bs1.indexOf( '1' ); int pos2 = bs2.indexOf( '1' ); if ( pos1 == -1 ) { if ( pos2 == -1 ) { return 0; } else { return -1; } } else if ( pos2 == -1 ) { return 1; } int length1 = array1.length - pos1; int length2 = array2.length - pos2; if ( length1 == length2 ) { for ( int i = 0; i < length1; i++ ) { int i1 = i + pos1; int i2 = i + pos2; if ( array1[i1] < array2[i2] ) { return -1; } else if ( array1[i1] > array2[i2] ) { return 1; } } return 0; } if ( length1 < length2 ) { return -1; } else { return 1; } }
BitStringComparator extends LdapComparator<String> { public int compare( String bs1, String bs2 ) { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13743_COMPARING_BITSTRING, bs1, bs2 ) ); } if ( bs1 == bs2 ) { return 0; } if ( ( bs1 == null ) || ( bs2 == null ) ) { return bs1 == null ? -1 : 1; } char[] array1 = bs1.toCharArray(); char[] array2 = bs2.toCharArray(); int pos1 = bs1.indexOf( '1' ); int pos2 = bs2.indexOf( '1' ); if ( pos1 == -1 ) { if ( pos2 == -1 ) { return 0; } else { return -1; } } else if ( pos2 == -1 ) { return 1; } int length1 = array1.length - pos1; int length2 = array2.length - pos2; if ( length1 == length2 ) { for ( int i = 0; i < length1; i++ ) { int i1 = i + pos1; int i2 = i + pos2; if ( array1[i1] < array2[i2] ) { return -1; } else if ( array1[i1] > array2[i2] ) { return 1; } } return 0; } if ( length1 < length2 ) { return -1; } else { return 1; } } }
BitStringComparator extends LdapComparator<String> { public int compare( String bs1, String bs2 ) { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13743_COMPARING_BITSTRING, bs1, bs2 ) ); } if ( bs1 == bs2 ) { return 0; } if ( ( bs1 == null ) || ( bs2 == null ) ) { return bs1 == null ? -1 : 1; } char[] array1 = bs1.toCharArray(); char[] array2 = bs2.toCharArray(); int pos1 = bs1.indexOf( '1' ); int pos2 = bs2.indexOf( '1' ); if ( pos1 == -1 ) { if ( pos2 == -1 ) { return 0; } else { return -1; } } else if ( pos2 == -1 ) { return 1; } int length1 = array1.length - pos1; int length2 = array2.length - pos2; if ( length1 == length2 ) { for ( int i = 0; i < length1; i++ ) { int i1 = i + pos1; int i2 = i + pos2; if ( array1[i1] < array2[i2] ) { return -1; } else if ( array1[i1] > array2[i2] ) { return 1; } } return 0; } if ( length1 < length2 ) { return -1; } else { return 1; } } BitStringComparator( String oid ); }
BitStringComparator extends LdapComparator<String> { public int compare( String bs1, String bs2 ) { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13743_COMPARING_BITSTRING, bs1, bs2 ) ); } if ( bs1 == bs2 ) { return 0; } if ( ( bs1 == null ) || ( bs2 == null ) ) { return bs1 == null ? -1 : 1; } char[] array1 = bs1.toCharArray(); char[] array2 = bs2.toCharArray(); int pos1 = bs1.indexOf( '1' ); int pos2 = bs2.indexOf( '1' ); if ( pos1 == -1 ) { if ( pos2 == -1 ) { return 0; } else { return -1; } } else if ( pos2 == -1 ) { return 1; } int length1 = array1.length - pos1; int length2 = array2.length - pos2; if ( length1 == length2 ) { for ( int i = 0; i < length1; i++ ) { int i1 = i + pos1; int i2 = i + pos2; if ( array1[i1] < array2[i2] ) { return -1; } else if ( array1[i1] > array2[i2] ) { return 1; } } return 0; } if ( length1 < length2 ) { return -1; } else { return 1; } } BitStringComparator( String oid ); int compare( String bs1, String bs2 ); }
BitStringComparator extends LdapComparator<String> { public int compare( String bs1, String bs2 ) { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13743_COMPARING_BITSTRING, bs1, bs2 ) ); } if ( bs1 == bs2 ) { return 0; } if ( ( bs1 == null ) || ( bs2 == null ) ) { return bs1 == null ? -1 : 1; } char[] array1 = bs1.toCharArray(); char[] array2 = bs2.toCharArray(); int pos1 = bs1.indexOf( '1' ); int pos2 = bs2.indexOf( '1' ); if ( pos1 == -1 ) { if ( pos2 == -1 ) { return 0; } else { return -1; } } else if ( pos2 == -1 ) { return 1; } int length1 = array1.length - pos1; int length2 = array2.length - pos2; if ( length1 == length2 ) { for ( int i = 0; i < length1; i++ ) { int i1 = i + pos1; int i2 = i + pos2; if ( array1[i1] < array2[i2] ) { return -1; } else if ( array1[i1] > array2[i2] ) { return 1; } } return 0; } if ( length1 < length2 ) { return -1; } else { return 1; } } BitStringComparator( String oid ); int compare( String bs1, String bs2 );  }