ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r723730 - /ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Replace.java
Date Fri, 05 Dec 2008 13:24:15 GMT
Author: bodewig
Date: Fri Dec  5 05:24:14 2008
New Revision: 723730

URL: http://svn.apache.org/viewvc?rev=723730&view=rev
Log:
Take advantage of JDK 1.4 (and 1.2, actually)

Modified:
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Replace.java

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Replace.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Replace.java?rev=723730&r1=723729&r2=723730&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Replace.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Replace.java Fri Dec  5 05:24:14
2008
@@ -31,9 +31,9 @@
 import java.io.OutputStreamWriter;
 import java.io.Reader;
 import java.io.Writer;
+import java.util.ArrayList;
 import java.util.Enumeration;
 import java.util.Properties;
-import java.util.Vector;
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.DirectoryScanner;
 import org.apache.tools.ant.Project;
@@ -62,7 +62,7 @@
     private File propertyFile = null;
     private File replaceFilterFile = null;
     private Properties properties = null;
-    private Vector replacefilters = new Vector();
+    private ArrayList replacefilters = new ArrayList();
 
     private File dir = null;
 
@@ -271,8 +271,7 @@
          */
         void flush() {
             replace();
-            // Avoid runtime problem on pre 1.4 when compiling post 1.4
-            outputBuffer.append(inputBuffer.toString());
+            outputBuffer.append(inputBuffer);
             inputBuffer.delete(0, inputBuffer.length());
         }
 
@@ -282,13 +281,14 @@
          *         replacement.
          */
         private int replace() {
-            int found = inputBuffer.toString().indexOf(token);
+            int found = inputBuffer.indexOf(token);
             int pos = -1;
+            final int tokenLength = token.length();
+            final int replaceValueLength = replaceValue.length();
             while (found >= 0) {
-                inputBuffer.replace(found, found + token.length(),
-                        replaceValue);
-                pos = found + replaceValue.length();
-                found = inputBuffer.toString().indexOf(token, pos);
+                inputBuffer.replace(found, found + tokenLength, replaceValue);
+                pos = found + replaceValueLength;
+                found = inputBuffer.indexOf(token, pos);
                 ++replaceCount;
             }
             return pos;
@@ -442,7 +442,7 @@
      */
     public void execute() throws BuildException {
 
-        Vector savedFilters = (Vector) replacefilters.clone();
+        ArrayList savedFilters = (ArrayList) replacefilters.clone();
         Properties savedProperties =
             properties == null ? null : (Properties) properties.clone();
 
@@ -546,7 +546,7 @@
             throws BuildException {
         for (int i = 0; i < replacefilters.size(); i++) {
             Replacefilter element =
-                (Replacefilter) replacefilters.elementAt(i);
+                (Replacefilter) replacefilters.get(i);
             element.validate();
         }
     }
@@ -653,7 +653,7 @@
      */
     private void flushFilterChain() {
         for (int i = 0; i < replacefilters.size(); i++) {
-            Replacefilter filter = (Replacefilter) replacefilters.elementAt(i);
+            Replacefilter filter = (Replacefilter) replacefilters.get(i);
             filter.flush();
         }
     }
@@ -664,7 +664,7 @@
      */
     private boolean processFilterChain() {
         for (int i = 0; i < replacefilters.size(); i++) {
-            Replacefilter filter = (Replacefilter) replacefilters.elementAt(i);
+            Replacefilter filter = (Replacefilter) replacefilters.get(i);
             if (!filter.process()) {
                 return false;
             }
@@ -681,7 +681,7 @@
     private StringBuffer buildFilterChain(StringBuffer inputBuffer) {
         StringBuffer buf = inputBuffer;
         for (int i = 0; i < replacefilters.size(); i++) {
-            Replacefilter filter = (Replacefilter) replacefilters.elementAt(i);
+            Replacefilter filter = (Replacefilter) replacefilters.get(i);
             filter.setInputBuffer(buf);
             buf = filter.getOutputBuffer();
         }
@@ -694,7 +694,7 @@
      */
     private void logFilterChain(String filename) {
         for (int i = 0; i < replacefilters.size(); i++) {
-            Replacefilter filter = (Replacefilter) replacefilters.elementAt(i);
+            Replacefilter filter = (Replacefilter) replacefilters.get(i);
             log("Replacing in " + filename + ": " + filter.getToken()
                     + " --> " + filter.getReplaceValue(), Project.MSG_VERBOSE);
         }
@@ -803,7 +803,7 @@
      */
     public Replacefilter createReplacefilter() {
         Replacefilter filter = new Replacefilter();
-        replacefilters.addElement(filter);
+        replacefilters.add(filter);
         return filter;
     }
 
@@ -814,7 +814,7 @@
      */
     private Replacefilter createPrimaryfilter() {
         Replacefilter filter = new Replacefilter();
-        replacefilters.insertElementAt(filter, 0);
+        replacefilters.add(0, filter);
         return filter;
     }
 
@@ -822,10 +822,12 @@
      * Replace occurrences of str1 in StringBuffer str with str2.
      */
     private void stringReplace(StringBuffer str, String str1, String str2) {
-        int found = str.toString().indexOf(str1);
+        int found = str.indexOf(str1);
+        final int str1Length = str1.length();
+        final int str2Length = str2.length();
         while (found >= 0) {
-            str.replace(found, found + str1.length(), str2);
-            found = str.toString().indexOf(str1, found + str2.length());
+            str.replace(found, found + str1Length, str2);
+            found = str.indexOf(str1, found + str2Length);
         }
     }
 



Mime
View raw message