-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExtensions.java
More file actions
72 lines (55 loc) · 1.88 KB
/
Extensions.java
File metadata and controls
72 lines (55 loc) · 1.88 KB
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
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
public class Extensions {
static Set<Value> removeAll(Set<Value> setA, Set<Value> setB){
Set<Value> res = new HashSet<Value>();
Iterator<Value> it = setA.iterator();
// HashSet wird mit dem Iterator durchlaufen
while (it.hasNext())
{
// Next gibt das aktuelle HashSet-Objekt zurück
// und geht zum nächsten über
Value setLeft = (Value) it.next();
Iterator<Value> itright = setB.iterator();
boolean isPresent = false;
while(itright.hasNext())
{
Value rightside = (Value) itright.next();
if (setLeft.toString().equals(rightside.toString())) {
isPresent = true;
}
}
if(!isPresent)
{
res.add(setLeft);
}
}
return res;
}
static Set<Value> intersection(Set<Value> setA, Set<Value> setB){
Set<Value> res = new HashSet<Value>();
Iterator<Value> it = setA.iterator();
// HashSet wird mit dem Iterator durchlaufen
while (it.hasNext())
{
// Next gibt das aktuelle HashSet-Objekt zurück
// und geht zum nächsten über
Value setLeft = (Value) it.next();
Iterator<Value> itright = setB.iterator();
boolean isPresent = false;
while(itright.hasNext())
{
Value rightside = (Value) itright.next();
if (setLeft.toString().equals(rightside.toString())) {
isPresent = true;
}
}
if(isPresent)
{
res.add(setLeft);
}
}
return res;
}
}