|
I included the RegEx "flavor" in the factory method name for a reason -
someone might want to use one of the other flavors (Awk, etc). Adrian Crum Sandglass Software www.sandglass-software.com On 11/17/2013 6:35 AM, [hidden email] wrote: > 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()) { > > |
|
Administrator
|
OK, I renames it createOrGetPerl5CompiledPattern
I thought also about naming PatternFactory.java OroPatternFactory.java for 2 reasons: 1) in case we would want to create a RegexPatternFactory.java for Java regex. 2) PatternFactory is a bit confusing as a name, since at 1st glance it could evoke the Factory Patten But then thought 1) it would be better to have all in a solle PatternFactory class 2) was not an issue after all, though maybe we could finally rename it RegexPatternFactory.java with the idea that it could possibly contains all caches implementation in the future. It would then be easy to switch from one to the other... if needed later... Jacques On Sunday, November 17, 2013 1:28 PM Adrian Crum <[hidden email]> wrote: > I included the RegEx "flavor" in the factory method name for a reason - > someone might want to use one of the other flavors (Awk, etc). > > Adrian Crum > Sandglass Software > www.sandglass-software.com > > On 11/17/2013 6:35 AM, [hidden email] wrote: >> 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()) { |
|
RegexPatternFactory is a good name.
Thank you for the fixes. Adrian Crum Sandglass Software www.sandglass-software.com On 11/17/2013 8:51 AM, Jacques Le Roux wrote: > OK, I renames it createOrGetPerl5CompiledPattern > > I thought also about naming PatternFactory.java OroPatternFactory.java for 2 reasons: > 1) in case we would want to create a RegexPatternFactory.java for Java regex. > 2) PatternFactory is a bit confusing as a name, since at 1st glance it could evoke the Factory Patten > > But then thought > 1) it would be better to have all in a solle PatternFactory class > 2) was not an issue after all, though maybe we could finally rename it RegexPatternFactory.java with the idea that it could possibly contains all caches implementation in the future. It would then be easy to switch from one to the other... if needed later... > > Jacques > > On Sunday, November 17, 2013 1:28 PM Adrian Crum <[hidden email]> wrote: >> I included the RegEx "flavor" in the factory method name for a reason - >> someone might want to use one of the other flavors (Awk, etc). >> >> Adrian Crum >> Sandglass Software >> www.sandglass-software.com >> >> On 11/17/2013 6:35 AM, [hidden email] wrote: >>> 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()) { |
| Free forum by Nabble | Edit this page |
