[ 
https://issues.apache.org/jira/browse/LOG4J2-1930?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Gary Gregory closed LOG4J2-1930.
--------------------------------
       Resolution: Fixed
    Fix Version/s: 2.9

In Git master.

> Add forEach() methods to org.apache.logging.log4j.message.MapMessage
> --------------------------------------------------------------------
>
>                 Key: LOG4J2-1930
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-1930
>             Project: Log4j 2
>          Issue Type: New Feature
>          Components: API
>            Reporter: Gary Gregory
>            Assignee: Gary Gregory
>             Fix For: 2.9
>
>
> Add {{forEach()}} methods to {{org.apache.logging.log4j.message.MapMessage}} 
> that delegate to the internal {{ReadOnlyStringMap}}. This avoids call sites 
> making a copy of the map by calling {{MapMessage.getData()}}.
> {code:java}
>     /**
>      * Performs the given action for each key-value pair in this data 
> structure
>      * until all entries have been processed or the action throws an 
> exception.
>      * <p>
>      * Some implementations may not support structural modifications (adding 
> new elements or removing elements) while
>      * iterating over the contents. In such implementations, attempts to add 
> or remove elements from the
>      * {@code BiConsumer}'s {@link BiConsumer#accept(Object, Object)} accept} 
> method may cause a
>      * {@code ConcurrentModificationException} to be thrown.
>      * </p>
>      *
>      * @param action The action to be performed for each key-value pair in 
> this collection
>      * @param <V> type of the value
>      * @throws java.util.ConcurrentModificationException some implementations 
> may not support structural modifications
>      *          to this data structure while iterating over the contents with 
> {@link #forEach(BiConsumer)} or
>      *          {@link #forEach(TriConsumer, Object)}.
>      * @see ReadOnlyStringMap#forEach(BiConsumer)
>      * @since 2.9
>      */
>     public <V> void forEach(final BiConsumer<String, ? super V> action) {
>         data.forEach(action);
>     }
>     /**
>      * Performs the given action for each key-value pair in this data 
> structure
>      * until all entries have been processed or the action throws an 
> exception.
>      * <p>
>      * The third parameter lets callers pass in a stateful object to be 
> modified with the key-value pairs,
>      * so the TriConsumer implementation itself can be stateless and 
> potentially reusable.
>      * </p>
>      * <p>
>      * Some implementations may not support structural modifications (adding 
> new elements or removing elements) while
>      * iterating over the contents. In such implementations, attempts to add 
> or remove elements from the
>      * {@code TriConsumer}'s {@link TriConsumer#accept(Object, Object, 
> Object) accept} method may cause a
>      * {@code ConcurrentModificationException} to be thrown.
>      * </p>
>      *
>      * @param action The action to be performed for each key-value pair in 
> this collection
>      * @param state the object to be passed as the third parameter to each 
> invocation on the specified
>      *          triconsumer
>      * @param <V> type of the value
>      * @param <S> type of the third parameter
>      * @throws java.util.ConcurrentModificationException some implementations 
> may not support structural modifications
>      *          to this data structure while iterating over the contents with 
> {@link #forEach(BiConsumer)} or
>      *          {@link #forEach(TriConsumer, Object)}.
>      * @see ReadOnlyStringMap#forEach(TriConsumer, Object)
>      * @since 2.9
>      */
>     public <V, S> void forEach(final TriConsumer<String, ? super V, S> 
> action, final S state) {
>         data.forEach(action, state);
>     }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Reply via email to