-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRecordOperators.java
More file actions
55 lines (49 loc) · 1.75 KB
/
Copy pathRecordOperators.java
File metadata and controls
55 lines (49 loc) · 1.75 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
import java.util.Vector;
public class RecordOperators {
private static boolean recordExists(Vector<Tuple> records, Tuple record) {
// Check if a record exists in a record vector.
for (Tuple r : records) {
if (r.compareTo(record)) {
return true;
}
}
return false;
}
public static Vector<Tuple> xorRecords(Vector<Tuple> records1, Vector<Tuple> records2) {
// Return the XOR of two record vectors.
Vector<Tuple> xorRecords = new Vector<Tuple>();
// Add records that are in records1 but not in records2, and vice versa.
for (Tuple record1 : records1) {
if (!recordExists(records2, record1)) {
xorRecords.add(record1);
}
}
for (Tuple record2 : records2) {
if (!recordExists(records1, record2)) {
xorRecords.add(record2);
}
}
return xorRecords;
}
public static Vector<Tuple> andRecords(Vector<Tuple> records1, Vector<Tuple> records2) {
// Return the AND of two record vectors.
Vector<Tuple> andRecords = new Vector<Tuple>();
for (Tuple record1 : records1) {
if (recordExists(records2, record1)) {
andRecords.add(record1);
}
}
return andRecords;
}
public static Vector<Tuple> orRecords(Vector<Tuple> records1, Vector<Tuple> records2) {
// Return the OR of two record vectors.
Vector<Tuple> orRecords = new Vector<Tuple>(records1);
for (Tuple record2 : records2) {
boolean found = recordExists(records1, record2);
if (!found) {
orRecords.add(record2);
}
}
return orRecords;
}
}