logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ralph Goers <ralph.go...@dslextreme.com>
Subject Re: svn commit: r1596446 - /logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/ThreadContext.java
Date Wed, 21 May 2014 05:33:56 GMT
Yeah, I’m against that for 2.0 GA.

Ralph

On May 20, 2014, at 8:09 PM, Gary Gregory <garydgregory@gmail.com> wrote:

> Java 7 keeps creeping in here and there. I'm all for making Java 7 the required platform...
I'm probably in the minority...
> 
> Gary
> 
> ---------- Forwarded message ----------
> From: <mattsicker@apache.org>
> Date: Tue, May 20, 2014 at 11:00 PM
> Subject: svn commit: r1596446 - /logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/ThreadContext.java
> To: commits@logging.apache.org
> 
> 
> Author: mattsicker
> Date: Wed May 21 03:00:17 2014
> New Revision: 1596446
> 
> URL: http://svn.apache.org/r1596446
> Log:
> Add empty iterator implementation (yay 1.7) along with some warning suppression (it's
ok to share immutable collection classes as public fields).
> 
> Modified:
>     logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/ThreadContext.java
> 
> Modified: logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/ThreadContext.java
> URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/ThreadContext.java?rev=1596446&r1=1596445&r2=1596446&view=diff
> ==============================================================================
> --- logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/ThreadContext.java
(original)
> +++ logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/ThreadContext.java
Wed May 21 03:00:17 2014
> @@ -24,6 +24,7 @@ import java.util.Collections;
>  import java.util.Iterator;
>  import java.util.List;
>  import java.util.Map;
> +import java.util.NoSuchElementException;
> 
>  import org.apache.logging.log4j.message.ParameterizedMessage;
>  import org.apache.logging.log4j.spi.DefaultThreadContextMap;
> @@ -52,6 +53,8 @@ public final class ThreadContext  {
> 
>          private static final long serialVersionUID = 1L;
> 
> +        private static final Iterator<String> EMPTY_ITERATOR = new EmptyIterator<String>();
> +
>          @Override
>          public String pop() {
>              return null;
> @@ -131,8 +134,7 @@ public final class ThreadContext  {
> 
>          @Override
>          public Iterator<String> iterator() {
> -            List<String> empty = Collections.emptyList();
> -            return empty.iterator();
> +            return EMPTY_ITERATOR;
>          }
> 
>          @Override
> @@ -143,13 +145,37 @@ public final class ThreadContext  {
>      }
> 
>      /**
> +     * An empty iterator. Since Java 1.7 added the Collections.emptyIterator() method,
we have to make do.
> +     * @param <E> the type of the empty iterator
> +     */
> +    private static class EmptyIterator<E> implements Iterator<E> {
> +
> +        @Override
> +        public boolean hasNext() {
> +            return false;
> +        }
> +
> +        @Override
> +        public E next() {
> +            throw new NoSuchElementException("This is an empty iterator!");
> +        }
> +
> +        @Override
> +        public void remove() {
> +            // no-op
> +        }
> +    }
> +
> +    /**
>       * Empty, immutable Map.
>       */
> +    @SuppressWarnings("PublicStaticCollectionField")
>      public static final Map<String, String> EMPTY_MAP = Collections.emptyMap();
> 
>      /**
>       * Empty, immutable ContextStack.
>       */
> +    @SuppressWarnings("PublicStaticCollectionField")
>      public static final ThreadContextStack EMPTY_STACK = new EmptyThreadContextStack();
> 
>      private static final String DISABLE_MAP = "disableThreadContextMap";
> @@ -334,7 +360,7 @@ public final class ThreadContext  {
>       * @param stack The stack to use.
>       */
>      public static void setStack(final Collection<String> stack) {
> -        if (stack.size() == 0 || !useStack) {
> +        if (stack.isEmpty() || !useStack) {
>              return;
>          }
>          contextStack.clear();
> 
> 
> 
> 
> 
> -- 
> E-Mail: garydgregory@gmail.com | ggregory@apache.org 
> Java Persistence with Hibernate, Second Edition
> JUnit in Action, Second Edition
> Spring Batch in Action
> Blog: http://garygregory.wordpress.com 
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory


Mime
View raw message