[logback-dev] svn commit: r2412 - logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper
noreply.ceki at qos.ch
noreply.ceki at qos.ch
Wed Aug 5 17:08:20 CEST 2009
Author: ceki
Date: Wed Aug 5 17:08:20 2009
New Revision: 2412
Added:
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DatePatternToRegexUtil.java
- copied, changed from r2411, /logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DatePatternAsRegexUtil.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/SequenceToRegex4SDF.java
- copied, changed from r2411, /logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/SDFToken.java
Removed:
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DatePatternAsRegexUtil.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/SDFToken.java
Modified:
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DateTokenConverter.java
Log:
- better class names
- added a few comments
Copied: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DatePatternToRegexUtil.java (from r2411, /logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DatePatternAsRegexUtil.java)
==============================================================================
--- /logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DatePatternAsRegexUtil.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DatePatternToRegexUtil.java Wed Aug 5 17:08:20 2009
@@ -10,45 +10,54 @@
package ch.qos.logback.core.rolling.helper;
+import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
-public class DatePatternAsRegexUtil {
+/**
+ * This class is concerned with computing a regex corresponding to a date
+ * pattern (in {@link SimpleDateFormat} format).
+ *
+ * @author Ceki Gülcü
+ *
+ */
+public class DatePatternToRegexUtil {
final String datePattern;
final int length;
- DatePatternAsRegexUtil(String datePattern) {
+ DatePatternToRegexUtil(String datePattern) {
this.datePattern = datePattern;
length = datePattern.length();
}
String asRegex() {
- List<SDFToken> tokenList = tokenize();
+ List<SequenceToRegex4SDF> sequenceList = tokenize();
StringBuilder sb = new StringBuilder();
- for(SDFToken token: tokenList) {
- sb.append(token.toRegex());
+ for (SequenceToRegex4SDF seq : sequenceList) {
+ sb.append(seq.toRegex());
}
return sb.toString();
}
- private List<SDFToken> tokenize() {
- List<SDFToken> tokenList = new ArrayList<SDFToken>();
- SDFToken token = null;
+ private List<SequenceToRegex4SDF> tokenize() {
+ List<SequenceToRegex4SDF> sequenceList = new ArrayList<SequenceToRegex4SDF>();
+ SequenceToRegex4SDF sequence = null;
for (int i = 0; i < length; i++) {
char t = datePattern.charAt(i);
- if (token == null || token.c != t) {
- token = addNewToken(tokenList, t);
+ if (sequence == null || sequence.c != t) {
+ sequence = addNewSequence(sequenceList, t);
} else {
- token.inc();
+ sequence.inc();
}
}
- return tokenList;
+ return sequenceList;
}
- SDFToken addNewToken(List<SDFToken> tokenList, char t) {
- SDFToken token = new SDFToken(t);
- tokenList.add(token);
+ SequenceToRegex4SDF addNewSequence(List<SequenceToRegex4SDF> sequenceList,
+ char t) {
+ SequenceToRegex4SDF token = new SequenceToRegex4SDF(t);
+ sequenceList.add(token);
return token;
}
}
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DateTokenConverter.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DateTokenConverter.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DateTokenConverter.java Wed Aug 5 17:08:20 2009
@@ -68,7 +68,7 @@
}
public String asRegex() {
- DatePatternAsRegexUtil toRegex = new DatePatternAsRegexUtil(datePattern);
+ DatePatternToRegexUtil toRegex = new DatePatternToRegexUtil(datePattern);
return toRegex.asRegex();
}
}
Copied: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/SequenceToRegex4SDF.java (from r2411, /logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/SDFToken.java)
==============================================================================
--- /logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/SDFToken.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/SequenceToRegex4SDF.java Wed Aug 5 17:08:20 2009
@@ -9,11 +9,18 @@
*/
package ch.qos.logback.core.rolling.helper;
-class SDFToken {
+/**
+ * This class supports mapping tokens (set of same character sequences) to
+ * regular expressions as appropriate for SimpleDateFormatter.
+ *
+ * @author ceki
+ *
+ */
+class SequenceToRegex4SDF {
final char c;
int occurrences;
- public SDFToken(char c) {
+ public SequenceToRegex4SDF(char c) {
this.c = c;
this.occurrences = 1;
}
@@ -47,7 +54,7 @@
case 'S':
return number(occurrences);
case 'E':
- return ".{3,12}";
+ return ".{3,12}";
case 'a':
return ".{2}";
case 'z':
@@ -67,9 +74,9 @@
@Override
public String toString() {
- return c+"("+occurrences+")";
+ return c + "(" + occurrences + ")";
}
-
+
private String number(int occurences) {
return "\\d{" + occurrences + "}";
}
More information about the logback-dev
mailing list