directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1033490 - in /directory/shared/trunk/ldap/src: main/java/org/apache/directory/shared/asn1/primitives/BitString.java test/java/org/apache/directory/shared/asn1/primitives/BitStringTest.java
Date Wed, 10 Nov 2010 14:30:51 GMT
Author: elecharny
Date: Wed Nov 10 14:30:50 2010
New Revision: 1033490

URL: http://svn.apache.org/viewvc?rev=1033490&view=rev
Log:
Some more fixes for the BitString implementation

Modified:
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/asn1/primitives/BitString.java
    directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/asn1/primitives/BitStringTest.java

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/asn1/primitives/BitString.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/asn1/primitives/BitString.java?rev=1033490&r1=1033489&r2=1033490&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/asn1/primitives/BitString.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/asn1/primitives/BitString.java
Wed Nov 10 14:30:50 2010
@@ -182,7 +182,7 @@ public class BitString implements Serial
             throw new IndexOutOfBoundsException( I18n.err( I18n.ERR_00030_BIT_NUMBER_OUT_OF_BOUND
) );
         }
 
-        int posBytes = ( pos >> 3 );
+        int posBytes = pos >> 3;
         int bitNumber = 7 - pos % 8;
 
         bytes[posBytes] |= ( 1 << bitNumber );
@@ -204,9 +204,8 @@ public class BitString implements Serial
             throw new IndexOutOfBoundsException( I18n.err( I18n.ERR_00030_BIT_NUMBER_OUT_OF_BOUND
) );
         }
 
-        int realPos = pos + nbUnusedBits;
-        int posBytes = nbBytes - 1 - ( realPos >> 3 );
-        int bitNumber = realPos % 8;
+        int posBytes = pos >> 3;
+        int bitNumber = 7 - pos % 8;
 
         bytes[posBytes] &= ~( 1 << bitNumber );
     }
@@ -239,9 +238,8 @@ public class BitString implements Serial
             throw new IndexOutOfBoundsException( I18n.err( I18n.ERR_00031_CANNOT_FIND_BIT,
pos, nbBits ) );
         }
 
-        int realPos = pos + nbUnusedBits;
-        int posBytes = nbBytes - ( realPos >> 3 ) - 1;
-        int bitNumber = realPos % 8;
+        int posBytes = pos >> 3;
+        int bitNumber = 7 - pos % 8;
 
         int res = bytes[posBytes] & ( 1 << bitNumber );
         
@@ -250,11 +248,11 @@ public class BitString implements Serial
 
 
     /**
-     * @return The number of bytes used to encode this BitString
+     * @return The number of bits stored in this BitString
      */
     public int size()
     {
-        return nbBytes;
+        return nbBits;
     }
 
 

Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/asn1/primitives/BitStringTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/asn1/primitives/BitStringTest.java?rev=1033490&r1=1033489&r2=1033490&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/asn1/primitives/BitStringTest.java
(original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/asn1/primitives/BitStringTest.java
Wed Nov 10 14:30:50 2010
@@ -265,7 +265,7 @@ public class BitStringTest
         
         bitString.clearBit( 11 );
         byte[] bytesModified = new byte[]
-            { 0x00, (byte)0xAA, 0x11, (byte)0x80, (byte)0xFE };
+            { 0x00, (byte)0xAA, 0x01, (byte)0x88, (byte)0xFE };
                             
         assertEquals( Asn1StringUtils.dumpBytes( bytesModified ), Asn1StringUtils.dumpBytes(
bitString.getData() ) );
     }



Mime
View raw message