From 1e7eda9ea67fff9a8929c3c1a03d701797ebfc14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Euzenat?= <Jerome.Euzenat@inria.fr> Date: Tue, 9 Mar 2010 19:34:39 +0000 Subject: [PATCH] - implemented missing hashCode (solve BUG #9680 Failed to redefine hashCode when equal is redefined) --- src/fr/inrialpes/exmo/align/impl/BasicCell.java | 6 +++++- src/fr/inrialpes/exmo/align/impl/BasicRelation.java | 3 +++ src/fr/inrialpes/exmo/align/impl/ObjectCell.java | 5 +++++ src/fr/inrialpes/exmo/align/impl/URICell.java | 6 +++++- src/fr/inrialpes/exmo/align/impl/edoal/EDOALCell.java | 6 +++++- src/fr/inrialpes/exmo/align/impl/edoal/EDOALRelation.java | 8 +++++++- src/fr/inrialpes/exmo/align/impl/edoal/Value.java | 2 +- 7 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/fr/inrialpes/exmo/align/impl/BasicCell.java b/src/fr/inrialpes/exmo/align/impl/BasicCell.java index c7910046..f655b64a 100644 --- a/src/fr/inrialpes/exmo/align/impl/BasicCell.java +++ b/src/fr/inrialpes/exmo/align/impl/BasicCell.java @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (C) INRIA, 2003-2005, 2007-2009 + * Copyright (C) INRIA, 2003-2005, 2007-2010 * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -72,6 +72,10 @@ public class BasicCell implements Cell, Comparable<Cell> { } } + public int hashCode() { + return 17 + 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/BasicRelation.java b/src/fr/inrialpes/exmo/align/impl/BasicRelation.java index 296775c1..80574c31 100644 --- a/src/fr/inrialpes/exmo/align/impl/BasicRelation.java +++ b/src/fr/inrialpes/exmo/align/impl/BasicRelation.java @@ -108,6 +108,9 @@ public class BasicRelation implements Relation return false; } } + public int hashCode() { + return 19+relation.hashCode(); + } /** Housekeeping **/ public void dump( ContentHandler h ){}; diff --git a/src/fr/inrialpes/exmo/align/impl/ObjectCell.java b/src/fr/inrialpes/exmo/align/impl/ObjectCell.java index 3e811a96..b78e7fe9 100644 --- a/src/fr/inrialpes/exmo/align/impl/ObjectCell.java +++ b/src/fr/inrialpes/exmo/align/impl/ObjectCell.java @@ -67,6 +67,11 @@ public class ObjectCell extends BasicCell { } } + 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 550193b1..b7f4ada2 100644 --- a/src/fr/inrialpes/exmo/align/impl/URICell.java +++ b/src/fr/inrialpes/exmo/align/impl/URICell.java @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (C) INRIA Rhône-Alpes, 2007-2008 + * Copyright (C) INRIA, 2007-2008, 2010 * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -76,6 +76,10 @@ public class URICell extends BasicCell { } } + 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 848e0599..86bbd80f 100644 --- a/src/fr/inrialpes/exmo/align/impl/edoal/EDOALCell.java +++ b/src/fr/inrialpes/exmo/align/impl/edoal/EDOALCell.java @@ -2,7 +2,7 @@ * $Id$ * * Sourceforge version 1.2 - 2008 - * Copyright (C) INRIA, 2007-2009 + * Copyright (C) INRIA, 2007-2010 * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -86,6 +86,10 @@ public class EDOALCell extends BasicCell { } } + 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; diff --git a/src/fr/inrialpes/exmo/align/impl/edoal/EDOALRelation.java b/src/fr/inrialpes/exmo/align/impl/edoal/EDOALRelation.java index d087cb9c..808e5fc3 100644 --- a/src/fr/inrialpes/exmo/align/impl/edoal/EDOALRelation.java +++ b/src/fr/inrialpes/exmo/align/impl/edoal/EDOALRelation.java @@ -2,7 +2,7 @@ * $Id$ * * Sourceforge version 1.3 - 2008 - * Copyright (C) INRIA, 2007-2009 + * Copyright (C) INRIA, 2007-2010 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by @@ -41,6 +41,8 @@ import org.xml.sax.ContentHandler; * In fact, for the EDOAL Mapping language, this encodes directions * but should be rewritten in order to achive a better implementation * + * I feel this is not used anymore + * * @author Jérôme Euzenat * @version $Id$ */ @@ -228,6 +230,10 @@ public class EDOALRelation implements Relation { } } + public int hashCode() { + return 5 + 3*type.hashCode() + 7*direction.hashCode() ; + } + /** Housekeeping **/ public void dump( ContentHandler h ){}; diff --git a/src/fr/inrialpes/exmo/align/impl/edoal/Value.java b/src/fr/inrialpes/exmo/align/impl/edoal/Value.java index 11b7c379..b220d8fb 100644 --- a/src/fr/inrialpes/exmo/align/impl/edoal/Value.java +++ b/src/fr/inrialpes/exmo/align/impl/edoal/Value.java @@ -65,7 +65,7 @@ public class Value { //implements Cloneable, Visitable { } public int hashCode() { - return value.hashCode(); + return 5*value.hashCode(); } public boolean equals(final Object o) { -- GitLab