Return-Path: X-Original-To: apmail-logging-commits-archive@minotaur.apache.org Delivered-To: apmail-logging-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 3C7C411A24 for ; Wed, 14 May 2014 23:42:18 +0000 (UTC) Received: (qmail 47762 invoked by uid 500); 10 May 2014 23:23:03 -0000 Delivered-To: apmail-logging-commits-archive@logging.apache.org Received: (qmail 5957 invoked by uid 500); 10 May 2014 23:03:59 -0000 Mailing-List: contact commits-help@logging.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@logging.apache.org Delivered-To: mailing list commits@logging.apache.org Received: (qmail 25715 invoked by uid 99); 10 May 2014 22:58:04 -0000 Received: from Unknown (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 10 May 2014 22:58:04 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 07 May 2014 17:07:05 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id B8E4B23888D7; Wed, 7 May 2014 17:06:41 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@logging.apache.org From: ggregory@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20140507170641.B8E4B23888D7@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 list = stack.get(); - if (list == null || list.size() == 0) { - throw new NoSuchElementException("The ThreadContext stack is empty"); - } - final List copy = new ArrayList(list); - final int last = copy.size() - 1; - final String result = copy.remove(last); + final List copy = list == null ? new ArrayList() + : new ArrayList(list); + copy.add(s); stack.set(Collections.unmodifiableList(copy)); - return result; - } - - @Override - public String peek() { - final List 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 strings) { + if (!useStack || strings.isEmpty()) { + return false; } - add(message); - } - - @Override - public int getDepth() { final List list = stack.get(); - return list == null ? 0 : list.size(); + final List copy = list == null ? new ArrayList() + : new ArrayList(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 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 list = stack.get(); - if (list == null) { - return; - } - final List copy = new ArrayList(); - 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 result = stack.get(); - return result == null ? 0 : result.size(); + public int getDepth() { + final List 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 result = stack.get(); - return result != null && result.contains(o); - } - - @Override public Iterator iterator() { final List immutable = stack.get(); if (immutable == null) { @@ -151,37 +129,37 @@ public class DefaultThreadContextStack i } @Override - public Object[] toArray() { - final List result = stack.get(); - if (result == null) { - return new String[0]; + public String peek() { + final List 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[] toArray(final T[] ts) { - final List 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 list = stack.get(); + if (list == null || list.size() == 0) { + throw new NoSuchElementException("The ThreadContext stack is empty"); + } + final List copy = new ArrayList(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 list = stack.get(); - final List copy = list == null ? new ArrayList() - : new ArrayList(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 list = stack.get(); - return list != null && list.containsAll(objects); - } - - @Override - public boolean addAll(final Collection strings) { - if (!useStack || strings.isEmpty()) { - return false; - } - final List list = stack.get(); - final List copy = list == null ? new ArrayList() - : new ArrayList(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 result = stack.get(); + return result == null ? 0 : result.size(); + } + + @Override + public Object[] toArray() { + final List result = stack.get(); + if (result == null) { + return new String[0]; + } + return result.toArray(new Object[result.size()]); + } + + @Override + public T[] toArray(final T[] ts) { + final List 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 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 list = stack.get(); + if (list == null) { + return; + } + final List copy = new ArrayList(); + final int count = Math.min(depth, list.size()); + for (int i = 0; i < count; i++) { + copy.add(list.get(i)); + } + stack.set(copy); + } }