Skip to contentMethod: toOwlChanges(OWLOntology)
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.owlapi.change;
19:
20: import org.semanticweb.owlapi.model.AddAxiom;
21: import org.semanticweb.owlapi.model.OWLAxiom;
22: import org.semanticweb.owlapi.model.OWLOntology;
23: import org.semanticweb.owlapi.model.OWLOntologyChange;
24:
25: import javax.annotation.Nonnull;
26: import java.util.List;
27: import java.util.Objects;
28:
29: /**
30: * Add axiom wrapper which allows us to set ontology to which it is applied.
31: */
32: public class MutableAddAxiom extends AddAxiom implements MutableAxiomChange {
33:
34: private OWLOntology ontology;
35:
36: /**
37: * @param ont the ontology to which the change is to be applied
38: * @param axiom The added axiom
39: */
40: public MutableAddAxiom(OWLOntology ont, OWLAxiom axiom) {
41: super(ont, axiom);
42: this.ontology = ont;
43: }
44:
45: @Override
46: public void setOntology(OWLOntology ontology) {
47: this.ontology = ontology;
48: }
49:
50: @Nonnull
51: @Override
52: public OWLOntology getOntology() {
53: return ontology;
54: }
55:
56: @Override
57: public List<OWLOntologyChange> toOwlChanges(OWLOntology targetOntology) {
58: this.ontology = targetOntology;
59: return List.of(this);
60: }
61:
62: @Override
63: public boolean equals(Object o) {
64: if (this == o) {
65: return true;
66: }
67: if (!(o instanceof MutableAddAxiom)) {
68: return false;
69: }
70: if (!super.equals(o)) {
71: return false;
72: }
73: MutableAddAxiom that = (MutableAddAxiom) o;
74: return Objects.equals(ontology, that.ontology) && Objects.equals(getAxiom(), that.getAxiom());
75: }
76:
77: @Override
78: public int hashCode() {
79: return Objects.hash(super.hashCode(), ontology);
80: }
81: }