svn commit: r1542709 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/util/PatternFactory.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1542709 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/util/PatternFactory.java

jleroux@apache.org
Author: jleroux
Date: Sun Nov 17 11:35:49 2013
New Revision: 1542709

URL: http://svn.apache.org/r1542709
Log:
Changes module and method names
Uses | instead of & in compile mask options
Adds a comment about when to use or not

Added:
    ofbiz/trunk/framework/base/src/org/ofbiz/base/util/PatternFactory.java
      - copied, changed from r1542558, ofbiz/trunk/framework/base/src/org/ofbiz/base/util/PatternFactory.java

Copied: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/PatternFactory.java (from r1542558, ofbiz/trunk/framework/base/src/org/ofbiz/base/util/PatternFactory.java)
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/PatternFactory.java?p2=ofbiz/trunk/framework/base/src/org/ofbiz/base/util/PatternFactory.java&p1=ofbiz/trunk/framework/base/src/org/ofbiz/base/util/PatternFactory.java&r1=1542558&r2=1542709&rev=1542709&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/PatternFactory.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/PatternFactory.java Sun Nov 17 11:35:49 2013
@@ -25,29 +25,30 @@ import org.ofbiz.base.util.cache.UtilCac
 
 /**
  * A RegEx compiled pattern factory.
- *
+ *
  */
 public class PatternFactory {
 
-    public static final String module = CompilerMatcher.class.getName();
+    public static final String module = PatternFactory.class.getName();
     private static final UtilCache<String, Pattern> compiledPerl5Patterns = UtilCache.createUtilCache("regularExpression.compiledPerl5Patterns", false);
 
     /**
      * Compiles and caches a Perl5 regexp pattern for the given string pattern.
-     *
+     * This would be of no benefits (and may bloat memory usage) if stringPattern is never the same.
      * @param stringPattern a Perl5 pattern string
      * @param caseSensitive case sensitive true/false
      * @return a <code>Pattern</code> instance for the given string pattern
      * @throws MalformedPatternException
      */
-    public Pattern getPerl5Instance(String stringPattern, boolean caseSensitive) throws MalformedPatternException {
+
+    public Pattern createOrGetCompiledPattern(String stringPattern, boolean caseSensitive) throws MalformedPatternException {
         Pattern pattern = compiledPerl5Patterns.get(stringPattern);
         if (pattern == null) {
             Perl5Compiler compiler = new Perl5Compiler();
             if (caseSensitive) {
-                pattern = compiler.compile(stringPattern, Perl5Compiler.READ_ONLY_MASK);
+                pattern = compiler.compile(stringPattern, Perl5Compiler.READ_ONLY_MASK); // READ_ONLY_MASK guarantees immutability
             } else {
-                pattern = compiler.compile(stringPattern, Perl5Compiler.CASE_INSENSITIVE_MASK & Perl5Compiler.READ_ONLY_MASK);
+                pattern = compiler.compile(stringPattern, Perl5Compiler.CASE_INSENSITIVE_MASK | Perl5Compiler.READ_ONLY_MASK);
             }
             pattern = compiledPerl5Patterns.putIfAbsentAndGet(stringPattern, pattern);
             if (Debug.verboseOn()) {