diff options
author | Jason Tedor <jason@tedor.me> | 2017-06-27 11:29:04 -0400 |
---|---|---|
committer | Jason Tedor <jason@tedor.me> | 2017-06-27 11:29:35 -0400 |
commit | 9b3768204b30892ff8c49bf8716e2dc1ef43ad8a (patch) | |
tree | b543d518219ec2741007ce62ff2b5fc7add36b81 /core/src/main | |
parent | c55dc23270b5969d009f0c1caea9780ab4f22a44 (diff) |
Add Javadocs and tests for set difference methods
This commit adds Javadocs and tests for some set difference utility
methods in core.
Diffstat (limited to 'core/src/main')
-rw-r--r-- | core/src/main/java/org/elasticsearch/common/util/set/Sets.java | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/core/src/main/java/org/elasticsearch/common/util/set/Sets.java b/core/src/main/java/org/elasticsearch/common/util/set/Sets.java index f2bba5cde3..0f1fe22c02 100644 --- a/core/src/main/java/org/elasticsearch/common/util/set/Sets.java +++ b/core/src/main/java/org/elasticsearch/common/util/set/Sets.java @@ -71,12 +71,31 @@ public final class Sets { return !left.stream().anyMatch(k -> right.contains(k)); } + /** + * The relative complement, or difference, of the specified left and right set. Namely, the resulting set contains all the elements that + * are in the left set but not in the right set. Neither input is mutated by this operation, an entirely new set is returned. + * + * @param left the left set + * @param right the right set + * @param <T> the type of the elements of the sets + * @return the relative complement of the left set with respect to the right set + */ public static <T> Set<T> difference(Set<T> left, Set<T> right) { Objects.requireNonNull(left); Objects.requireNonNull(right); return left.stream().filter(k -> !right.contains(k)).collect(Collectors.toSet()); } + /** + * The relative complement, or difference, of the specified left and right set, returned as a sorted set. Namely, the resulting set + * contains all the elements that are in the left set but not in the right set, and the set is sorted using the natural ordering of + * element type. Neither input is mutated by this operation, an entirely new set is returned. + * + * @param left the left set + * @param right the right set + * @param <T> the type of the elements of the sets + * @return the sorted relative complement of the left set with respect to the right set + */ public static <T> SortedSet<T> sortedDifference(Set<T> left, Set<T> right) { Objects.requireNonNull(left); Objects.requireNonNull(right); |