From: gmungoc Date: Wed, 24 Apr 2019 15:05:56 +0000 (+0100) Subject: JAL-3010 TEMPORARY patch for BioJava bug to save all synonyms X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=fefafff8f5082392f6dc59307738dc8b2be103d5;p=jalview.git JAL-3010 TEMPORARY patch for BioJava bug to save all synonyms --- diff --git a/src/org/biojava/nbio/ontology/Synonym.java b/src/org/biojava/nbio/ontology/Synonym.java new file mode 100644 index 0000000..3902026 --- /dev/null +++ b/src/org/biojava/nbio/ontology/Synonym.java @@ -0,0 +1,128 @@ +/* + * BioJava development code + * + * This code may be freely distributed and modified under the + * terms of the GNU Lesser General Public Licence. This should + * be distributed with the code. If you do not have a copy, + * see: + * + * http://www.gnu.org/copyleft/lesser.html + * + * Copyright for this code is held jointly by the individual + * authors. These should be listed in @author doc comments. + * + * For more information on the BioJava project and its aims, + * or to join the biojava-l mailing list, visit the home page + * at: + * + * http://www.biojava.org/ + * + * Created on Jan 24, 2008 + * + */ + +package org.biojava.nbio.ontology; + +import java.util.Comparator; + + +public class Synonym implements Comparable{ + + + public final static int UNKNOWN_SCOPE = -1; + public final static int RELATED_SYNONYM = 0; + public final static int EXACT_SYNONYM = 1; + public final static int NARROW_SYNONYM = 2; + public final static int BROAD_SYNONYM = 3; + + int scope; + String category; + String name; + + @Override + public String toString(){ + String txt = "Synonym: name:"+name+ " category:" + category + " scope: " +scope; + return txt; + } + + @Override + public int hashCode() + { + return toString().hashCode(); + } + + @Override + public boolean equals(Object obj) + { + return obj instanceof Synonym + && ((Synonym) obj).toString().equals(this.toString()); + } + + public final static Comparator COMPARATOR = new Comparator() + { + @Override + public int compare(Synonym a, Synonym b) { + if (a == null && b == null) + { + return 0; + } + if (a == null) + { + return -1; + } + if (b == null) + { + return 1; + } + if (a.equals(b)) + { + return 0; + } + String catA = a.getCategory(); + String catB = b.getCategory(); + if (catA == null && catB != null) + { + return 1; + } + if (catA != null && catB == null) + { + return -1; + } + if (catA != null && catB != null) + { + int comp = catA.compareToIgnoreCase(catB); + if (comp != 0) + { + return comp; + } + } + // todo check for null name + return a.getName().compareToIgnoreCase(b.getName()); + } + }; + + public Synonym() { + } + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + public String getCategory() { + return category; + } + public void setCategory(String category) { + this.category = category; + } + public int getScope() { + return scope; + } + public void setScope(int scope) { + this.scope = scope; + } + @Override + public int compareTo(Synonym o) { + return COMPARATOR.compare(this, o); + } +}