- public DBRefEntry(DBRefEntry entry)
- {
- this(new String(entry.source), new String(entry.version), new String(entry.accessionId), new Mapping(entry.map));
- }
- public boolean equals(DBRefEntry entry) {
- if (entry==this)
- return true;
- if (entry==null)
- return false;
- if ((source!=null && entry.source!=null && source.equals(entry.source))
- &&
- (accessionId!=null && entry.accessionId!=null && accessionId.equals(entry.accessionId))
- &&
- (version!=null && entry.version!=null && version.equals(entry.version))
- &&
- ((map==null && entry.map==null) || (map!=null && entry.map!=null && map.equals(entry.map)))) {
- return true;
- }
+
+ /**
+ * Clone an entry, this time not allowing any null fields except map.
+ *
+ */
+ public DBRefEntry(DBRefEntryI entry)
+ {
+ this((entry.getSource() == null ? "" : new String(entry.getSource())),
+ (entry.getVersion() == null ? ""
+ : new String(entry.getVersion())),
+ (entry.getAccessionId() == null ? ""
+ : new String(entry.getAccessionId())),
+ (entry.getMap() == null ? null : new Mapping(entry.getMap())),
+ entry.isCanonical());
+ }
+
+ @Override
+ public boolean equals(Object o)
+ {
+ // TODO should also override hashCode to ensure equal objects have equal
+ // hashcodes
+
+ // if (o == null || !(o instanceof DBRefEntry))
+ // {
+ // return false;
+ // }
+ // DBRefEntry entry = (DBRefEntry) o;
+ // if (entry == this)
+ // {
+ // return true;
+ // }
+ Mapping em;
+ return (o != null && o instanceof DBRefEntry && (o == this || equalRef(
+ (DBRefEntry) o)
+ && (map == null) == ((em = ((DBRefEntry) o).map) == null)
+ && (map == null || map.equals(em))));
+ //
+ // {
+ // return true;
+ // }
+ // return false;
+ }
+
+ /**
+ * Answers true if this object is either equivalent to, or can be 'improved'
+ * by, the given entry. Specifically, answers true if
+ * <ul>
+ * <li>source and accession are identical (ignoring case)</li>
+ * <li>version is identical (ignoring case), or this version is of the format
+ * "someSource:0", in which case the version for the other entry replaces
+ * it</li>
+ * <li>mappings are not compared but if this entry has no mapping, replace
+ * with that for the other entry</li>
+ * </ul>
+ *
+ * @param other
+ * @return
+ */
+ @Override
+ public boolean updateFrom(DBRefEntryI other)
+ {
+ if (other == null)
+ {
+ return false;
+ }
+ if (other == this)
+ {
+ return true;
+ }
+
+ boolean improved = false;
+ /*
+ * source must either match or be both null
+ */
+ String otherSource = other.getSource();
+ if ((source == null && otherSource != null)
+ || (source != null && otherSource == null)
+ || (source != null && !source.equalsIgnoreCase(otherSource)))
+ {