directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 10016 - in incubator/directory/snickers/trunk/ber: . src/java/org/apache/snickers/ber/digester src/java/org/apache/snickers/ber/digester/rules src/test/org/apache/snickers/ber/digester src/test/org/apache/snickers/ber/digester/rules
Date Thu, 15 Apr 2004 01:10:23 GMT
Author: akarasulu
Date: Wed Apr 14 18:10:22 2004
New Revision: 10016

Removed:
   incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/BooleanStack.java
   incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/ByteStack.java
   incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/CharStack.java
   incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/DoubleStack.java
   incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/FloatStack.java
   incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/IntStack.java
   incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/LongStack.java
   incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/ShortStack.java
   incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/digester/BooleanStackTest.java
   incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/digester/ByteStackTest.java
   incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/digester/CharStackTest.java
   incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/digester/DoubleStackTest.java
   incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/digester/FloatStackTest.java
   incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/digester/IntStackTest.java
   incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/digester/LongStackTest.java
   incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/digester/ShortStackTest.java
Modified:
   incubator/directory/snickers/trunk/ber/maven.xml
   incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/BERDigester.java
   incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/Rules.java
   incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/RulesBase.java
   incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/TagTree.java
   incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/rules/ByteAccumulator.java
   incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/rules/PrimitiveOctetStringRule.java
   incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/digester/RulesBaseTest.java
   incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/digester/TagTreeTest.java
   incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/digester/rules/ByteAccumulatorTest.java
   incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/digester/rules/PrimitiveOctetStringRuleTest.java
Log:
o removed primitive collections which were moved to commons-collections
o added an accumulator class along with a test since this will be used often
o added more to the OctetStringRule and to its test case


Modified: incubator/directory/snickers/trunk/ber/maven.xml
==============================================================================
--- incubator/directory/snickers/trunk/ber/maven.xml	(original)
+++ incubator/directory/snickers/trunk/ber/maven.xml	Wed Apr 14 18:10:22 2004
@@ -1,7 +1,7 @@
-<?xml version="1.0" encoding="ISO-8859-1"?> 
-  
-<project 
-  default="jar:install" 
-  >
-  
-</project>
+<?xml version="1.0" encoding="ISO-8859-1"?> 
+  
+<project 
+  default="jar:install" 
+  >
+  
+</project>

Modified: incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/BERDigester.java
==============================================================================
--- incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/BERDigester.java
(original)
+++ incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/BERDigester.java
Wed Apr 14 18:10:22 2004
@@ -35,6 +35,7 @@
 import org.apache.commons.codec.stateful.AbstractStatefulDecoder ;
 
 import org.apache.commons.collections.ArrayStack ;
+import org.apache.commons.collections.primitives.*;
 
 
 /**

Modified: incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/Rules.java
==============================================================================
--- incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/Rules.java
(original)
+++ incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/Rules.java
Wed Apr 14 18:10:22 2004
@@ -18,6 +18,8 @@
 package org.apache.snickers.ber.digester ;
 
 
+import org.apache.commons.collections.primitives.IntStack;
+
 import java.util.List ;
 
 

Modified: incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/RulesBase.java
==============================================================================
--- incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/RulesBase.java
(original)
+++ incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/RulesBase.java
Wed Apr 14 18:10:22 2004
@@ -17,6 +17,8 @@
 package org.apache.snickers.ber.digester ;
 
 
+import org.apache.commons.collections.primitives.IntStack;
+
 import java.util.List ;
 import java.util.ArrayList ;
 import java.util.Collections ;

Modified: incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/TagTree.java
==============================================================================
--- incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/TagTree.java
(original)
+++ incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/TagTree.java
Wed Apr 14 18:10:22 2004
@@ -22,6 +22,7 @@
 import java.util.Collections ;
 
 import org.apache.commons.lang.Validate ;
+import org.apache.commons.collections.primitives.IntStack;
 
 
 /**

Modified: incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/rules/ByteAccumulator.java
==============================================================================
--- incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/rules/ByteAccumulator.java
(original)
+++ incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/rules/ByteAccumulator.java
Wed Apr 14 18:10:22 2004
@@ -73,14 +73,15 @@
         if ( initial <= 0 )
         {
             bs = ArrayUtils.EMPTY_BYTE_ARRAY ;
+            this.initial = 0 ;
         }
         else
         {
             bs = new byte[initial] ;
+            this.initial = initial ;
         }
 
         pos = 0 ;
-        this.initial = initial ;
         increment = DEFAULT_INCREMENT ;
     }
 
@@ -206,40 +207,80 @@
     }
 
 
+    /**
+     * Allocates memory to handle a capacity without the need to grow.
+     * This serves to control growth for more efficient use.
+     *
+     * @param capacity the capacity to hold without the need to grow
+     */
     public void ensureCapacity( int capacity )
     {
         if ( bs.length < capacity )
         {
             byte[] newArray = new byte[capacity] ;
-            System.arraycopy( bs, 0, newArray, 0, pos + 1 ) ;
+
+            if ( bs != ArrayUtils.EMPTY_BYTE_ARRAY )
+            {
+                System.arraycopy( bs, 0, newArray, 0, pos + 1 ) ;
+            }
+
+            bs = newArray ;
         }
     }
 
 
