From 7656f2889369cd62d8f8517c4a14d6d2597a46eb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Euzenat?= <Jerome.Euzenat@inria.fr>
Date: Wed, 9 Sep 2015 21:49:19 +0000
Subject: [PATCH] - implemented inverse() so that it return an object of the
 same type (no cast needed)

---
 .../inrialpes/exmo/align/impl/BasicAlignment.java  | 12 ++++++++----
 .../inrialpes/exmo/align/impl/ObjectAlignment.java |  6 ++++++
 src/fr/inrialpes/exmo/align/impl/URIAlignment.java |  7 +++++++
 .../exmo/align/impl/edoal/EDOALAlignment.java      | 14 +++++++++++++-
 4 files changed, 34 insertions(+), 5 deletions(-)

diff --git a/src/fr/inrialpes/exmo/align/impl/BasicAlignment.java b/src/fr/inrialpes/exmo/align/impl/BasicAlignment.java
index 78efbf36..edad15c8 100644
--- a/src/fr/inrialpes/exmo/align/impl/BasicAlignment.java
+++ b/src/fr/inrialpes/exmo/align/impl/BasicAlignment.java
@@ -775,21 +775,25 @@ public class BasicAlignment implements Alignment, Extensible {
      * ( o', o, n, inverse(r)) iff compose(r) exists.
      */
 
-    public Alignment inverse() throws AlignmentException {
+    public BasicAlignment inverse() throws AlignmentException {
 	BasicAlignment result = createNewAlignment( onto2, onto1 );
+	invertContent( result, "inverted", "http://exmo.inrialpes.fr/align/impl/BasicAlignment#inverse" );
+	return result;
+    }
+
+    public void invertContent( BasicAlignment result, String label, String method ) throws AlignmentException {
 	result.setFile1( getFile2() );
 	result.setFile2( getFile1() );
 	result.setType( invertType() );
 	result.setLevel( getLevel() );
-	result.setExtensions( extensions.convertExtension( "inverted", "http://exmo.inrialpes.fr/align/impl/BasicAlignment#inverse" ) );
+	result.setExtensions( extensions.convertExtension( label, method ) );
 	for ( Entry<Object,Object> e : namespaces.entrySet() ) {
 	    result.setXNamespace( (String)e.getKey(), (String)e.getValue() );
 	}
 	for ( Cell c : this ) {
 	    result.addCell( c.inverse() );
 	}
-	return (Alignment)result;
-    };
+    }
 
     /** Housekeeping **/
     public void dump(ContentHandler h) {
diff --git a/src/fr/inrialpes/exmo/align/impl/ObjectAlignment.java b/src/fr/inrialpes/exmo/align/impl/ObjectAlignment.java
index 810518f1..c0d79ebf 100644
--- a/src/fr/inrialpes/exmo/align/impl/ObjectAlignment.java
+++ b/src/fr/inrialpes/exmo/align/impl/ObjectAlignment.java
@@ -122,6 +122,12 @@ public class ObjectAlignment extends BasicAlignment {
 	return align;
     }
 
+    public ObjectAlignment inverse() throws AlignmentException {
+	ObjectAlignment result = createNewAlignment( onto2, onto1 );
+	invertContent( result, "inverted", "http://exmo.inrialpes.fr/align/impl/ObjectAlignment#inverse" );
+	return result;
+    }
+
     /**
      * This is a clone with the URI instead of Object objects
      */
diff --git a/src/fr/inrialpes/exmo/align/impl/URIAlignment.java b/src/fr/inrialpes/exmo/align/impl/URIAlignment.java
index aa37f263..713381bd 100644
--- a/src/fr/inrialpes/exmo/align/impl/URIAlignment.java
+++ b/src/fr/inrialpes/exmo/align/impl/URIAlignment.java
@@ -163,5 +163,12 @@ public class URIAlignment extends BasicAlignment {
 	return align;
     }
 
+    public URIAlignment inverse() throws AlignmentException {
+	URIAlignment result = createNewAlignment( onto2, onto1 );
+	invertContent( result, "inverted", "http://exmo.inrialpes.fr/align/impl/URIAlignment#inverse" );
+	return result;
+    }
+
+
 }
 
diff --git a/src/fr/inrialpes/exmo/align/impl/edoal/EDOALAlignment.java b/src/fr/inrialpes/exmo/align/impl/edoal/EDOALAlignment.java
index 2c0630e2..2f6d1d9d 100644
--- a/src/fr/inrialpes/exmo/align/impl/edoal/EDOALAlignment.java
+++ b/src/fr/inrialpes/exmo/align/impl/edoal/EDOALAlignment.java
@@ -345,7 +345,7 @@ public class EDOALAlignment extends BasicAlignment {
     // It has two difficulties
     // - it should call the current init() and not that of BasicAlignement
     // - it should catch the AlignmentException that it is supposed to raise
-    public Object clone() {
+    public EDOALAlignment clone() {
 	EDOALAlignment align = new EDOALAlignment();
 	try {
 	    align.init( (Ontology)getOntology1(), (Ontology)getOntology2() );
@@ -363,4 +363,16 @@ public class EDOALAlignment extends BasicAlignment {
 	return align;
     }
 
+    public EDOALAlignment createNewAlignment( Object onto1, Object onto2 ) throws AlignmentException {
+	EDOALAlignment align = new EDOALAlignment();
+	align.init( onto1, onto2 );
+	return align;
+    }
+
+    public EDOALAlignment inverse() throws AlignmentException {
+	EDOALAlignment result = createNewAlignment( onto2, onto1 );
+	invertContent( result, "inverted", "http://exmo.inrialpes.fr/align/impl/edoal/EDOALAlignment#inverse" );
+	return result;
+    }
+
  }
-- 
GitLab