Is there an API for Set operations like Union, intersection, difference, Cartesian product, Function from a set to another, domain restriction and range restriction of those functions, .... in Java?
Please comment on coverage (of operations) and performance.
Thanks
The
java.util.Set
class doesn't have those calls in its API, but you can combine operations likeremoveAll()
,retainAll()
, andaddAll()
to do union, intersection, and difference. I'm not sure I know what you mean by domain restriction.Set from the API
You can 'simulate' intersection, difference, domain restriction with retainAll, removeAll and addAll method that accept any Collection as a input parameter.
The Google Guava library also has a bunch of useful methods (e.g. set union and difference).
https://code.google.com/p/guava-libraries/wiki/CollectionUtilitiesExplained#Sets
Example (from page linked above):
I don't know any API but have used following methods do such things on Set.
Reference: Set operations: union, intersection, difference, symmetric difference, is subset, is superset
Yes, the java
Set
class.Via Java SE tutorial:
http://download.oracle.com/javase/tutorial/collections/interfaces/set.html