[slf4j-dev] svn commit: r552 - in slf4j/trunk/src/java/org/slf4j: . impl

ceki at slf4j.org ceki at slf4j.org
Thu Feb 16 18:01:18 CET 2006


Author: ceki
Date: Thu Feb 16 18:01:17 2006
New Revision: 552

Modified:
   slf4j/trunk/src/java/org/slf4j/IMarkerFactory.java
   slf4j/trunk/src/java/org/slf4j/Marker.java
   slf4j/trunk/src/java/org/slf4j/impl/BasicMarker.java
   slf4j/trunk/src/java/org/slf4j/impl/BasicMarkerFactory.java
Log:

- added the exists method IMarkerFactory interface
- added contains(String) method to Marker interface
- Corresponding additions to BasicMarkerFactory and BasicMarker

Modified: slf4j/trunk/src/java/org/slf4j/IMarkerFactory.java
==============================================================================
--- slf4j/trunk/src/java/org/slf4j/IMarkerFactory.java	(original)
+++ slf4j/trunk/src/java/org/slf4j/IMarkerFactory.java	Thu Feb 16 18:01:17 2006
@@ -57,4 +57,12 @@
    * @return a Marker instance
    */
   Marker getMarker(String name);
+  
+  /**
+   * Checks if the marker with the name already exists. If name is null, then false 
+   * is returned.
+   * 
+   * @return true id the marker exists, false otherwise. 
+   */
+  boolean exists(String name);
 }

Modified: slf4j/trunk/src/java/org/slf4j/Marker.java
==============================================================================
--- slf4j/trunk/src/java/org/slf4j/Marker.java	(original)
+++ slf4j/trunk/src/java/org/slf4j/Marker.java	Thu Feb 16 18:01:17 2006
@@ -102,6 +102,18 @@
    * @return Whether this marker contains the other marker.
    */
   public boolean contains(Marker other);
+
+  
+  
+  /**
+   * Does this marker contain the marker named 'name'? 
+   * 
+   * If 'name' is null the returned value is always false.
+   * 
+   * @param other The marker to test for inclusion.
+   * @return Whether this marker contains the other marker.
+   */
+  public boolean contains(String name);
   
 //  void makeImmutable();
 //  public boolean isImmutable();

Modified: slf4j/trunk/src/java/org/slf4j/impl/BasicMarker.java
==============================================================================
--- slf4j/trunk/src/java/org/slf4j/impl/BasicMarker.java	(original)
+++ slf4j/trunk/src/java/org/slf4j/impl/BasicMarker.java	Thu Feb 16 18:01:17 2006
@@ -33,6 +33,7 @@
 
 package org.slf4j.impl;
 
+import org.slf4j.IMarkerFactory;
 import org.slf4j.Marker;
 
 import java.util.Collections;
@@ -54,11 +55,13 @@
  * @author Ceki Gülcü
  */
 public class BasicMarker implements Marker {
-  String name;
+  final String name;
   List children;
-
-  BasicMarker(String name) {
+  final IMarkerFactory factory;
+  
+  BasicMarker(String name, IMarkerFactory factory) {
     this.name = name;
+    this.factory = factory;
   }
 
   public String getName() {
@@ -123,4 +126,17 @@
     }
     return false;
   }
+  
+  public boolean contains(String name) {
+    if(name == null) {
+      return false;
+    }
+    if(factory.exists(name)) {
+      Marker other = factory.getMarker(name);
+      return contains(other);     
+    } else {
+      return false;
+    }
+  }
+
 }

Modified: slf4j/trunk/src/java/org/slf4j/impl/BasicMarkerFactory.java
==============================================================================
--- slf4j/trunk/src/java/org/slf4j/impl/BasicMarkerFactory.java	(original)
+++ slf4j/trunk/src/java/org/slf4j/impl/BasicMarkerFactory.java	Thu Feb 16 18:01:17 2006
@@ -75,9 +75,20 @@
 
     Marker marker = (Marker) markerMap.get(name);
     if (marker == null) {
-      marker = new BasicMarker(name);
+      marker = new BasicMarker(name, this);
       markerMap.put(name, marker);
     }
     return marker;
   }
+  
+  /**
+   * Does the name marked already exist?
+   */
+  public synchronized boolean exists(String name) {
+    if (name == null) {
+      return false;
+    }
+    return markerMap.containsKey(name);
+  }
+  
 }



More information about the slf4j-dev mailing list