diff --git a/src/fr/inrialpes/exmo/align/impl/BasicCell.java b/src/fr/inrialpes/exmo/align/impl/BasicCell.java index f655b64ace24da81b4971dedc275f4bf42b8c897..afe6ac4d56f69222b50f488c0f8e08e5680d6f58 100644 --- a/src/fr/inrialpes/exmo/align/impl/BasicCell.java +++ b/src/fr/inrialpes/exmo/align/impl/BasicCell.java @@ -64,12 +64,14 @@ public class BasicCell implements Cell, Comparable<Cell> { }; // the strength must be compared with regard to abstract types - public boolean equals( Cell c ) { - if ( c instanceof BasicCell ){ - return ( object1 == c.getObject1() && object2 == c.getObject2() && strength == c.getStrength() && (relation.equals( c.getRelation() )) ); - } else { - return false; - } + public boolean equals( Object c ) { + if ( c != null && c instanceof Cell ) return equals( (Cell)c ); + else return false; + } + + public boolean equals ( Cell c ) { + if ( c == null ) return false; + else return ( object1.equals(((BasicCell)c).getObject1()) && object2.equals(((BasicCell)c).getObject2()) && strength == ((BasicCell)c).getStrength() && (relation.equals( ((BasicCell)c).getRelation() )) ); } public int hashCode() { diff --git a/src/fr/inrialpes/exmo/align/impl/ObjectCell.java b/src/fr/inrialpes/exmo/align/impl/ObjectCell.java index 42bf209fc81eb9eacef492eb1cd07758ec0e4e30..6e6a9199162c2b03cd8a9ec5ea588694ac7ae5a5 100644 --- a/src/fr/inrialpes/exmo/align/impl/ObjectCell.java +++ b/src/fr/inrialpes/exmo/align/impl/ObjectCell.java @@ -56,21 +56,6 @@ public class ObjectCell extends BasicCell { super( id, ob1, ob2, rel, m ); }; - - // the strength must be compared with regard to abstract types - public boolean equals( Cell c ) { - if ( c instanceof ObjectCell ){ - return ( object1 == c.getObject1() && object2 == c.getObject2() && strength == c.getStrength() && (relation.equals( c.getRelation() )) ); - } else { - return false; - } - } - - public int hashCode() { - return 31 + 7*object1.hashCode() + 11*object2.hashCode() + relation.hashCode() + (int)(strength*150.); - } - - /** * Used to order the cells in an alignment: * -- this > c iff this.getStrength() < c.getStrength() -- diff --git a/src/fr/inrialpes/exmo/align/impl/URICell.java b/src/fr/inrialpes/exmo/align/impl/URICell.java index b7f4ada2397749cf6a51473e76c871c1792b21d4..8a3146e6a97a5d3a739521d48ecb21627750ba55 100644 --- a/src/fr/inrialpes/exmo/align/impl/URICell.java +++ b/src/fr/inrialpes/exmo/align/impl/URICell.java @@ -67,19 +67,6 @@ public class URICell extends BasicCell { // super( ob1, ob2, rel, m ); //}; - // the strength must be compared with regard to abstract types - public boolean equals( Cell c ) { - if ( c instanceof URICell ){ - return ( object1.equals(c.getObject1()) && object2.equals(c.getObject2()) && strength == c.getStrength() && (relation.equals( c.getRelation() )) ); - } else { - return false; - } - } - - public int hashCode() { - return 23 + 7*object1.hashCode() + 11*object2.hashCode() + relation.hashCode() + (int)(strength*150.); - } - public URI getObject1AsURI( Alignment al ) throws AlignmentException { return (URI)object1; }; diff --git a/src/fr/inrialpes/exmo/align/impl/edoal/EDOALCell.java b/src/fr/inrialpes/exmo/align/impl/edoal/EDOALCell.java index 86bbd80f9e0cb8ce123c5334dfc90e35db6a41f5..8bb0802e1722e21a951175f2b60c3c37b66b88e3 100644 --- a/src/fr/inrialpes/exmo/align/impl/edoal/EDOALCell.java +++ b/src/fr/inrialpes/exmo/align/impl/edoal/EDOALCell.java @@ -78,25 +78,14 @@ public class EDOALCell extends BasicCell { super( id, (Object)ob1, (Object)ob2, rel, m ); }; - public boolean equals( Cell c ) { - if ( c instanceof EDOALCell ){ - return ( object1.equals(c.getObject1()) && object2.equals(c.getObject2()) && strength == c.getStrength() && (relation.equals( c.getRelation() )) ); - } else { - return false; - } - } - - public int hashCode() { - return 11 + 7*object1.hashCode() + 11*object2.hashCode() + relation.hashCode() + (int)(strength*150.); - } - - // JE// Maybe do it in case Expressions have URI public URI getObject1AsURI( Alignment al ) throws AlignmentException { - return null; + if ( object1 instanceof Id ) return ((Id)object1).getURI(); + else return null; //throw new AlignmentException( "Cannot convert to URI "+object1 ); } public URI getObject2AsURI( Alignment al ) throws AlignmentException { - return null; + if ( object2 instanceof Id ) return ((Id)object2).getURI(); + else return null; //throw new AlignmentException( "Cannot convert to URI "+object2 ); } diff --git a/test/src/BasicAlignmentTest.java b/test/src/BasicAlignmentTest.java index ffece5dcb4391ca0134c3844eb643bfc6243c152..28ac314c2c6bd759e8cbf097775d7bf3a4749042 100644 --- a/test/src/BasicAlignmentTest.java +++ b/test/src/BasicAlignmentTest.java @@ -37,6 +37,7 @@ import fr.inrialpes.exmo.align.impl.BasicAlignment; import fr.inrialpes.exmo.align.impl.BasicCell; import fr.inrialpes.exmo.align.impl.BasicRelation; import fr.inrialpes.exmo.align.impl.URIAlignment; +import fr.inrialpes.exmo.align.impl.URICell; import fr.inrialpes.exmo.align.parser.AlignmentParser; import org.semanticweb.owl.align.Alignment; @@ -71,7 +72,8 @@ public class BasicAlignmentTest { assertEquals( result.nbCells(), 1, "Alignment should contain 1 cell" ); } - private static Cell cell1, cell2, cell3, cell4, cell5; + private static Cell cell1, cell2, cell3, cell4, cell5, cell6; + private static Cell ucell1, ucell2, ucell3, ucell4, ucell5, ucell6; /** * @throws java.lang.Exception @@ -81,6 +83,7 @@ public class BasicAlignmentTest { URI cls1 = URI.create( "http://example.org/test#cls1" ); URI cls2 = URI.create( "http://example.org/test#cls2" ); URI cls3 = URI.create( "http://example.org/test#cls3" ); + URI cls4 = URI.create( "http://example.org/test#cls3" ); Relation rel1 = new BasicRelation( "=" ); Relation rel2 = new BasicRelation( "<" ); cell1 = new BasicCell( "1", cls1, cls2, rel1, 0); @@ -88,16 +91,17 @@ public class BasicAlignmentTest { cell3 = new BasicCell( "3", cls1, cls3, rel1, 0); cell4 = new BasicCell( "4", cls1, cls2, rel2, 0); cell5 = new BasicCell( "5", cls1, cls2, rel1, .5); + cell6 = new BasicCell( "6", cls1, cls4, rel1, 0); + ucell1 = new URICell( "1", cls1, cls2, rel1, 0); + ucell2 = new URICell( "2", cls1, cls2, rel1, 0); + ucell3 = new URICell( "3", cls1, cls3, rel1, 0); + ucell4 = new URICell( "4", cls1, cls2, rel2, 0); + ucell5 = new URICell( "5", cls1, cls2, rel1, .5); + ucell6 = new URICell( "6", cls1, cls4, rel1, 0); + assertTrue( cls3.equals( cls4 ) ); // Check that URIs are correct! + assertTrue( cls3.hashCode() == cls4.hashCode() ); } - /** - * @throws java.lang.Exception - */ - @AfterClass(groups = { "raw", "full" }, alwaysRun = true ) - public static void tearDownAfterClass() throws Exception { - cell1 = cell2 = cell3 = cell4 = cell5 = null; - } - @Test(groups = { "full", "raw" }) public void testEquals() { assertTrue( cell1.equals( cell1 ) ); // 1 == 1 @@ -107,6 +111,7 @@ public class BasicAlignmentTest { assertTrue( !cell1.equals( cell3 ) ); // 1 != 3 assertTrue( !cell1.equals( cell4 ) ); // 1 != 4 assertTrue( !cell1.equals( cell5 ) ); // 1 != 5 + assertTrue( cell6.equals( cell3 ) ); // 6 == 3 } @Test(groups = { "full", "raw" }) @@ -118,6 +123,32 @@ public class BasicAlignmentTest { assertTrue( !cell1.equals( (Object) cell3 ) ); // 1 != 3 assertTrue( !cell1.equals( (Object) cell4 ) ); // 1 != 4 assertTrue( !cell1.equals( (Object) cell5 ) ); // 1 != 5 + assertTrue( cell6.equals( (Object)cell3 ) ); // 6 == 3 + } + + // These have been added because equals is not redefined in URICell anymore + @Test(groups = { "full", "raw" }) + public void testUEquals() { + assertTrue( ucell1.equals( ucell1 ) ); // 1 == 1 + assertTrue( ucell1.equals( ucell2 ) ); // 1 == 2 + assertTrue( ucell2.equals( ucell1 ) ); // 2 == 1 + assertTrue( !ucell1.equals( null ) ); // 1 != null + assertTrue( !ucell1.equals( ucell3 ) ); // 1 != 3 + assertTrue( !ucell1.equals( ucell4 ) ); // 1 != 4 + assertTrue( !ucell1.equals( ucell5 ) ); // 1 != 5 + assertTrue( cell6.equals( cell3 ) ); // 6 == 3 + } + + @Test(groups = { "full", "raw" }) + public void testUEqualsObject() { + assertTrue( ucell1.equals( (Object) ucell1 ) ); // 1 == 1 + assertTrue( ucell1.equals( (Object) ucell2 ) ); // 1 == 2 + assertTrue( ucell2.equals( (Object) ucell1 ) ); // 2 == 1 + assertTrue( !ucell1.equals( (Object) null ) ); // 1 != null + assertTrue( !ucell1.equals( (Object) ucell3 ) ); // 1 != 3 + assertTrue( !ucell1.equals( (Object) ucell4 ) ); // 1 != 4 + assertTrue( !ucell1.equals( (Object) ucell5 ) ); // 1 != 5 + assertTrue( ucell6.equals( (Object)ucell3 ) ); // 6 == 3 } @Test(groups = { "full", "raw" }) @@ -125,6 +156,15 @@ public class BasicAlignmentTest { assertTrue( cell1.equals( cell2 ) && cell1.hashCode() == cell2.hashCode() ); assertTrue( cell1.equals( cell1 ) && cell1.hashCode() == cell1.hashCode() ); assertTrue( cell2.equals( cell1 ) && cell2.hashCode() == cell1.hashCode() ); + assertTrue( cell3.equals( cell6 ) && cell3.hashCode() == cell6.hashCode() ); } + /** + * @throws java.lang.Exception + */ + @AfterClass(groups = { "raw", "full" }, alwaysRun = true ) + public static void tearDownAfterClass() throws Exception { + cell1 = cell2 = cell3 = cell4 = cell5 = cell6 = null; + } + }