You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2014/03/05 17:09:02 UTC
svn commit: r1574557 -
/commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/parser/RegexFTPFileEntryParserImpl.java
Author: sebb
Date: Wed Mar 5 16:09:02 2014
New Revision: 1574557
URL: http://svn.apache.org/r1574557
Log:
Constructors should not call overrideable methods.
Add setRegex(regex, flags) method
Modified:
commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/parser/RegexFTPFileEntryParserImpl.java
Modified: commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/parser/RegexFTPFileEntryParserImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/parser/RegexFTPFileEntryParserImpl.java?rev=1574557&r1=1574556&r2=1574557&view=diff
==============================================================================
--- commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/parser/RegexFTPFileEntryParserImpl.java (original)
+++ commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/parser/RegexFTPFileEntryParserImpl.java Wed Mar 5 16:09:02 2014
@@ -69,7 +69,7 @@ public abstract class RegexFTPFileEntryP
public RegexFTPFileEntryParserImpl(String regex) {
super();
- setRegex(regex);
+ compileRegex(regex, 0);
}
/**
@@ -143,14 +143,41 @@ public abstract class RegexFTPFileEntryP
* @since 2.0
* @throws IllegalArgumentException if the regex cannot be compiled
*/
- public boolean setRegex(String regex) {
+ public boolean setRegex(final String regex) {
+ compileRegex(regex, 0);
+ return true;
+ }
+
+
+ /**
+ * Alter the current regular expression being utilised for entry parsing
+ * and create a new {@link Pattern} instance.
+ * @param regex The new regular expression
+ * @param flags the flags to apply, see {@link Pattern#compile(String, int)}. Use 0 for none.
+ * @return true
+ * @since 3.4
+ * @throws IllegalArgumentException if the regex cannot be compiled
+ */
+ public boolean setRegex(final String regex, final int flags) {
+ compileRegex(regex, flags);
+ return true;
+ }
+
+ /**
+ * Compile the regex and store the {@link Pattern}.
+ *
+ * This is an internal method to do the work so the constructor does not
+ * have to call an overrideable method.
+ *
+ * @param regex the expression to compile
+ * @param flags the flags to apply, see {@link Pattern#compile(String, int)}. Use 0 for none.
+ * @throws IllegalArgumentException if the regex cannot be compiled
+ */
+ private void compileRegex(final String regex, final int flags) {
try {
- pattern = Pattern.compile(regex);
- return true;
+ pattern = Pattern.compile(regex, flags);
} catch (PatternSyntaxException pse) {
- throw new IllegalArgumentException("Unparseable regex supplied: "
- + regex);
+ throw new IllegalArgumentException("Unparseable regex supplied: " + regex);
}
}
-
}