garydgregory commented on pull request #258:
URL: 
https://github.com/apache/commons-collections/pull/258#issuecomment-994870141


   Hi All,
   I agree on initially minimizing exposure of internal utilities WRT BitMap.
   
   As @aherbert mentioned, this is an anti-pattern for sure:
   ```
       @Override
       public boolean contains(IndexProducer indexProducer) {
           try {
               indexProducer.forEachIndex(idx -> {
                   if (!indices.contains(idx)) {
                       throw new NoMatchException();
                   }
               });
               return true;
           } catch (NoMatchException e) {
               return false;
           }
       }
   ```
   It sounds like something where a Stream API can be used. But then why not 
delegate the implementation of contains to IndexProducer? But... then 
IndexProducer looks like:
   
   ```
   ...
   public interface IndexProducer {
   
       /**
        * Each index is passed to the consumer.
        * <p>Any exceptions thrown by the action are relayed to the caller.</p>
        *
        * <p>Indices ordering is not guaranteed</p>
        *
        * @param consumer the action to be performed for each non-zero bit 
index.
        * @throws NullPointerException if the specified action is null
        */
       void forEachIndex(IntConsumer consumer);
   ...
   ```
   And that does not seem best at first glance because Stream#forEach() can 
already take an IntConsumer as a parameter but this is not a Stream.
   
   Anyway, I am OK bringing this in with or without the int to long change 
because it will be easier to further experiment and maybe improve the design 
regarding Streams and implementations of methods. I'll leave it to @aherbert to 
approve the PR or ask for more changes.
   
   


-- 
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