Am Mo, den 10.11.2003 schrieb Shapira, Yoav um 18:20:
> Howdy,
> A couple of things (I haven't even read the substance of the patch,
> these are just style comments):
> - I'd prefer a diff instead of the whole file,

would that be something like the appended file?

> - It looked like there were tabs in the file?

yes.. there already were tabs in the file before I edited it.
I tried to figure out what kind of formatting-style is used and
to emulate that.

-- 
have fun,
Sven Helmberger,
Amaris Softwareentwicklungsges. mbH


--- jakarta-log4j-1.2.8/src/java/org/apache/log4j/NDC.java	2003-02-20 02:07:34.000000000 +0100
+++ /home/sven/src/log4j/org/apache/log4j/NDC.java	2003-11-10 17:56:58.000000000 +0100
@@ -200,7 +200,22 @@
   String get() {
     Stack s = (Stack) ht.get(Thread.currentThread());
     if(s != null && !s.isEmpty()) 
-      return ((DiagnosticContext) s.peek()).fullMessage;
+		{
+			DiagnosticContext top=(DiagnosticContext) s.peek();
+			if (top.fullMessage == null) {
+			
+				StringBuffer buf=new StringBuffer();
+
+				for (Enumeration e=s.elements(); e.hasMoreElements(); )
+				{
+					DiagnosticContext dc=(DiagnosticContext)e.nextElement();
+					buf.append(dc.message).append(' ');
+				}
+
+				top.fullMessage=buf.toString();			
+			}
+      return top.fullMessage;
+		}
     else
       return null;
   }
@@ -278,6 +293,24 @@
   public
   static
   String pop() {
+		return popObject().toString();
+  }
+
+	/**
+     Clients should call this method before leaving a diagnostic
+     context.
+
+     <p>The returned value is the value that was pushed last. If no
+     context is available, then the empty string "" is returned.
+	 
+	   The difference to [EMAIL PROTECTED] #pop()} is that is gives the possibility
+	   to pop the context information without evaluating the String 
+	   representation.
+		 
+	   @see #pop()	 */
+  public
+  static
+	Object popObject() {
     Thread key = Thread.currentThread();
     Stack stack = (Stack) ht.get(key);
     if(stack != null && !stack.isEmpty()) 
@@ -299,10 +332,16 @@
   public
   static
   String peek() {
+		return peekObject().toString();
+  }
+
+	public
+  static
+  Object peekObject() {
     Thread key = Thread.currentThread();
     Stack stack = (Stack) ht.get(key);
     if(stack != null && !stack.isEmpty())
-      return ((DiagnosticContext) stack.peek()).message;
+      return ((DiagnosticContext) stack.peek()).message.toString();
     else
       return "";
   }
@@ -317,21 +356,33 @@
   public
   static
   void push(String message) {
+		
+		// Push string argument as Object
+		push((Object)message);
+	}
+	
+	/**
+	  Push new diagnostic context information for the current thread.
+	  This variant takes an Object-message and calls the object's
+	  toString() if the content is needed.
+	  This late evaluation is an optimization for context information
+	  which is costly to convert into a String representation.
+    
+    @param message The new diagnostic context information. 
+	  @see #push(String) */
+	public
+	static
+	void push(Object message) {
     Thread key = Thread.currentThread();
     Stack stack = (Stack) ht.get(key);
-      
-    if(stack == null) {
-      DiagnosticContext dc = new DiagnosticContext(message, null);      
+    DiagnosticContext dc = new DiagnosticContext(message);
+		
+    if(stack == null){
+			
       stack = new Stack();
       ht.put(key, stack);
-      stack.push(dc);
-    } else if (stack.isEmpty()) {
-      DiagnosticContext dc = new DiagnosticContext(message, null);            
-      stack.push(dc);
-    } else {
-      DiagnosticContext parent = (DiagnosticContext) stack.peek();
-      stack.push(new DiagnosticContext(message, parent));
-    }    
+    }
+		stack.push(dc);
   }
 
   /**
@@ -399,17 +450,12 @@
   
   // =====================================================================
    private static class DiagnosticContext {
-
+		 
     String fullMessage;
-    String message;
+    Object message;
     
-    DiagnosticContext(String message, DiagnosticContext parent) {
+    DiagnosticContext(Object message) {
       this.message = message;
-      if(parent != null) {
-	fullMessage = parent.fullMessage + ' ' + message;
-      } else {
-	fullMessage = message;
-      }
     }
   }
 }

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to