+    /**
+     * The growth increment by which the backing store is augmented.
+     *
+     * @return the number of bytes to grow the backing store by
+     */
     public int getGrowthIncrement()
     {
         return increment ;
     }
 
 
+    /**
+     * The initial size of the backing store.
+     *
+     * @return the initial size in bytes of the backing store
+     */
     public int getInitialSize()
     {
         return initial ;
     }
 
 
+    /**
+     * The current capacity of the backing store which may change as this
+     * accumulator is filled with bytes.
+     *
+     * @return the current capacity in bytes
+     */
     public int getCapacity()
     {
         return bs.length ;
     }
 
 
+    /**
+     * The remaining free space that can be filled before having to grow the
+     * backing store of the accumulator.
+     *
+     * @return the remaining free space until the next growth spurt
+     */
     public int getRemainingSpace()
     {
         return bs.length - pos ;
     }
 
 
+    /**
+     * The current position within the backing store marking the point to
+     * which this accumulator is filled.
+     *
+     * @return the current fill position
+     */
     public int getPosition()
     {
         return pos ;

Modified: incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/rules/PrimitiveOctetStringRule.java
==============================================================================
--- incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/rules/PrimitiveOctetStringRule.java
(original)
+++ incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/rules/PrimitiveOctetStringRule.java
Wed Apr 14 18:10:22 2004
@@ -27,7 +27,7 @@
 
 /**
  * A rule that collects the value bytes of an ASN.1 OCTET STRING and pushes
- * the byte[] onto the digester's Object stack.
+ * the buffer of bytes onto the digester's Object stack as a ByteBuffer.
  * <p>
  * This rule can only handle primitive octet strings.  Constructed OCTET STRING
  * values are simply ignored by this rule rather than throwing exceptions.
@@ -39,8 +39,6 @@
 public class PrimitiveOctetStringRule extends AbstractRule
 {
     private ByteAccumulator accumulator = new ByteAccumulator( 0 ) ;
-    /** whether or not the length is known */
-    private boolean isLengthIndeterminate = false ;
     /** used to determin if our type is constructed or primitive */
     private boolean isConstructed = false ;
 
@@ -58,20 +56,6 @@
     }
 
 
-    /*
-     * Creates a rule instance which grows the backing store on indeterminate
-     * length OCTET STRINGS by the specified growth increment.
-     *
-     * @param increment the byte increment to grow the backing store by
-     */
-/*
-    PrimitiveOctetStringRule( int increment )
-    {
-        this.increment = increment ;
-    }
-*/
-
-
     // -----------------------------------------------------------------------
     // Rule event method overrides
     // -----------------------------------------------------------------------
@@ -113,11 +97,7 @@
         // @todo Length should not be visible outside of the digester
         // package.  The digester or a contants interface should contain
         // these constants.
-        if ( Length.INDEFINATE == length )
-        {
-            isLengthIndeterminate = true ;
-        }
-        else
+        if ( Length.INDEFINATE != length )
         {
             accumulator.ensureCapacity( length ) ;
         }
@@ -158,6 +138,5 @@
 
         // clean up
         isConstructed = false ;
-        isLengthIndeterminate = false ;
     }
 }

Modified: incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/digester/RulesBaseTest.java
==============================================================================
--- incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/digester/RulesBaseTest.java
(original)
+++ incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/digester/RulesBaseTest.java
Wed Apr 14 18:10:22 2004
@@ -21,6 +21,8 @@
 
 import java.util.List ;
 
