logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1593069 - /logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/spi/DefaultThreadContextStack.java
Date Wed, 07 May 2014 17:06:41 GMT
Author: ggregory
Date: Wed May  7 17:06:41 2014
New Revision: 1593069

URL: http://svn.apache.org/r1593069
Log:
Sort methods in AB order.

Modified:
    logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/spi/DefaultThreadContextStack.java

Modified: logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/spi/DefaultThreadContextStack.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/spi/DefaultThreadContextStack.java?rev=1593069&r1=1593068&r2=1593069&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/spi/DefaultThreadContextStack.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/spi/DefaultThreadContextStack.java
Wed May  7 17:06:41 2014
@@ -42,43 +42,29 @@ public class DefaultThreadContextStack i
     }
 
     @Override
-    public String pop() {
+    public boolean add(final String s) {
         if (!useStack) {
-            return "";
+            return false;
         }
         final List<String> list = stack.get();
-        if (list == null || list.size() == 0) {
-            throw new NoSuchElementException("The ThreadContext stack is empty");
-        }
-        final List<String> copy = new ArrayList<String>(list);
-        final int last = copy.size() - 1;
-        final String result = copy.remove(last);
+        final List<String> copy = list == null ? new ArrayList<String>()
+                : new ArrayList<String>(list);
+        copy.add(s);
         stack.set(Collections.unmodifiableList(copy));
-        return result;
-    }
-
-    @Override
-    public String peek() {
-        final List<String> list = stack.get();
-        if (list == null || list.size() == 0) {
-            return null;
-        }
-        final int last = list.size() - 1;
-        return list.get(last);
+        return true;
     }
 
     @Override
-    public void push(final String message) {
-        if (!useStack) {
-            return;
+    public boolean addAll(final Collection<? extends String> strings) {
+        if (!useStack || strings.isEmpty()) {
+            return false;
         }
-        add(message);
-    }
-
-    @Override
-    public int getDepth() {
         final List<String> list = stack.get();
-        return list == null ? 0 : list.size();
+        final List<String> copy = list == null ? new ArrayList<String>()
+                : new ArrayList<String>(list);
+        copy.addAll(strings);
+        stack.set(Collections.unmodifiableList(copy));
+        return true;
     }
 
     @Override
@@ -91,21 +77,24 @@ public class DefaultThreadContextStack i
     }
 
     @Override
-    public void trim(final int depth) {
-        if (depth < 0) {
-            throw new IllegalArgumentException(
-                    "Maximum stack depth cannot be negative");
+    public void clear() {
+        stack.remove();
+    }
+
+    @Override
+    public boolean contains(final Object o) {
+        final List<String> result = stack.get();
+        return result != null && result.contains(o);
+    }
+
+    @Override
+    public boolean containsAll(final Collection<?> objects) {
+        if (objects.isEmpty()) { // quick check before accessing the ThreadLocal
+            return true; // looks counter-intuitive, but see
+                         // j.u.AbstractCollection
         }
         final List<String> list = stack.get();
-        if (list == null) {
-            return;
-        }
-        final List<String> copy = new ArrayList<String>();
-        final int count = Math.min(depth, list.size());
-        for (int i = 0; i < count; i++) {
-            copy.add(list.get(i));
-        }
-        stack.set(copy);
+        return list != null && list.containsAll(objects);
     }
 
     @Override
@@ -118,14 +107,9 @@ public class DefaultThreadContextStack i
     }
 
     @Override
-    public void clear() {
-        stack.remove();
-    }
-
-    @Override
-    public int size() {
-        final List<String> result = stack.get();
-        return result == null ? 0 : result.size();
+    public int getDepth() {
+        final List<String> list = stack.get();
+        return list == null ? 0 : list.size();
     }
 
     @Override
@@ -135,12 +119,6 @@ public class DefaultThreadContextStack i
     }
 
     @Override
-    public boolean contains(final Object o) {
-        final List<String> result = stack.get();
-        return result != null && result.contains(o);
-    }
-
-    @Override
     public Iterator<String> iterator() {
         final List<String> immutable = stack.get();
         if (immutable == null) {
@@ -151,37 +129,37 @@ public class DefaultThreadContextStack i
     }
 
     @Override
-    public Object[] toArray() {
-        final List<String> result = stack.get();
-        if (result == null) {
-            return new String[0];
+    public String peek() {
+        final List<String> list = stack.get();
+        if (list == null || list.size() == 0) {
+            return null;
         }
-        return result.toArray(new Object[result.size()]);
+        final int last = list.size() - 1;
+        return list.get(last);
     }
 
     @Override
-    public <T> T[] toArray(final T[] ts) {
-        final List<String> result = stack.get();
-        if (result == null) {
-            if (ts.length > 0) { // as per the contract of j.u.List#toArray(T[])
-                ts[0] = null;
-            }
-            return ts;
+    public String pop() {
+        if (!useStack) {
+            return "";
         }
-        return result.toArray(ts);
+        final List<String> list = stack.get();
+        if (list == null || list.size() == 0) {
+            throw new NoSuchElementException("The ThreadContext stack is empty");
+        }
+        final List<String> copy = new ArrayList<String>(list);
+        final int last = copy.size() - 1;
+        final String result = copy.remove(last);
+        stack.set(Collections.unmodifiableList(copy));
+        return result;
     }
 
     @Override
-    public boolean add(final String s) {
+    public void push(final String message) {
         if (!useStack) {
-            return false;
+            return;
         }
-        final List<String> list = stack.get();
-        final List<String> copy = list == null ? new ArrayList<String>()
-                : new ArrayList<String>(list);
-        copy.add(s);
-        stack.set(Collections.unmodifiableList(copy));
-        return true;
+        add(message);
     }
 
     @Override
@@ -200,29 +178,6 @@ public class DefaultThreadContextStack i
     }
 
     @Override
-    public boolean containsAll(final Collection<?> objects) {
-        if (objects.isEmpty()) { // quick check before accessing the ThreadLocal
-            return true; // looks counter-intuitive, but see
-                         // j.u.AbstractCollection
-        }
-        final List<String> list = stack.get();
-        return list != null && list.containsAll(objects);
-    }
-
-    @Override
-    public boolean addAll(final Collection<? extends String> strings) {
-        if (!useStack || strings.isEmpty()) {
-            return false;
-        }
-        final List<String> list = stack.get();
-        final List<String> copy = list == null ? new ArrayList<String>()
-                : new ArrayList<String>(list);
-        copy.addAll(strings);
-        stack.set(Collections.unmodifiableList(copy));
-        return true;
-    }
-
-    @Override
     public boolean removeAll(final Collection<?> objects) {
         if (!useStack || objects.isEmpty()) {
             return false;
@@ -253,8 +208,53 @@ public class DefaultThreadContextStack i
     }
 
     @Override
+    public int size() {
+        final List<String> result = stack.get();
+        return result == null ? 0 : result.size();
+    }
+
+    @Override
+    public Object[] toArray() {
+        final List<String> result = stack.get();
+        if (result == null) {
+            return new String[0];
+        }
+        return result.toArray(new Object[result.size()]);
+    }
+
+    @Override
+    public <T> T[] toArray(final T[] ts) {
+        final List<String> result = stack.get();
+        if (result == null) {
+            if (ts.length > 0) { // as per the contract of j.u.List#toArray(T[])
+                ts[0] = null;
+            }
+            return ts;
+        }
+        return result.toArray(ts);
+    }
+
+    @Override
     public String toString() {
         final List<String> list = stack.get();
         return list == null ? "[]" : list.toString();
     }
+
+    @Override
+    public void trim(final int depth) {
+        if (depth < 0) {
+            throw new IllegalArgumentException(
+                    "Maximum stack depth cannot be negative");
+        }
+        final List<String> list = stack.get();
+        if (list == null) {
+            return;
+        }
+        final List<String> copy = new ArrayList<String>();
+        final int count = Math.min(depth, list.size());
+        for (int i = 0; i < count; i++) {
+            copy.add(list.get(i));
+        }
+        stack.set(copy);
+    }
 }



Mime
View raw message