1 package eu.fbk.dkm.pikes.eval;
2
3 import java.util.Objects;
4
5 import javax.annotation.Nullable;
6
7 import org.eclipse.rdf4j.model.IRI;
8
9 public final class Relation implements Comparable<Relation> {
10
11 private final IRI first;
12
13 private final IRI second;
14
15 private final boolean extra;
16
17 public Relation(final IRI first, final IRI second, final boolean extra) {
18 final boolean swap = Util.VALUE_ORDERING.compare(first, second) > 0;
19 this.first = swap ? second : first;
20 this.second = swap ? first : second;
21 this.extra = extra;
22 }
23
24 public IRI getFirst() {
25 return this.first;
26 }
27
28 public IRI getSecond() {
29 return this.second;
30 }
31
32 public boolean isExtra() {
33 return this.extra;
34 }
35
36 @Override
37 public int compareTo(final Relation other) {
38 int result = Util.VALUE_ORDERING.compare(this.first, other.first);
39 if (result == 0) {
40 result = Util.VALUE_ORDERING.compare(this.second, other.second);
41 }
42 return result;
43 }
44
45 @Override
46 public boolean equals(final Object object) {
47 if (object == this) {
48 return true;
49 }
50 if (!(object instanceof Relation)) {
51 return false;
52 }
53 final Relation other = (Relation) object;
54 return this.first.equals(other.first) && this.second.equals(other.second);
55 }
56
57 @Override
58 public int hashCode() {
59 return Objects.hash(this.first, this.second);
60 }
61
62 public String toString(@Nullable final IRI baseIRI) {
63 return "(" + Util.format(baseIRI, this.first) + ", " + Util.format(baseIRI, this.second)
64 + ")";
65 }
66
67 @Override
68 public String toString() {
69 return toString(null);
70 }
71
72 }