-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'protegeproject:master' into removeLibs
- Loading branch information
Showing
6 changed files
with
145 additions
and
4 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
...editor-owl/src/main/java/org/protege/editor/owl/ui/OWLPropertyAssertionRowComparator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package org.protege.editor.owl.ui; | ||
|
||
import org.protege.editor.owl.ui.frame.OWLFrameSectionRow; | ||
import org.semanticweb.owlapi.model.OWLIndividual; | ||
import org.semanticweb.owlapi.model.OWLObject; | ||
import org.semanticweb.owlapi.model.OWLPropertyAssertionAxiom; | ||
|
||
import java.util.Comparator; | ||
|
||
/** | ||
* Compares rows of type {@link OWLPropertyAssertionAxiom}. | ||
* Comparison priority is as follows: | ||
* inference > property > object | ||
* <p> | ||
* Author: Michael Opitz <br> | ||
* https://github.com/mmopitz<br> | ||
* Date: 30-Sep-2024<br><br> | ||
*/ | ||
public class OWLPropertyAssertionRowComparator<E extends OWLPropertyAssertionAxiom<?, ?>, PAIR> implements | ||
Comparator<OWLFrameSectionRow<OWLIndividual, E, PAIR>> { | ||
private final Comparator<OWLObject> delegate; | ||
|
||
public OWLPropertyAssertionRowComparator(Comparator<OWLObject> delegate) { | ||
this.delegate = delegate; | ||
} | ||
|
||
|
||
@Override | ||
public int compare(OWLFrameSectionRow<OWLIndividual, E, PAIR> o1, OWLFrameSectionRow<OWLIndividual, E, PAIR> o2) { | ||
if (o1.isInferred() && !o2.isInferred()) { | ||
return 1; | ||
} | ||
else if (o2.isInferred() && !o1.isInferred()) { | ||
return -1; | ||
} | ||
int comparison = delegate.compare(o1.getAxiom().getProperty(), o2.getAxiom().getProperty()); | ||
if (comparison != 0) { | ||
return comparison; | ||
} | ||
return delegate.compare(o1.getAxiom().getObject(), o2.getAxiom().getObject()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
...l/src/test/java/org/protege/editor/owl/ui/OWLPropertyAssertionRowComparator_TestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package org.protege.editor.owl.ui; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mock; | ||
import org.mockito.runners.MockitoJUnitRunner; | ||
import org.protege.editor.owl.ui.frame.OWLFrameSectionRow; | ||
import org.semanticweb.owlapi.model.*; | ||
|
||
import java.util.Comparator; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.mockito.Mockito.when; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class OWLPropertyAssertionRowComparator_TestCase { | ||
|
||
@Mock | ||
Comparator<OWLObject> delegate; | ||
@Mock | ||
OWLFrameSectionRow<OWLIndividual, OWLObjectPropertyAssertionAxiom, String> o1; | ||
@Mock | ||
OWLFrameSectionRow<OWLIndividual, OWLObjectPropertyAssertionAxiom, String> o2; | ||
@Mock | ||
OWLObjectPropertyAssertionAxiom opa1; | ||
@Mock | ||
OWLObjectPropertyAssertionAxiom opa2; | ||
@Mock | ||
OWLObjectProperty op1; | ||
@Mock | ||
OWLObjectProperty op2; | ||
@Mock | ||
OWLIndividual i1; | ||
@Mock | ||
OWLIndividual i2; | ||
|
||
OWLPropertyAssertionRowComparator<OWLObjectPropertyAssertionAxiom, String> comparator; | ||
|
||
@Before | ||
public void setUp() { | ||
comparator = new OWLPropertyAssertionRowComparator<>(delegate); | ||
} | ||
|
||
@Test | ||
public void testInferred1() { | ||
when(o1.isInferred()).thenReturn(true); | ||
when(o2.isInferred()).thenReturn(false); | ||
assertEquals(1, comparator.compare(o1, o2)); | ||
} | ||
|
||
@Test | ||
public void testInferred2() { | ||
when(o1.isInferred()).thenReturn(false); | ||
when(o2.isInferred()).thenReturn(true); | ||
assertEquals(-1, comparator.compare(o1, o2)); | ||
} | ||
|
||
@Test | ||
public void testDifferentProperty() { | ||
when(o1.getAxiom()).thenReturn(opa1); | ||
when(o2.getAxiom()).thenReturn(opa2); | ||
when(opa1.getProperty()).thenReturn(op1); | ||
when(opa2.getProperty()).thenReturn(op2); | ||
when(delegate.compare(op1, op2)).thenReturn(-2); | ||
assertEquals(-2, comparator.compare(o1, o2)); | ||
} | ||
|
||
@Test | ||
public void testDifferentIndividuals() { | ||
when(o1.getAxiom()).thenReturn(opa1); | ||
when(o2.getAxiom()).thenReturn(opa2); | ||
when(opa1.getProperty()).thenReturn(op1); | ||
when(opa2.getProperty()).thenReturn(op2); | ||
when(opa1.getObject()).thenReturn(i1); | ||
when(opa2.getObject()).thenReturn(i2); | ||
when(delegate.compare(op1, op2)).thenReturn(0); | ||
when(delegate.compare(i1, i2)).thenReturn(-2); | ||
assertEquals(-2, comparator.compare(o1, o2)); | ||
} | ||
|
||
@Test | ||
public void testSame() { | ||
when(o1.getAxiom()).thenReturn(opa1); | ||
when(o2.getAxiom()).thenReturn(opa2); | ||
when(opa1.getProperty()).thenReturn(op1); | ||
when(opa2.getProperty()).thenReturn(op2); | ||
when(opa1.getObject()).thenReturn(i1); | ||
when(opa2.getObject()).thenReturn(i2); | ||
when(delegate.compare(op1, op2)).thenReturn(0); | ||
when(delegate.compare(i1, i2)).thenReturn(0); | ||
assertEquals(0, comparator.compare(o1, o2)); | ||
} | ||
|
||
} |