[logback-dev] svn commit: r2409 - in logback/trunk/logback-core/src: main/java/ch/qos/logback/core/rolling/helper test/java/ch/qos/logback/core/rolling/helper

noreply.ceki at qos.ch noreply.ceki at qos.ch
Mon Aug 3 23:33:41 CEST 2009


Author: ceki
Date: Mon Aug  3 23:33:41 2009
New Revision: 2409

Added:
   logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DatePatternAsRegexUtil.java
      - copied, changed from r2407, /logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DatePatternToRegex.java
Removed:
   logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DatePatternToRegex.java
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/FileNamePattern.java
   logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/DatePatternToRegexTest.java
   logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/FileNamePatternTest.java

Log:
- renamed toRegex methods asRegex
- unfinished work

Copied: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DatePatternAsRegexUtil.java (from r2407, /logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DatePatternToRegex.java)
==============================================================================
--- /logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DatePatternToRegex.java	(original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DatePatternAsRegexUtil.java	Mon Aug  3 23:33:41 2009
@@ -13,17 +13,17 @@
 import java.util.ArrayList;
 import java.util.List;
 
-public class DatePatternToRegex {
+public class DatePatternAsRegexUtil {
 
   final String datePattern;
   final int length;
 
-  DatePatternToRegex(String datePattern) {
+  DatePatternAsRegexUtil(String datePattern) {
     this.datePattern = datePattern;
     length = datePattern.length();
   }
 
-  String toRegex() {
+  String asRegex() {
     List<SDFToken> tokenList = tokenize();
     StringBuilder sb = new StringBuilder();
     for(SDFToken token: tokenList) {

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	Mon Aug  3 23:33:41 2009
@@ -67,15 +67,8 @@
     return (o instanceof Date);
   }
 
-  public String toRegex() {
-    DatePatternToRegex toRegex = new DatePatternToRegex(datePattern);
-    return toRegex.toRegex();
+  public String asRegex() {
+    DatePatternAsRegexUtil toRegex = new DatePatternAsRegexUtil(datePattern);
+    return toRegex.asRegex();
   }
-  
-  /**
-   * Set the date pattern.
-   */
-  // public void setDatePattern(String string) {
-  // datePattern = string;
-  // }
 }

Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileNamePattern.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileNamePattern.java	(original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileNamePattern.java	Mon Aug  3 23:33:41 2009
@@ -156,4 +156,22 @@
     }
     return buf.toString();
   }
+  
+  // Given date, convert this instance to  a regular expression 
+  String asRegex() {
+    StringBuilder buf = new StringBuilder();
+    Converter<Object> p = headTokenConverter;
+    while (p != null) {
+      if(p instanceof LiteralConverter) {
+        buf.append(p.convert(null));
+      } else if (p instanceof IntegerTokenConverter) {
+        buf.append("\\d{1,2}");
+      } else if(p instanceof DateTokenConverter) {
+        DateTokenConverter dtc = (DateTokenConverter) p;
+        xbuf.append(dtc.asRegex());
+      }
+      p = p.getNext();
+    }
+    return buf.toString();
+  }
 }

Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/DatePatternToRegexTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/DatePatternToRegexTest.java	(original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/DatePatternToRegexTest.java	Mon Aug  3 23:33:41 2009
@@ -75,7 +75,7 @@
   
   void verify(SimpleDateFormat sdf, Calendar calendar, DateTokenConverter dtc) {
     String expected = sdf.format(calendar.getTime());
-    String regex = dtc.toRegex();
+    String regex = dtc.asRegex();
     //System.out.println("expected="+expected);
     //System.out.println(regex);
     assertTrue("[" + expected + "] does not match regex [" + regex + "]",

Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/FileNamePatternTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/FileNamePatternTest.java	(original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/FileNamePatternTest.java	Mon Aug  3 23:33:41 2009
@@ -110,13 +110,19 @@
   public void asRegexByDate() {
     Calendar cal = Calendar.getInstance();
     cal.set(2003, 4, 20, 17, 55);
-    
     FileNamePattern fnp = new FileNamePattern("foo-%d{yyyy.MM.dd}-%i.txt", context);
-    
     String regex = fnp.asRegex(cal.getTime());
-    
     assertEquals("foo-2003.05.20-\\d{1,2}.txt", regex);
   }
-  
+
+  @Test
+  public void asRegex() {
+    Calendar cal = Calendar.getInstance();
+    cal.set(2003, 4, 20, 17, 55);
+    FileNamePattern fnp = new FileNamePattern("foo-%d{yyyy.MM.dd}-%i.txt", context);
+    String regex = fnp.asRegex();
+    assertEquals("foo-2003.05.20-\\d{1,2}.txt", regex);
+  }
+
 
 }


More information about the logback-dev mailing list