openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1759273 - in /openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/ openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/ openjpa-kernel/src/main/java/org/apa...
Date Mon, 05 Sep 2016 14:10:33 GMT
Author: struberg
Date: Mon Sep  5 14:10:33 2016
New Revision: 1759273

URL: http://svn.apache.org/viewvc?rev=1759273&view=rev
Log:
OPENJPA-2662 get rid of serp.util.Strings#replace

Modified:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ApplicationIdTool.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/MatchesExpression.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/BlacklistClassResolver.java
    openjpa/trunk/openjpa-kernel/src/test/java/org/apache/openjpa/enhance/TestAsmAdaptor.java
    openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ConfigurationImpl.java
    openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Options.java
    openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/StringUtil.java
    openjpa/trunk/openjpa-lib/src/test/java/org/apache/openjpa/lib/util/StringUtilTest.java

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java?rev=1759273&r1=1759272&r2=1759273&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java
Mon Sep  5 14:10:33 2016
@@ -51,13 +51,13 @@ import org.apache.openjpa.kernel.Filters
 import org.apache.openjpa.kernel.MixedLockLevels;
 import org.apache.openjpa.kernel.exps.Literal;
 import org.apache.openjpa.lib.util.Localizer;
+import org.apache.openjpa.lib.util.StringUtil;
 import org.apache.openjpa.meta.JavaTypes;
 import org.apache.openjpa.util.OpenJPAException;
 import org.apache.openjpa.util.StoreException;
 import org.apache.openjpa.util.UnsupportedException;
 import org.apache.openjpa.util.UserException;
 
-import serp.util.Strings;
 
 /**
  * Dictionary for IBM DB2 database.
@@ -759,9 +759,9 @@ public class DB2Dictionary
     private String addCastAsString(String func, String target, 
             String asString) {
         String fstring = func;
-        if (func.indexOf(target) != -1)
-            fstring = Strings.replace(
-                func, target, "CAST(" + target + asString + ")");
+        if (func.indexOf(target) != -1) {
+            fstring = StringUtil.replace(func, target, "CAST(" + target + asString + ")");
+        }
         return fstring;
     }
 

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ApplicationIdTool.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ApplicationIdTool.java?rev=1759273&r1=1759272&r2=1759273&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ApplicationIdTool.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ApplicationIdTool.java
Mon Sep  5 14:10:33 2016
@@ -48,6 +48,7 @@ import org.apache.openjpa.lib.util.Files
 import org.apache.openjpa.lib.util.J2DoPrivHelper;
 import org.apache.openjpa.lib.util.Localizer;
 import org.apache.openjpa.lib.util.Options;
+import org.apache.openjpa.lib.util.StringUtil;
 import org.apache.openjpa.meta.AccessCode;
 import org.apache.openjpa.meta.ClassMetaData;
 import org.apache.openjpa.meta.DelegatingMetaDataFactory;
@@ -436,9 +437,10 @@ public class ApplicationIdTool {
         if (isInnerClass()) {
             // indent the entire code block one level to make it
             // a propertly indented innder class
-            _code = code.getTab() + Strings.replace(_code,
-                J2DoPrivHelper.getLineSeparator(),
-                J2DoPrivHelper.getLineSeparator() + code.getTab());
+            _code = code.getTab() +
+                    StringUtil.replace(_code,
+                                       J2DoPrivHelper.getLineSeparator(),
+                                       J2DoPrivHelper.getLineSeparator() + code.getTab());
         }
 
         return true;

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/MatchesExpression.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/MatchesExpression.java?rev=1759273&r1=1759272&r2=1759273&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/MatchesExpression.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/MatchesExpression.java
Mon Sep  5 14:10:33 2016
@@ -20,7 +20,7 @@ package org.apache.openjpa.kernel.exps;
 
 import org.apache.openjpa.lib.util.Localizer;
 import org.apache.openjpa.lib.util.SimpleRegex;
-import serp.util.Strings;
+import org.apache.openjpa.lib.util.StringUtil;
 
 /**
  * Expression that compares two others.
@@ -69,8 +69,8 @@ class MatchesExpression
 
         // now translate from the single and multi character escape
         // sequences into an escape that conforms to the regexp syntax
-        str = Strings.replace(str, _multi, ".*");
-        str = Strings.replace(str, _single, ".");
+        str = StringUtil.replace(str, _multi, ".*");
+        str = StringUtil.replace(str, _single, ".");
 
         SimpleRegex re = new SimpleRegex(str, uncase);
         boolean matches = re.matches(o1.toString());

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/BlacklistClassResolver.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/BlacklistClassResolver.java?rev=1759273&r1=1759272&r2=1759273&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/BlacklistClassResolver.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/BlacklistClassResolver.java
Mon Sep  5 14:10:33 2016
@@ -60,3 +60,5 @@ public class BlacklistClassResolver {
     }
 }
 
+
+

Modified: openjpa/trunk/openjpa-kernel/src/test/java/org/apache/openjpa/enhance/TestAsmAdaptor.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/test/java/org/apache/openjpa/enhance/TestAsmAdaptor.java?rev=1759273&r1=1759272&r2=1759273&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/test/java/org/apache/openjpa/enhance/TestAsmAdaptor.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/test/java/org/apache/openjpa/enhance/TestAsmAdaptor.java
Mon Sep  5 14:10:33 2016
@@ -247,3 +247,6 @@ public class TestAsmAdaptor
         }
     }
 }
+
+
+

Modified: openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ConfigurationImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ConfigurationImpl.java?rev=1759273&r1=1759272&r2=1759273&view=diff
==============================================================================
--- openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ConfigurationImpl.java
(original)
+++ openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ConfigurationImpl.java
Mon Sep  5 14:10:33 2016
@@ -68,7 +68,6 @@ import org.apache.openjpa.lib.util.Parse
 import org.apache.openjpa.lib.util.Services;
 import org.apache.openjpa.lib.util.StringDistance;
 import org.apache.openjpa.lib.util.StringUtil;
-import serp.util.Strings;
 
 /**
  * Default implementation of the {@link Configuration} interface.

Modified: openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Options.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Options.java?rev=1759273&r1=1759272&r2=1759273&view=diff
==============================================================================
--- openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Options.java (original)
+++ openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Options.java Mon Sep
 5 14:10:33 2016
@@ -34,8 +34,6 @@ import java.util.TreeSet;
 
 import org.apache.commons.lang3.StringUtils;
 
-import serp.util.Strings;
-
 /**
  * A specialization of the {@link Properties} map type with the added
  * abilities to read application options from the command line and to

Modified: openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/StringUtil.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/StringUtil.java?rev=1759273&r1=1759272&r2=1759273&view=diff
==============================================================================
--- openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/StringUtil.java (original)
+++ openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/StringUtil.java Mon
Sep  5 14:10:33 2016
@@ -16,6 +16,8 @@
  */
 package org.apache.openjpa.lib.util;
 
