blob: e19c9bf6cda9b6667978216e5bf9f1d430618a80 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.document.select;
import com.yahoo.document.BucketId;
import java.util.HashSet;
/**
* A set of bucket ids covered by a document selector.
*
* @author Simon Thoresen Hult
*/
public class BucketSet extends HashSet<BucketId> {
/**
* Constructs a new bucket set that contains no ids.
*/
public BucketSet() {
// empty
}
/**
* Constructs a new bucket set that contains a single id.
*
* @param id The id to add to this as initial value.
*/
public BucketSet(BucketId id) {
add(id);
}
/**
* Constructs a new bucket set that is a copy of another.
*
* @param set The set to copy.
*/
public BucketSet(BucketSet set) {
this.addAll(set);
}
/**
* Returns the intersection between this bucket set and another.
*
* @param rhs The set to form an intersection with.
* @return The intersection.
*/
public BucketSet intersection(BucketSet rhs) {
if (rhs == null) {
return new BucketSet(this); // The other has all buckets marked, this is the smaller.
} else {
BucketSet ret = new BucketSet(this);
ret.retainAll(rhs);
return ret;
}
}
/**
* Returns the union between this bucket set and another.
*
* @param rhs The set to form a union with.
* @return The union.
*/
public BucketSet union(BucketSet rhs) {
if (rhs == null) {
return null;
} else {
BucketSet ret = new BucketSet(this);
ret.addAll(rhs);
return ret;
}
}
}
|