Sets.difference should accept general Collection as second argument
See original GitHub issueCurrent signature of Sets.difference
method is
SetView<E> difference(final Set<E> set1, final Set<?> set2)
however, for all usages of set2
argument everything would work as well if argument was of type Collection<?>
, without impact on performance for current usages. Why not to make signature less strict?
In my use case, I do following manipulation:
BiMap<Foo,Foo> specialFoos = ...
Set<Foo> nonspecialLeftFoos = Sets.difference(leftFoos ,specialFoos.keySet());
Set<Foo> nonspecialRightFoos = Sets.difference(rightFoos,specialFoos.values());
where this issue is the only reason why specialFoos
is a BiMap
.
Thanks for response.
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
The Set Interface - Java™ Tutorials
A Set is a Collection that cannot contain duplicate elements. It models the mathematical set abstraction. The Set interface contains only methods inherited...
Read more >Sets | Collections (Scala 2.8 - 2.12)
The operations on sets are summarized in the following table for general sets ... except that ++ takes a Traversable argument whereas union...
Read more >Sets in Python - Real Python
Set elements are unique. Duplicate elements are not allowed. A set itself may be modified, but the elements contained in the set must...
Read more >Sets in Julia - GeeksforGeeks
Sets are different from arrays because sets are unordered collections of unique elements whereas the order of elements is strictly remembered ...
Read more >SetUtils (Apache Commons Collections 4.4 API)
Returns a unmodifiable view containing the difference of the given Set s, ... the second set, must not be null; Returns: a view...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Or, if you’re on Java 8 and a fan of lambdas:
Sets.filter(set, e -> !collection.contains(e))
.If you really want that behavior you can also always get it with Sets.filter(set, not(in(Collection))).
On Mon, Feb 13, 2017, 9:03 AM Michał Sobkiewicz notifications@github.com wrote: