TimurMahammadov / google-collections

Automatically exported from code.google.com/p/google-collections
Apache License 2.0
0 stars 0 forks source link

Support removal from Iterables and Maps based on Predicate #45

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I'd like to be able to filter Iterables and Maps in place. Perhaps adding a
method to Iterables with the following signature:

public static <T> void filterInPlace(
      final Iterable<T> unfiltered, final Predicate<? super T> predicate)

and one to Maps with the following signature:

public static <K, V> void filterInPlace(
      Map<K, V> unfiltered, Predicate<? super K> predicate)

I've attached diffs against the 20071022 snapshot, if you feel this is
worth adding. If not, then it'll stay in my own toolbox of
things-built-on-top-of-google-collections. I've also attached a couple of
simple unit tests.

Original issue reported on code.google.com by ericcram...@gmail.com on 19 Dec 2007 at 4:21

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks for contributing this!

I'm busy right now, but I'll look this over in January.

Original comment by jared.l....@gmail.com on 19 Dec 2007 at 9:12

GoogleCodeExporter commented 9 years ago
I've just filed issue 48.  If we implement that, then you will be able to 
accomplish
your filtering in place using

  filter(myCollection, predicate).clear()

or

  filter(myMap.keySet(), predicate).clear()

where the predicate matches what you want removed.

If that goes forward, I will close this issue, but thank you very much for the 
idea.

Original comment by kevin...@gmail.com on 30 Jan 2008 at 5:15

GoogleCodeExporter commented 9 years ago
I wrote Collections2.filter(Collection, Predicate) and Sets.filter(Set, 
Predicate) 
methods that create a filtered Collection or Set. They return a filtered 
Collection
or Set view.

We don't yet have any map-filtering logic.

Original comment by jared.l....@gmail.com on 17 Jul 2008 at 9:00

GoogleCodeExporter commented 9 years ago
I implemented three Maps methods that return filtered maps: filterKeys(),
filterValues(), and filterEntries(). They'll be in the next release.

Original comment by jared.l....@gmail.com on 13 Oct 2008 at 6:36