directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r349930 - in /directory/network/branches/chain_refactor/src: java/org/apache/mina/common/ java/org/apache/mina/common/support/ test/org/apache/mina/common/
Date Wed, 30 Nov 2005 12:18:55 GMT
Author: trustin
Date: Wed Nov 30 04:18:42 2005
New Revision: 349930

URL: http://svn.apache.org/viewcvs?rev=349930&view=rev
Log:
* Added DefaultIoFilterChainBuilder.toString() and its test case
* Added AbstractIoFilterChain.toString() and its test case

Modified:
    directory/network/branches/chain_refactor/src/java/org/apache/mina/common/DefaultIoFilterChainBuilder.java
    directory/network/branches/chain_refactor/src/java/org/apache/mina/common/support/AbstractIoFilterChain.java
    directory/network/branches/chain_refactor/src/test/org/apache/mina/common/DefaultIoFilterChainBuilderTest.java
    directory/network/branches/chain_refactor/src/test/org/apache/mina/common/IoFilterChainTest.java

Modified: directory/network/branches/chain_refactor/src/java/org/apache/mina/common/DefaultIoFilterChainBuilder.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/chain_refactor/src/java/org/apache/mina/common/DefaultIoFilterChainBuilder.java?rev=349930&r1=349929&r2=349930&view=diff
==============================================================================
--- directory/network/branches/chain_refactor/src/java/org/apache/mina/common/DefaultIoFilterChainBuilder.java
(original)
+++ directory/network/branches/chain_refactor/src/java/org/apache/mina/common/DefaultIoFilterChainBuilder.java
Wed Nov 30 04:18:42 2005
@@ -209,6 +209,42 @@
             chain.addLast( e.getName(), e.getFilter() );
         }
     }
+    
+    public String toString()
+    {
+        StringBuffer buf = new StringBuffer();
+        buf.append( "{ " );
+        
+        boolean empty = true;
+        
+        for( Iterator i = entries.iterator(); i.hasNext(); )
+        {
+            Entry e = ( Entry ) i.next();
+            if( !empty )
+            {
+                buf.append( ", " );
+            }
+            else
+            {
+                empty = false;
+            }
+            
+            buf.append( '(' );
+            buf.append( e.getName() );
+            buf.append( ':' );
+            buf.append( e.getFilter() );
+            buf.append( ')' );
+        }
+        
+        if( empty )
+        {
+            buf.append( "empty" );
+        }
+        
+        buf.append( " }" );
+        
+        return buf.toString();
+    }
 
     private void checkBaseName( String baseName )
     {
@@ -245,7 +281,7 @@
         entriesByFilter.remove( e.getFilter() );
     }
 
-    public static class EntryImpl implements Entry
+    private static class EntryImpl implements Entry
     {
         private final String name;
         private final IoFilter filter;

Modified: directory/network/branches/chain_refactor/src/java/org/apache/mina/common/support/AbstractIoFilterChain.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/chain_refactor/src/java/org/apache/mina/common/support/AbstractIoFilterChain.java?rev=349930&r1=349929&r2=349930&view=diff
==============================================================================
--- directory/network/branches/chain_refactor/src/java/org/apache/mina/common/support/AbstractIoFilterChain.java
(original)
+++ directory/network/branches/chain_refactor/src/java/org/apache/mina/common/support/AbstractIoFilterChain.java
Wed Nov 30 04:18:42 2005
@@ -557,6 +557,45 @@
         return list;
     }
     
+    public String toString()
+    {
+        StringBuffer buf = new StringBuffer();
+        buf.append( "{ " );
+        
+        boolean empty = true;
+        
+        EntryImpl e = head.nextEntry;
+        while( e != tail )
+        {
+            if( !empty )
+            {
+                buf.append( ", " );
+            }
+            else
+            {
+                empty = false;
+            }
+            
+            buf.append( '(' );
+            buf.append( e.getName() );
+            buf.append( ':' );
+            buf.append( e.getFilter() );
+            buf.append( ')' );
+
+            e = e.nextEntry;
+        }
+
+        if( empty )
+        {
+            buf.append( "empty" );
+        }
+        
+        buf.append( " }" );
+        
+        return buf.toString();
+    }
+
+    
     protected void finalize() throws Throwable
     {
         try

Modified: directory/network/branches/chain_refactor/src/test/org/apache/mina/common/DefaultIoFilterChainBuilderTest.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/chain_refactor/src/test/org/apache/mina/common/DefaultIoFilterChainBuilderTest.java?rev=349930&r1=349929&r2=349930&view=diff
==============================================================================
--- directory/network/branches/chain_refactor/src/test/org/apache/mina/common/DefaultIoFilterChainBuilderTest.java
(original)
+++ directory/network/branches/chain_refactor/src/test/org/apache/mina/common/DefaultIoFilterChainBuilderTest.java
Wed Nov 30 04:18:42 2005
@@ -69,6 +69,26 @@
         Assert.assertEquals( "FCAEBGDH", actual );
     }
     
