+ DBRefEntry dBRefEntry)
+ {
+ if (string == null || dBRefEntry == null)
+ {
+ return false;
+ }
+ String coordsys = dasCoordinateSystemsLookup.get(string.toLowerCase());
+ return coordsys == null ? false : coordsys.equals(dBRefEntry
+ .getSource());
+ }
+
+ /**
+ * look up source in an internal list of database reference sources and return
+ * the canonical jalview name for the source, or the original string if it has
+ * no canonical form.
+ *
+ * @param source
+ * @return canonical jalview source (one of jalview.datamodel.DBRefSource.*)
+ * or original source
+ */
+ public static String getCanonicalName(String source)
+ {
+ if (source == null)
+ {
+ return null;
+ }
+ String canonical = canonicalSourceNameLookup.get(source.toLowerCase());
+ return canonical == null ? source : canonical;
+ }
+
+ /**
+ * Returns an array of those references that match the given entry, or null if
+ * no matches. Currently uses a comparator which matches if
+ * <ul>
+ * <li>database sources are the same</li>
+ * <li>accession ids are the same</li>
+ * <li>both have no mapping, or the mappings are the same</li>
+ * </ul>
+ *
+ * @param ref
+ * Set of references to search
+ * @param entry
+ * pattern to match
+ * @return
+ */
+ public static DBRefEntry[] searchRefs(DBRefEntry[] ref, DBRefEntry entry)
+ {
+ return searchRefs(ref, entry,
+ matchDbAndIdAndEitherMapOrEquivalentMapList);
+ }
+
+ /**
+ * Returns an array of those references that match the given entry, according
+ * to the given comparator. Returns null if no matches.
+ *
+ * @param refs
+ * an array of database references to search
+ * @param entry
+ * an entry to compare against
+ * @param comparator
+ * @return
+ */
+ static DBRefEntry[] searchRefs(DBRefEntry[] refs, DBRefEntry entry,
+ DbRefComp comparator)
+ {
+ if (refs == null || entry == null)
+ {
+ return null;
+ }
+ List<DBRefEntry> rfs = new ArrayList<DBRefEntry>();
+ for (int i = 0; i < refs.length; i++)
+ {
+ if (comparator.matches(entry, refs[i]))
+ {
+ rfs.add(refs[i]);
+ }
+ }
+ return rfs.size() == 0 ? null : rfs.toArray(new DBRefEntry[rfs.size()]);
+ }
+
+ interface DbRefComp
+ {
+ public boolean matches(DBRefEntry refa, DBRefEntry refb);
+ }
+
+ /**
+ * match on all non-null fields in refa
+ */
+ public static DbRefComp matchNonNullonA = new DbRefComp()
+ {
+ public boolean matches(DBRefEntry refa, DBRefEntry refb)
+ {
+ if (refa.getSource() == null
+ || refb.getSource().equals(refa.getSource()))
+ {
+ if (refa.getVersion() == null
+ || refb.getVersion().equals(refa.getVersion()))
+ {
+ if (refa.getAccessionId() == null
+ || refb.getAccessionId().equals(refa.getAccessionId()))
+ {
+ if (refa.getMap() == null
+ || (refb.getMap() != null && refb.getMap().equals(
+ refa.getMap())))
+ {
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+ }
+ };
+
+ /**
+ * either field is null or field matches for all of source, version, accession
+ * id and map.
+ */
+ public static DbRefComp matchEitherNonNull = new DbRefComp()
+ {
+ public boolean matches(DBRefEntry refa, DBRefEntry refb)
+ {
+ if ((refa.getSource() == null || refb.getSource() == null)
+ || refb.getSource().equals(refa.getSource()))
+ {
+ if ((refa.getVersion() == null || refb.getVersion() == null)
+ || refb.getVersion().equals(refa.getVersion()))
+ {
+ if ((refa.getAccessionId() == null || refb.getAccessionId() == null)
+ || refb.getAccessionId().equals(refa.getAccessionId()))
+ {
+ if ((refa.getMap() == null || refb.getMap() == null)
+ || (refb.getMap() != null && refb.getMap().equals(
+ refa.getMap())))
+ {
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+ }
+ };
+
+ /**
+ * accession ID and DB must be identical. Version is ignored. Map is either
+ * not defined or is a match (or is compatible?)
+ */
+ public static DbRefComp matchDbAndIdAndEitherMap = new DbRefComp()
+ {
+ public boolean matches(DBRefEntry refa, DBRefEntry refb)
+ {
+ if (refa.getSource() != null && refb.getSource() != null
+ && refb.getSource().equals(refa.getSource()))
+ {
+ // We dont care about version
+ // if ((refa.getVersion()==null || refb.getVersion()==null)
+ // || refb.getVersion().equals(refa.getVersion()))
+ // {
+ if (refa.getAccessionId() != null && refb.getAccessionId() != null
+ || refb.getAccessionId().equals(refa.getAccessionId()))
+ {
+ if ((refa.getMap() == null || refb.getMap() == null)
+ || (refa.getMap() != null && refb.getMap() != null && refb
+ .getMap().equals(refa.getMap())))
+ {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+ };
+
+ /**
+ * accession ID and DB must be identical. Version is ignored. No map on either
+ * or map but no maplist on either or maplist of map on a is the complement of
+ * maplist of map on b.
+ */
+ public static DbRefComp matchDbAndIdAndComplementaryMapList = new DbRefComp()
+ {
+ public boolean matches(DBRefEntry refa, DBRefEntry refb)
+ {
+ if (refa.getSource() != null && refb.getSource() != null
+ && refb.getSource().equals(refa.getSource()))
+ {
+ // We dont care about version
+ // if ((refa.getVersion()==null || refb.getVersion()==null)
+ // || refb.getVersion().equals(refa.getVersion()))
+ // {
+ if (refa.getAccessionId() != null && refb.getAccessionId() != null
+ || refb.getAccessionId().equals(refa.getAccessionId()))
+ {
+ if ((refa.getMap() == null && refb.getMap() == null)
+ || (refa.getMap() != null && refb.getMap() != null))
+ {
+ if ((refb.getMap().getMap() == null && refa.getMap().getMap() == null)
+ || (refb.getMap().getMap() != null
+ && refa.getMap().getMap() != null && refb
+ .getMap().getMap().getInverse()
+ .equals(refa.getMap().getMap())))
+ {
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+ }
+ };
+
+ /**
+ * accession ID and DB must be identical. Version is ignored. No map on both
+ * or or map but no maplist on either or maplist of map on a is equivalent to
+ * the maplist of map on b.
+ */
+ public static DbRefComp matchDbAndIdAndEquivalentMapList = new DbRefComp()