+import org.apache.commons.collections.primitives.IntStack;
+
 
 /**
  * A test case for the RulesBase.

Modified: incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/digester/TagTreeTest.java
==============================================================================
--- incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/digester/TagTreeTest.java
(original)
+++ incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/digester/TagTreeTest.java
Wed Apr 14 18:10:22 2004
@@ -20,6 +20,7 @@
 import java.util.List ;
 
 import junit.framework.TestCase ;
+import org.apache.commons.collections.primitives.IntStack;
 
 
 /**
@@ -116,7 +117,7 @@
                 .get(0) ) ;
         assertEquals( rule2, ( (List) tree.match( new IntStack( pattern2 ) ) )
                 .get(0) ) ;
-        assertNotSame( rule0, ( (List) tree.match( new IntStack( pattern1 ) ) ) 
+        assertNotSame( rule0, ( (List) tree.match( new IntStack( pattern1 ) ) )
                 .get(0) ) ;
         assertNotSame( rule1, ( (List) tree.match( new IntStack( pattern2 ) ) )
                 .get(0) ) ;

Modified: incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/digester/rules/ByteAccumulatorTest.java
==============================================================================
--- incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/digester/rules/ByteAccumulatorTest.java
(original)
+++ incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/digester/rules/ByteAccumulatorTest.java
Wed Apr 14 18:10:22 2004
@@ -47,6 +47,21 @@
     }
 
 
+    public void testByteAccumulatorInt()
+    {
+        ByteAccumulator ba = new ByteAccumulator( 72 ) ;
+        assertEquals( ba.getInitialSize(), ba.getCapacity() ) ;
+        assertEquals( ba.getInitialSize(), ba.getRemainingSpace() ) ;
+        assertEquals( 0, ba.getPosition() ) ;
+
+        // shuts up clover
+        ba = new ByteAccumulator( -1 ) ;
+        assertEquals( ba.getInitialSize(), ba.getCapacity() ) ;
+        assertEquals( ba.getInitialSize(), ba.getRemainingSpace() ) ;
+        assertEquals( 0, ba.getPosition() ) ;
+    }
+
+
     /**
      * Fills the buffer by varying amounts so that either the remaining
      * amount is used for growth increment or the set increment value is
@@ -132,6 +147,51 @@
         assertEquals( 0x02, buf.get() ) ;
         assertEquals( 0x03, buf.get() ) ;
         assertFalse( buf.hasRemaining() ) ;
+
+        ByteAccumulator ba = new ByteAccumulator( 1 ) ;
+        ba.fill( ByteBuffer.allocate( 1 ) ) ;
+        buf = ba.drain() ;
+        buf.get() ;
+        assertFalse( buf.hasRemaining() ) ;
+    }
+
+
+    public void testDrainInt0()
+    {
+        accumulator.fill( ByteBuffer.allocate( 200 ) ) ;
+        accumulator.drain( -1 ) ;
+        assertEquals( 0, accumulator.getCapacity() ) ;
+        assertEquals( 0, accumulator.getRemainingSpace() ) ;
+    }
+
+
+    public void testDrainInt1()
+    {
+        accumulator.fill( ByteBuffer.allocate( 200 ) ) ;
+        accumulator.drain( 10 ) ;
+        assertEquals( 10, accumulator.getCapacity() ) ;
+        assertEquals( 10, accumulator.getRemainingSpace() ) ;
+    }
+
+
+    public void testDrainInt2()
+    {
+        accumulator.fill( ByteBuffer.allocate( 20 ) ) ;
+        accumulator.drain( 10 ) ;
+        assertEquals( 10, accumulator.getCapacity() ) ;
+        assertEquals( 10, accumulator.getRemainingSpace() ) ;
+    }
+
+
+    public void testEnsureCapacity()
+    {
+        accumulator.ensureCapacity( 150 ) ;
+        accumulator.ensureCapacity( 10 ) ;
+        assertEquals( 150, accumulator.getCapacity() ) ;
+        assertEquals( 150, accumulator.getRemainingSpace() ) ;
+        accumulator.ensureCapacity( 222 ) ;
+        assertEquals( 222, accumulator.getCapacity() ) ;
+        assertEquals( 222, accumulator.getRemainingSpace() ) ;
     }
 
 

Modified: incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/digester/rules/PrimitiveOctetStringRuleTest.java
==============================================================================
--- incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/digester/rules/PrimitiveOctetStringRuleTest.java
(original)
+++ incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/digester/rules/PrimitiveOctetStringRuleTest.java
Wed Apr 14 18:10:22 2004
@@ -74,7 +74,7 @@
 
 
     /**
-     * Tests for correct behavior when the OCTET STRING is constructed.
+     * Tests for correct behavior when the OCTET STRING is primitive.
      */
     public void testPrimitiveOctetString()
     {
@@ -87,9 +87,9 @@
 
         // we should have nothing in the object stack
         assertEquals( 1, digester.getCount() ) ;
-        byte[] pushed = ( byte [] ) digester.pop() ;
-        assertEquals( bites[0], pushed[0] ) ;
-        assertEquals( bites[1], pushed[1] ) ;
+        ByteBuffer pushed = ( ByteBuffer ) digester.pop() ;
+        assertEquals( bites[0], pushed.get() ) ;
+        assertEquals( bites[1], pushed.get() ) ;
         assertEquals( 0, digester.getCount() ) ;
     }
 

Mime
View raw message