|
|
@@ -6,32 +6,32 @@ import java.util.Set;
|
|
6
|
6
|
import java.util.function.Predicate;
|
|
7
|
7
|
import java.util.stream.Collectors;
|
|
8
|
8
|
|
|
9
|
|
-public class CustomSet<T> {
|
|
|
9
|
+class CustomSet<T> {
|
|
10
|
10
|
|
|
11
|
11
|
private Set<T> set;
|
|
12
|
12
|
|
|
13
|
|
- public CustomSet() {
|
|
|
13
|
+ CustomSet() {
|
|
14
|
14
|
this(Collections.emptyList());
|
|
15
|
15
|
}
|
|
16
|
16
|
|
|
17
|
|
- public CustomSet(Collection<T> data) {
|
|
|
17
|
+ CustomSet(Collection<T> data) {
|
|
18
|
18
|
set = new HashSet<>(data.size());
|
|
19
|
19
|
this.set.addAll(data);
|
|
20
|
20
|
}
|
|
21
|
21
|
|
|
22
|
|
- public boolean isEmpty() {
|
|
|
22
|
+ boolean isEmpty() {
|
|
23
|
23
|
return set.isEmpty();
|
|
24
|
24
|
}
|
|
25
|
25
|
|
|
26
|
|
- public boolean contains(T element) {
|
|
|
26
|
+ boolean contains(T element) {
|
|
27
|
27
|
return set.contains(element);
|
|
28
|
28
|
}
|
|
29
|
29
|
|
|
30
|
|
- public boolean isSubset(CustomSet<T> anotherSet) {
|
|
|
30
|
+ boolean isSubset(CustomSet<T> anotherSet) {
|
|
31
|
31
|
return set.containsAll(anotherSet.set);
|
|
32
|
32
|
}
|
|
33
|
33
|
|
|
34
|
|
- public boolean isDisjoint(CustomSet<T> anotherSet) {
|
|
|
34
|
+ boolean isDisjoint(CustomSet<T> anotherSet) {
|
|
35
|
35
|
if (set.isEmpty() || anotherSet.set.isEmpty()) {
|
|
36
|
36
|
return true;
|
|
37
|
37
|
}
|
|
|
@@ -40,15 +40,15 @@ public class CustomSet<T> {
|
|
40
|
40
|
.count() == 0;
|
|
41
|
41
|
}
|
|
42
|
42
|
|
|
43
|
|
- public boolean equals(CustomSet<T> anotherSet) {
|
|
|
43
|
+ boolean equals(CustomSet<T> anotherSet) {
|
|
44
|
44
|
return set.equals(anotherSet.set);
|
|
45
|
45
|
}
|
|
46
|
46
|
|
|
47
|
|
- public boolean add(T element) {
|
|
|
47
|
+ boolean add(T element) {
|
|
48
|
48
|
return set.add(element);
|
|
49
|
49
|
}
|
|
50
|
50
|
|
|
51
|
|
- public CustomSet<T> getIntersection(CustomSet<T> anotherSet) {
|
|
|
51
|
+ CustomSet<T> getIntersection(CustomSet<T> anotherSet) {
|
|
52
|
52
|
return new CustomSet<>(
|
|
53
|
53
|
set.stream()
|
|
54
|
54
|
.filter(anotherSet.set::contains)
|
|
|
@@ -56,13 +56,13 @@ public class CustomSet<T> {
|
|
56
|
56
|
);
|
|
57
|
57
|
}
|
|
58
|
58
|
|
|
59
|
|
- public CustomSet<T> getUnion(CustomSet<T> anotherSet) {
|
|
|
59
|
+ CustomSet<T> getUnion(CustomSet<T> anotherSet) {
|
|
60
|
60
|
final Set<T> union = new HashSet<>(set);
|
|
61
|
61
|
union.addAll(anotherSet.set);
|
|
62
|
62
|
return new CustomSet<>(union);
|
|
63
|
63
|
}
|
|
64
|
64
|
|
|
65
|
|
- public CustomSet<T> getDifference(CustomSet<T> anotherSet) {
|
|
|
65
|
+ CustomSet<T> getDifference(CustomSet<T> anotherSet) {
|
|
66
|
66
|
final Predicate<T> predicate = anotherSet::contains;
|
|
67
|
67
|
return new CustomSet<>(
|
|
68
|
68
|
set.stream()
|