[logback-dev] svn commit: r918 - in logback/trunk/logback-core/src: main/java/ch/qos/logback/core/util test/java/ch/qos/logback/core/util

noreply.ceki at qos.ch noreply.ceki at qos.ch
Wed Nov 15 09:53:36 CET 2006


Author: ceki
Date: Wed Nov 15 09:53:36 2006
New Revision: 918

Modified:
   logback/trunk/logback-core/src/main/java/ch/qos/logback/core/util/Duration.java
   logback/trunk/logback-core/src/main/java/ch/qos/logback/core/util/FileSize.java
   logback/trunk/logback-core/src/main/java/ch/qos/logback/core/util/PropertySetter.java
   logback/trunk/logback-core/src/test/java/ch/qos/logback/core/util/PropertySetterTest.java

Log:
ongoing work on Duration and FileSize support

Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/util/Duration.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/util/Duration.java	(original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/util/Duration.java	Wed Nov 15 09:53:36 2006
@@ -34,11 +34,32 @@
     this.millis = millis;
   }
 
-  long getMilliSeconds() {
+  Duration buildByMilliseconds(double value) {
+    return new Duration((long) (value));
+  }
+  
+  Duration buildBySeconds(double value) {
+    return new Duration((long) (SECONDS_COEFFICIENT*value));
+  }
+
+  Duration buildByMinutes(double value) {
+    return new Duration((long) (MINUTES_COEFFICIENT*value));
+  }
+  
+  Duration buildByHours(double value) {
+    return new Duration((long) (HOURS_COEFFICIENT*value));
+  }
+
+  Duration buildByDays(double value) {
+    return new Duration((long) (DAYS_COEFFICIENT*value));
+  }
+  
+  
+  public long getMilliSeconds() {
     return millis;
   }
 
-  static Duration valueOf(String durationStr) {
+  public static Duration valueOf(String durationStr) {
     Matcher matcher = DURATION_PATTERN.matcher(durationStr);
 
     long coefficient;

Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/util/FileSize.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/util/FileSize.java	(original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/util/FileSize.java	Wed Nov 15 09:53:36 2006
@@ -34,11 +34,11 @@
     this.size = size;
   }
 
-  long getSize() {
+  public long getSize() {
     return size;
   }
 
-  static FileSize valueOf(String fileSizeStr) {
+  static public FileSize valueOf(String fileSizeStr) {
     Matcher matcher = FILE_SIZE_PATTERN.matcher(fileSizeStr);
 
     long coefficient;

Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/util/PropertySetter.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/util/PropertySetter.java	(original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/util/PropertySetter.java	Wed Nov 15 09:53:36 2006
@@ -113,7 +113,7 @@
     name = Introspector.decapitalize(name);
 
     PropertyDescriptor prop = getPropertyDescriptor(name);
-   
+
     if (prop == null) {
       addWarn("No such property [" + name + "] in " + objClass.getName() + ".");
     } else {
@@ -231,9 +231,11 @@
         return X_AS_PROPERTY;
       } else if ("java.lang".equals(p.getName())) {
         return X_AS_PROPERTY;
-      } else if(Duration.class.isAssignableFrom(clazz)) {
+      } else if (Duration.class.isAssignableFrom(clazz)) {
+        return X_AS_PROPERTY;
+      } else if (FileSize.class.isAssignableFrom(clazz)) {
         return X_AS_PROPERTY;
-      }else {
+      } else {
         return X_AS_COMPONENT;
       }
     }
@@ -289,7 +291,7 @@
 
     name = capitalizeFirstLetter(name);
     Method adderMethod = getMethod("add" + name);
- 
+
     if (adderMethod == null) {
       addError("No adder for property [" + name + "].");
       return;
@@ -309,7 +311,6 @@
       return;
     }
 
-
     if (arg == null) {
       addError("Conversion to type [" + paramTypes[0] + "] failed.");
     } else {
@@ -392,8 +393,10 @@
       } else if ("false".equalsIgnoreCase(v)) {
         return Boolean.FALSE;
       }
-    } else if(Duration.class.isAssignableFrom(type)) {
+    } else if (Duration.class.isAssignableFrom(type)) {
       return Duration.valueOf(val);
+    } else if (FileSize.class.isAssignableFrom(type)) {
+      return FileSize.valueOf(val);
     }
 
     return null;

Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/util/PropertySetterTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/util/PropertySetterTest.java	(original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/util/PropertySetterTest.java	Wed Nov 15 09:53:36 2006
@@ -20,6 +20,7 @@
     assertEquals(ContainmentType.AS_SINGLE_PROPERTY, setter.canContainComponent("Name"));
     
     assertEquals(ContainmentType.AS_SINGLE_PROPERTY, setter.canContainComponent("Duration"));
+    assertEquals(ContainmentType.AS_SINGLE_PROPERTY, setter.canContainComponent("fs"));
     
     assertEquals(ContainmentType.AS_SINGLE_PROPERTY, setter.canContainComponent("open"));
     assertEquals(ContainmentType.AS_SINGLE_PROPERTY, setter.canContainComponent("Open"));
@@ -114,7 +115,13 @@
     setter.setProperty("duration", "1.4 seconds");
     assertEquals(1400, house.getDuration().getMilliSeconds());
   }
-  
+
+  public void testFileSize() {
+    House house = new House();
+    PropertySetter setter = new PropertySetter(house);
+    setter.setProperty("fs", "2 kb");
+    assertEquals(2*1024, house.getFs().getSize());
+  }
 }
 
 class House {
@@ -125,6 +132,7 @@
   String camelCase;
   SwimmingPool pool;
   Duration duration;
+  FileSize fs;
   
   List<String> adjectiveList = new ArrayList<String>();
   List<Window> windowList = new ArrayList<Window>();
@@ -193,6 +201,14 @@
   public void setDuration(Duration duration) {
     this.duration = duration;
   }
+
+  public FileSize getFs() {
+    return fs;
+  }
+
+  public void setFs(FileSize fs) {
+    this.fs = fs;
+  }
 }
 
 class Door {



More information about the logback-dev mailing list