+import org.apache.commons.lang3.StringUtils;
+
 import java.util.ArrayList;
 import java.util.List;
 
@@ -83,4 +85,21 @@ public final class StringUtil {
         return ret.toArray(new String[ret.size()]);
     }
 
+    /**
+     * Replace all instances of <code>from</code> in <code>str</code>
+     * with <code>to</code>.
+     *
+     * @param str the candidate string to replace
+     * @param from the token to replace
+     * @param to the new token
+     * @return the string with all the replacements made
+     */
+    public static String replace(String str, String from, String to) {
+        if (from.equals(to)) {
+            return str;
+        }
+        String[] split = split(str, from, Integer.MAX_VALUE);
+        return StringUtils.join(split, to);
+    }
+
 }

Modified: openjpa/trunk/openjpa-lib/src/test/java/org/apache/openjpa/lib/util/StringUtilTest.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-lib/src/test/java/org/apache/openjpa/lib/util/StringUtilTest.java?rev=1759273&r1=1759272&r2=1759273&view=diff
==============================================================================
--- openjpa/trunk/openjpa-lib/src/test/java/org/apache/openjpa/lib/util/StringUtilTest.java
(original)
+++ openjpa/trunk/openjpa-lib/src/test/java/org/apache/openjpa/lib/util/StringUtilTest.java
Mon Sep  5 14:10:33 2016
@@ -21,6 +21,7 @@ import java.util.concurrent.TimeUnit;
 import org.junit.Assert;
 import org.junit.Ignore;
 import org.junit.Test;
+import serp.util.Strings;
 
 public class StringUtilTest {
 
@@ -70,6 +71,22 @@ public class StringUtilTest {
         }
 
         long stop = System.nanoTime();
+        System.out.println("took: " + TimeUnit.NANOSECONDS.toMillis(stop - start));
+    }
+
+    @Test
+    @Ignore("only needed for manual performance tests")
+    public void testStringsReplacePerformance() {
+        String val = "This is my fnx test suite for fnx replacement to fnx=fnx";
+
+        long start = System.nanoTime();
+        for (int i = 1; i < 10000000; i++) {
+            //X Strings.replace(val, "fnx", "weirdo function");
+            //X val.replace("fnx", "weirdo function");
+            StringUtil.replace(val, "fnx", "weirdo function");
+        }
+
+        long stop = System.nanoTime();
         System.out.println("took: " + TimeUnit.NANOSECONDS.toMillis(stop - start));
     }
 }



Mime
View raw message