+ /**
+ * 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 List<SequenceI> findAllIdMatches(
+ jalview.analysis.SequenceIdMatcher.SeqIdName nam)
+ {
+ ArrayList<SequenceI> matches = new ArrayList<SequenceI>();
+ while (names.containsKey(nam))
+ {
+ matches.add(names.remove(nam));
+ }
+ List<SequenceI> r = pickbestMatches(nam, matches);
+ return r;
+ }
+
+ class SeqIdName
+ {
+ String id;
+
+ SeqIdName(String s)
+ {
+ if (s != null)
+ {
+ id = s.toLowerCase();
+ }
+ else
+ {
+ id = "";
+ }
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return ((id.length() >= 4) ? id.substring(0, 4).hashCode() : id
+ .hashCode());
+ }
+
+ @Override
+ public boolean equals(Object s)
+ {
+ if (s == null)
+ {
+ return false;
+ }
+ if (s instanceof SeqIdName)
+ {
+ return this.stringequals(((SeqIdName) s).id);
+ }
+ else
+ {
+ if (s instanceof String)
+ {
+ return this.stringequals(((String) s).toLowerCase());
+ }
+ }
+
+ 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
+ * @return boolean
+ */
+ private boolean stringequals(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;
+ }
+ }
+
+ /**
+ * toString method returns the wrapped sequence id. For debugging purposes
+ * only, behaviour not guaranteed not to change.
+ */
+ @Override
+ public String toString()
+ {
+ return id;
+ }
+ }