Uploaded image for project: 'Commons Collections'
  1. Commons Collections
  2. COLLECTIONS-448

Proposal for adding random pick methods to Bags

    XMLWordPrintableJSON

Details

    • Wish
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 4.0
    • 4.x
    • Bag

    Description

      Hello,

      This is a patch to add two methods to Bag interface and classes
      public E pick();
      public E pickAndRemit();
      as discussed in this mail.
      -----------------------------------------------------------------
      http://mail-archives.apache.org/mod_mbox/commons-dev/201303.mbox/%3CCAChO4O-YRE%3Db1%3D4hEK%2BuhvpV6-OD3F3apyRn3mwjvGzUEXe%2BaQ%40mail.gmail.com%3E
      I just saw the Bag interface and its implementations, I'm surprised that Bag <T> (and none of these implementations) expose the method
      public T pick() and public T pickAndRemit() (pick a random element)
      The Bag object we see in nature, it is mainly used to this, that's why it is widely used in the probability that when I met 2 white balls and one black, when I draw a ball randomly I have 2 times more likely to have a white ball

      I think that if this caracteristic exists it would be very valuable.
      ----------------------------------------------------------------------

      these methods pick a random element from the bag, The probability of picking a copy of a given element is proportional to the number of copies of this element in the bag.
      the diference between pick() and pickAndRemit() is that with pick() the picked element is removed from the bag.

      this is my first contribution on open source project

      if you accept to add this feature to bags and validate my patch i will propose one other patch to add this methods

      public Iterator<E> pick(int n); //pick random n element (with remove)
      public Iterator<E> pickAndRemit(int n) ; //pick random n element (without remove)

      -Question : should i regenerate the serialVersionUID of classes that i have changed ?

      Othmen Tiliouine

      Attachments

        1. pickFromABag2.patch
          8 kB
          Othmen Tiliouine

        Activity

          People

            Unassigned Unassigned
            influence160 Othmen Tiliouine
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Time Tracking

                Estimated:
                Original Estimate - 4h
                4h
                Remaining:
                Remaining Estimate - 4h
                4h
                Logged:
                Time Spent - Not Specified
                Not Specified