JAL-3438 spotless for 2.11.2.0
[jalview.git] / src / jalview / analysis / SequenceIdMatcher.java
index f744ed1..e3a9b29 100755 (executable)
@@ -20,6 +20,8 @@
  */
 package jalview.analysis;
 
+import java.util.Locale;
+
 import jalview.datamodel.DBRefEntry;
 import jalview.datamodel.SequenceI;
 
@@ -74,13 +76,13 @@ public class SequenceIdMatcher
       dbseq = dbseq.getDatasetSequence();
     }
     // add in any interesting identifiers
-    if (dbseq.getDBRefs() != null)
+    List<DBRefEntry> dbr = dbseq.getDBRefs();
+    if (dbr != null)
     {
-      DBRefEntry dbr[] = dbseq.getDBRefs();
       SeqIdName sid = null;
-      for (int r = 0; r < dbr.length; r++)
+      for (int r = 0, nr = dbr.size(); r < nr; r++)
       {
-        sid = new SeqIdName(dbr[r].getAccessionId());
+        sid = new SeqIdName(dbr.get(r).getAccessionId());
         if (!names.containsKey(sid))
         {
           names.put(sid, seq);
@@ -147,9 +149,8 @@ public class SequenceIdMatcher
       names.put(new SeqIdName(cand.getName()), cand);
       int q, w, candlen = cand.getName().length();
       // keep the one with an id 'closer' to the given seqnam string
-      if ((q = Math.abs(matchlen - namlen)) > (w = Math.abs(candlen
-              - namlen))
-              && candlen > matchlen)
+      if ((q = Math.abs(matchlen - namlen)) > (w = Math
+              .abs(candlen - namlen)) && candlen > matchlen)
       {
         best.clear();
         match = cand;
@@ -290,7 +291,7 @@ public class SequenceIdMatcher
     {
       if (s != null)
       {
-        id = new String(s.toLowerCase());
+        id = s.toLowerCase(Locale.ROOT);
       }
       else
       {
@@ -301,8 +302,8 @@ public class SequenceIdMatcher
     @Override
     public int hashCode()
     {
-      return ((id.length() >= 4) ? id.substring(0, 4).hashCode() : id
-              .hashCode());
+      return ((id.length() >= 4) ? id.substring(0, 4).hashCode()
+              : id.hashCode());
     }
 
     @Override
@@ -314,13 +315,13 @@ public class SequenceIdMatcher
       }
       if (s instanceof SeqIdName)
       {
-        return this.equals(((SeqIdName) s).id);
+        return this.stringequals(((SeqIdName) s).id);
       }
       else
       {
         if (s instanceof String)
         {
-          return this.equals((String) s);
+          return this.stringequals(((String) s).toLowerCase(Locale.ROOT));
         }
       }
 
@@ -344,18 +345,31 @@ public class SequenceIdMatcher
      * @param s
      * @return boolean
      */
-    public boolean equals(String s)
+    private boolean stringequals(String s)
     {
       if (id.length() > s.length())
       {
-        return id.startsWith(s) ? (WORD_SEP.indexOf(id.charAt(s.length())) > -1)
+        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;
+        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;
+    }
   }
 }