google / guava

Google core libraries for Java
Apache License 2.0
50.04k stars 10.86k forks source link

Method to remove n copies of every given element in an Iterable from a Multiset, and to do math on counts of all existing elements #3701

Open panyingself opened 4 years ago

panyingself commented 4 years ago

When using the removeOccurrences() method of Multisets, it occurred to me...

The current method is understood to be a batch deletion of the number of specified nodes in multisetToModify.

MultiSet:

The remove() method is provided to remove existing nodes as well as the number of times a specified node should be removed. Why not support batch sets instead of MultiSets?

MultiSet provides removeAll() method to support batch deletion of nodes, why not support the specified number of times of deletion?

Is there any consideration in this? I think it's more convenient from the user's point of view that MultiSet is directly supported so you don't have to call one more utility class.

cpovirk commented 4 years ago

It sounds like you're asking for a method that accepts:

Then, for each element in the Iterable, it removes multiplier occurrences of that element from the Multiset. Is that right?

panyingself commented 4 years ago

I'm sorry I was busy the other day

First of all, thank you very much for your reply

As you said, but beyond that, could you support some methods like:

    Multisets.addAllOccurrences(Multiset targetMultiset,int occurrences); -- Increment occurrences for all elements of the specified MultiSet

    Multisets.subtractionAllOccurrences(Multiset targetMultiset,int occurrences);-- Decrease occurrences on all elements of the specified MultiSet

    Multisets.multiplicationAllOccurrences(Multiset targetMultiset,int occurrences);-- Multiply the old occurrences times the specified occurrences for all elements of the specified MultiSet

    Multisets.divisionAllOccurrences(Multiset targetMultiset,int occurrences);-- Divide the existing occurrences of all elements in the specified MultiSet by the specified occurrences

The above approach is also frequently used in business scenarios,If not, could you please tell me how to implement the above scenario? Thank you for support......

cpovirk commented 4 years ago

Thanks for the additional details.

If we do add this, we probably won't do it soon. So if you need immediate help to implement something yourself, I'd recommend asking on Stack Overflow.

panyingself commented 4 years ago

Ok, thanks again for your reply.