[prev in list] [next in list] [prev in thread] [next in thread] 

List:       jakarta-commons-dev
Subject:    svn commit: r1163743 - in
From:       simonetripodi () apache ! org
Date:       2011-08-31 19:01:10
Message-ID: 20110831190110.D8B0723889E5 () eris ! apache ! org
[Download RAW message or body]

Author: simonetripodi
Date: Wed Aug 31 19:01:10 2011
New Revision: 1163743

URL: http://svn.apache.org/viewvc?rev=1163743&view=rev
Log:
used smarter ArrayList instead of continuous replaced fixed arrays

that modification introduces a Clirr error

    "Changed type of field commands from org.apache.commons.chain.Command[] to \
java.util.List"

it was used anyway only as internal data structure to store Command instances & for \
test purposes, not a meaningful change

Modified:
    commons/proper/chain/branches/version-2.0-work/src/main/java/org/apache/commons/chain/impl/ChainBase.java
  commons/proper/chain/branches/version-2.0-work/src/test/java/org/apache/commons/chain/config/TestChain.java
  commons/proper/chain/branches/version-2.0-work/src/test/java/org/apache/commons/chain/impl/ChainBaseTestCase.java


Modified: commons/proper/chain/branches/version-2.0-work/src/main/java/org/apache/commons/chain/impl/ChainBase.java
                
URL: http://svn.apache.org/viewvc/commons/proper/chain/branches/version-2.0-work/src/m \
ain/java/org/apache/commons/chain/impl/ChainBase.java?rev=1163743&r1=1163742&r2=1163743&view=diff
 ==============================================================================
--- commons/proper/chain/branches/version-2.0-work/src/main/java/org/apache/commons/chain/impl/ChainBase.java \
                (original)
+++ commons/proper/chain/branches/version-2.0-work/src/main/java/org/apache/commons/chain/impl/ChainBase.java \
Wed Aug 31 19:01:10 2011 @@ -17,8 +17,11 @@
 package org.apache.commons.chain.impl;
 
 
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Iterator;
+import java.util.List;
+
 import org.apache.commons.chain.Chain;
 import org.apache.commons.chain.Command;
 import org.apache.commons.chain.Context;
@@ -117,7 +120,7 @@ public class ChainBase<C extends Context
      * the order in which they may delegate processing to the remainder of
      * the {@link Chain}.</p>
      */
-    protected Command<C>[] commands = new Command[0];
+    private List<Command<C>> commands = new ArrayList<Command<C>>();
 
 
     /**
@@ -147,10 +150,7 @@ public class ChainBase<C extends Context
         if (frozen) {
             throw new IllegalStateException();
         }
-        Command[] results = new Command[commands.length + 1];
-        System.arraycopy(commands, 0, results, 0, commands.length);
-        results[commands.length] = command;
-        commands = results;
+        commands.add( command );
 
     }
 
@@ -187,10 +187,10 @@ public class ChainBase<C extends Context
         boolean saveResult = false;
         Exception saveException = null;
         int i = 0;
-        int n = commands.length;
+        int n = commands.size();
         for (i = 0; i < n; i++) {
             try {
-                saveResult = commands[i].execute(context);
+                saveResult = commands.get(i).execute(context);
                 if (saveResult) {
                     break;
                 }
@@ -207,10 +207,10 @@ public class ChainBase<C extends Context
         boolean handled = false;
         boolean result = false;
         for (int j = i; j >= 0; j--) {
-            if (commands[j] instanceof Filter) {
+            if (commands.get(j) instanceof Filter) {
                 try {
                     result =
-                        ((Filter) commands[j]).postprocess(context,
+                        ((Filter) commands.get(j)).postprocess(context,
                                                            saveException);
                     if (result) {
                         handled = true;
@@ -239,7 +239,7 @@ public class ChainBase<C extends Context
      * {@link Chain}.  This method is package private, and is used only
      * for the unit tests.</p>
      */
-    Command<C>[] getCommands() {
+    List<Command<C>> getCommands() {
 
         return (commands);
 

Modified: commons/proper/chain/branches/version-2.0-work/src/test/java/org/apache/commons/chain/config/TestChain.java
                
URL: http://svn.apache.org/viewvc/commons/proper/chain/branches/version-2.0-work/src/t \
est/java/org/apache/commons/chain/config/TestChain.java?rev=1163743&r1=1163742&r2=1163743&view=diff
 ==============================================================================
--- commons/proper/chain/branches/version-2.0-work/src/test/java/org/apache/commons/chain/config/TestChain.java \
                (original)
+++ commons/proper/chain/branches/version-2.0-work/src/test/java/org/apache/commons/chain/config/TestChain.java \
Wed Aug 31 19:01:10 2011 @@ -17,7 +17,6 @@
 package org.apache.commons.chain.config;
 
 
-import org.apache.commons.chain.Command;
 import org.apache.commons.chain.impl.ChainBase;
 
 
@@ -29,11 +28,11 @@ import org.apache.commons.chain.impl.Cha
 public class TestChain extends ChainBase {
 
 
-    public Command[] getCommands() {
+    /*public Command[] getCommands() {
 
     return (commands);
 
-    }
+    }*/
 
 
 }

Modified: commons/proper/chain/branches/version-2.0-work/src/test/java/org/apache/commons/chain/impl/ChainBaseTestCase.java
                
URL: http://svn.apache.org/viewvc/commons/proper/chain/branches/version-2.0-work/src/t \
est/java/org/apache/commons/chain/impl/ChainBaseTestCase.java?rev=1163743&r1=1163742&r2=1163743&view=diff
 ==============================================================================
--- commons/proper/chain/branches/version-2.0-work/src/test/java/org/apache/commons/chain/impl/ChainBaseTestCase.java \
                (original)
+++ commons/proper/chain/branches/version-2.0-work/src/test/java/org/apache/commons/chain/impl/ChainBaseTestCase.java \
Wed Aug 31 19:01:10 2011 @@ -17,9 +17,12 @@
 package org.apache.commons.chain.impl;
 
 
+import java.util.List;
+
 import junit.framework.Test;
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
+
 import org.apache.commons.chain.Chain;
 import org.apache.commons.chain.Command;
 import org.apache.commons.chain.Context;
@@ -343,10 +346,10 @@ public class ChainBaseTestCase extends T
     // Verify the number of configured commands
     protected void checkCommandCount(int expected) {
         if (chain instanceof ChainBase) {
-            Command commands[] = ((ChainBase) chain).getCommands();
+            List<Command> commands = ((ChainBase) chain).getCommands();
             assertNotNull("getCommands() returned a non-null array",
                           commands);
-            assertEquals("Correct command count", expected, commands.length);
+            assertEquals("Correct command count", expected, commands.size());
         }
     }
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic