melloware commented on PR #593:
URL: https://github.com/apache/myfaces/pull/593#issuecomment-1620442210

   So Mojarra wrote a custom iterator so it could properly handle this scenario.
   
   ```java
   // ---------------------------------------------------------- Inner Classes
   
       private static final class ComponentMessagesIterator implements 
Iterator<FacesMessage> {
   
           private Map<String, List<FacesMessage>> messages;
           private int outerIndex = -1;
           private int messagesSize;
           private Iterator<FacesMessage> inner;
           private Iterator<String> keys;
   
           // ------------------------------------------------------- 
Constructors
   
           ComponentMessagesIterator(Map<String, List<FacesMessage>> messages) {
   
               this.messages = messages;
               messagesSize = messages.size();
               keys = messages.keySet().iterator();
   
           }
   
           // ---------------------------------------------- Methods from 
Iterator
   
           @Override
           public boolean hasNext() {
   
               if (outerIndex == -1) {
                   // pop our first List, if any;
                   outerIndex++;
                   inner = messages.get(keys.next()).iterator();
   
               }
               while (!inner.hasNext()) {
                   outerIndex++;
                   if (outerIndex < messagesSize) {
                       inner = messages.get(keys.next()).iterator();
                   } else {
                       return false;
                   }
               }
               return inner.hasNext();
   
           }
   
           @Override
           public FacesMessage next() {
   
               if (outerIndex >= messagesSize) {
                   throw new NoSuchElementException();
               }
               if (inner != null && inner.hasNext()) {
                   return inner.next();
               } else {
                   // call this.hasNext() to properly initialize/position 
'inner'
                   if (!hasNext()) {
                       throw new NoSuchElementException();
                   } else {
                       return inner.next();
                   }
               }
   
           }
   
           @Override
           public void remove() {
   
               if (outerIndex == -1) {
                   throw new IllegalStateException();
               }
               inner.remove();
   
           }
   
       } // END ComponentMessagesIterator
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to