15
15
* @author itakurah (Niklas Hoefflin) (https://github.com/itakurah)
16
16
*/
17
17
18
- public class TwoPSet {
19
- private Set <String > setA ;
20
- private Set <String > setR ;
18
+ public class TwoPSet < T > {
19
+ private final Set <T > setA ;
20
+ private final Set <T > setR ;
21
21
22
22
/**
23
23
* Constructs an empty Two-Phase Set.
@@ -33,7 +33,7 @@ public TwoPSet() {
33
33
* @param element The element to be checked.
34
34
* @return True if the element is in the set and has not been removed, otherwise false.
35
35
*/
36
- public boolean lookup (String element ) {
36
+ public boolean lookup (T element ) {
37
37
return setA .contains (element ) && !setR .contains (element );
38
38
}
39
39
@@ -42,7 +42,7 @@ public boolean lookup(String element) {
42
42
*
43
43
* @param element The element to be added.
44
44
*/
45
- public void add (String element ) {
45
+ public void add (T element ) {
46
46
setA .add (element );
47
47
}
48
48
@@ -51,7 +51,7 @@ public void add(String element) {
51
51
*
52
52
* @param element The element to be removed.
53
53
*/
54
- public void remove (String element ) {
54
+ public void remove (T element ) {
55
55
if (lookup (element )) {
56
56
setR .add (element );
57
57
}
@@ -63,7 +63,7 @@ public void remove(String element) {
63
63
* @param otherSet The other 2P-Set to compare with.
64
64
* @return True if both SetA and SetR are subset, otherwise false.
65
65
*/
66
- public boolean compare (TwoPSet otherSet ) {
66
+ public boolean compare (TwoPSet < T > otherSet ) {
67
67
return otherSet .setA .containsAll (setA ) && otherSet .setR .containsAll (setR );
68
68
}
69
69
@@ -73,8 +73,8 @@ public boolean compare(TwoPSet otherSet) {
73
73
* @param otherSet The other 2P-Set to merge with.
74
74
* @return A new 2P-Set containing the merged elements.
75
75
*/
76
- public TwoPSet merge (TwoPSet otherSet ) {
77
- TwoPSet mergedSet = new TwoPSet ();
76
+ public TwoPSet < T > merge (TwoPSet < T > otherSet ) {
77
+ TwoPSet < T > mergedSet = new TwoPSet <> ();
78
78
mergedSet .setA .addAll (this .setA );
79
79
mergedSet .setA .addAll (otherSet .setA );
80
80
mergedSet .setR .addAll (this .setR );
0 commit comments