+    public void testGet() throws Exception
+    {
+        DefaultIoFilterChainBuilder builder = new DefaultIoFilterChainBuilder();
+        
+        IoFilter filterA = new IoFilterAdapter();
+        IoFilter filterB = new IoFilterAdapter();
+        IoFilter filterC = new IoFilterAdapter();
+        IoFilter filterD = new IoFilterAdapter();
+        
+        builder.addFirst( "A", filterA );
+        builder.addLast( "B", filterB );
+        builder.addBefore( "B", "C", filterC );
+        builder.addAfter( "A", "D", filterD );
+        
+        Assert.assertSame( filterA, builder.get( "A" ).getFilter() );
+        Assert.assertSame( filterB, builder.get( "B" ).getFilter() );
+        Assert.assertSame( filterC, builder.get( "C" ).getFilter() );
+        Assert.assertSame( filterD, builder.get( "D" ).getFilter() );
+    }
+    
     public void testRemove() throws Exception
     {
         DefaultIoFilterChainBuilder builder = new DefaultIoFilterChainBuilder();
@@ -101,5 +121,33 @@
         builder.clear();
         
         Assert.assertEquals( 0, builder.getAll().size() );
+    }
+    
+    public void testToString()
+    {
+        DefaultIoFilterChainBuilder builder = new DefaultIoFilterChainBuilder();
+        
+        // When the chain is empty
+        Assert.assertEquals( "{ empty }", builder.toString() );
+        
+        // When there's one filter
+        builder.addLast( "A", new IoFilterAdapter()
+        {
+            public String toString()
+            {
+                return "B";
+            }
+        } );
+        Assert.assertEquals( "{ (A:B) }", builder.toString() );
+        
+        // When there are two
+        builder.addLast( "C", new IoFilterAdapter()
+        {
+            public String toString()
+            {
+                return "D";
+            }
+        } );
+        Assert.assertEquals( "{ (A:B), (C:D) }", builder.toString() );
     }
 }

Modified: directory/network/branches/chain_refactor/src/test/org/apache/mina/common/IoFilterChainTest.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/chain_refactor/src/test/org/apache/mina/common/IoFilterChainTest.java?rev=349930&r1=349929&r2=349930&view=diff
==============================================================================
--- directory/network/branches/chain_refactor/src/test/org/apache/mina/common/IoFilterChainTest.java
(original)
+++ directory/network/branches/chain_refactor/src/test/org/apache/mina/common/IoFilterChainTest.java
Wed Nov 30 04:18:42 2005
@@ -73,6 +73,24 @@
         Assert.assertEquals( "FCAEBGDH", actual );
     }
     
+    public void testGet() throws Exception
+    {
+        IoFilter filterA = new IoFilterAdapter();
+        IoFilter filterB = new IoFilterAdapter();
+        IoFilter filterC = new IoFilterAdapter();
+        IoFilter filterD = new IoFilterAdapter();
+        
+        chain.addFirst( "A", filterA );
+        chain.addLast( "B", filterB );
+        chain.addBefore( "B", "C", filterC );
+        chain.addAfter( "A", "D", filterD );
+        
+        Assert.assertSame( filterA, chain.get( "A" ).getFilter() );
+        Assert.assertSame( filterB, chain.get( "B" ).getFilter() );
+        Assert.assertSame( filterC, chain.get( "C" ).getFilter() );
+        Assert.assertSame( filterD, chain.get( "D" ).getFilter() );
+    }
+    
     public void testRemove() throws Exception
     {
         chain.addLast( "A", new EventOrderTestFilter( 'A' ) );
@@ -103,6 +121,32 @@
         Assert.assertEquals( 0, chain.getAll().size() );
     }
     
+    public void testToString() throws Exception
+    {
+        // When the chain is empty
+        Assert.assertEquals( "{ empty }", chain.toString() );
+        
+        // When there's one filter
+        chain.addLast( "A", new IoFilterAdapter()
+        {
+            public String toString()
+            {
+                return "B";
+            }
+        } );
+        Assert.assertEquals( "{ (A:B) }", chain.toString() );
+        
+        // When there are two
+        chain.addLast( "C", new IoFilterAdapter()
+        {
+            public String toString()
+            {
+                return "D";
+            }
+        } );
+        Assert.assertEquals( "{ (A:B), (C:D) }", chain.toString() );
+    }
+
     public void testDefault()
     {
         run( "HS0 HSO HMR HMS HSI HEC HSC" );



Mime
View raw message