Skip to content

Method: equals(Object)

1: /*
2: * JOPA
3: * Copyright (C) 2024 Czech Technical University in Prague
4: *
5: * This library is free software; you can redistribute it and/or
6: * modify it under the terms of the GNU Lesser General Public
7: * License as published by the Free Software Foundation; either
8: * version 3.0 of the License, or (at your option) any later version.
9: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library.
17: */
18: package cz.cvut.kbss.ontodriver.jena.connector;
19:
20: import org.apache.jena.rdf.model.Property;
21: import org.apache.jena.rdf.model.Resource;
22: import org.apache.jena.rdf.model.Statement;
23:
24: import java.util.Objects;
25: import java.util.Set;
26:
27: /**
28: * Represents the subject, predicate and context(s) of a statement.
29: *
30: * Used to indicate what property values to remove from the repository.
31: */
32: public final class SubjectPredicateContext {
33:
34: private final Resource subject;
35:
36: private final Property predicate;
37:
38: private final Set<String> contexts;
39:
40: public SubjectPredicateContext(Resource subject, Property predicate, Set<String> contexts) {
41: assert subject != null;
42: assert contexts != null;
43:
44: this.subject = subject;
45: this.predicate = predicate;
46: this.contexts = contexts;
47: }
48:
49: public Resource getSubject() {
50: return subject;
51: }
52:
53: public Property getPredicate() {
54: return predicate;
55: }
56:
57: public Set<String> getContexts() {
58: return contexts;
59: }
60:
61: public boolean matches(Statement s, String context) {
62: return subject.equals(s.getSubject()) && predicate.equals(s.getPredicate()) &&
63: (contexts.isEmpty() || contexts.contains(context));
64: }
65:
66: @Override
67: public boolean equals(Object o) {
68:• if (this == o) return true;
69:• if (!(o instanceof SubjectPredicateContext)) return false;
70: SubjectPredicateContext that = (SubjectPredicateContext) o;
71:• return subject.equals(that.subject) && Objects.equals(predicate, that.predicate) && contexts.equals(
72: that.contexts);
73: }
74:
75: @Override
76: public int hashCode() {
77: return Objects.hash(subject, predicate, contexts);
78: }
79: }