+ /**
+ * core findIdMatch search method
+ *
+ * @param nam
+ * SeqIdName
+ * @return SequenceI
+ */
+ private SequenceI findIdMatch(
+ jalview.analysis.SequenceIdMatcher.SeqIdName nam)
+ {
+ Vector matches = new Vector();
+ while (names.containsKey(nam))
+ {
+ matches.addElement(names.remove(nam));
+ }
+ return pickbestMatch(nam, matches);
+ }
+ /**
+ * core findIdMatch search method for finding all equivalent matches
+ *
+ * @param nam
+ * SeqIdName
+ * @return SequenceI[]
+ */
+ private SequenceI[] findAllIdMatches(
+ jalview.analysis.SequenceIdMatcher.SeqIdName nam)
+ {
+ Vector matches = new Vector();
+ while (names.containsKey(nam))
+ {
+ matches.addElement(names.remove(nam));
+ }
+ SequenceI[] r=pickbestMatches(nam, matches);
+ return r;
+ }
+
+
+ private class SeqIdName
+ {
+ String id;
+
+ SeqIdName(String s)
+ {
+ if (s != null)
+ {
+ id = new String(s);
+ }
+ else
+ {
+ id = "";
+ }
+ }
+
+ public int hashCode()
+ {
+ return ((id.length() >= 4) ? id.substring(0, 4).hashCode() : id
+ .hashCode());
+ }
+
+ public boolean equals(Object s)
+ {
+ if (s instanceof SeqIdName)
+ {
+ return this.equals((SeqIdName) s);
+ }
+ else
+ {
+ if (s instanceof String)
+ {
+ return this.equals((String) s);
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * Characters that define the end of a unique sequence ID at the beginning
+ * of an arbitrary ID string JBPNote: This is a heuristic that will fail for
+ * arbritrarily extended sequence id's (like portions of an aligned set of
+ * repeats from one sequence)
+ */
+ private String WORD_SEP = "~. |#\\/<>!\""+((char)0x00A4)+"$%^*)}[@',?_";
+
+ /**
+ * matches if one ID properly contains another at a whitespace boundary.
+ * TODO: (JBPNote) These are not efficient. should use char[] for speed
+ * todo: (JBPNote) Set separator characters appropriately
+ *
+ * @param s
+ * SeqIdName
+ * @return boolean
+ */
+ public boolean equals(SeqIdName s)
+ {
+ // TODO: JAL-732 patch for cases when name includes a list of IDs, and the match contains one ID flanked
+ if (id.length() > s.id.length())
+ {
+ return id.startsWith(s.id) ? (WORD_SEP.indexOf(id.charAt(s.id
+ .length())) > -1) : false;
+ }
+ else
+ {
+ return s.id.startsWith(id) ? (s.id.equals(id) ? true : (WORD_SEP
+ .indexOf(s.id.charAt(id.length())) > -1)) : false;
+ }
+ }
+
+ public boolean equals(String s)
+ {
+ if (id.length() > s.length())
+ {
+ return id.startsWith(s) ? (WORD_SEP.indexOf(id.charAt(s.length())) > -1)
+ : false;
+ }
+ else
+ {
+ return s.startsWith(id) ? (s.equals(id) ? true : (WORD_SEP
+ .indexOf(s.charAt(id.length())) > -1)) : false;
+ }
+ }
+ }