Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-1930

Add forEach() methods to org.apache.logging.log4j.message.MapMessage

VotersWatch issueWatchersLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 2.9.0
    • API
    • None

    Description

      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().

          /**
           * 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);
          }
      

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            ggregory Gary D. Gregory
            ggregory Gary D. Gregory
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment