Merge remote-tracking branch 'origin/bug/JAL-2282' into develop
[jalview.git] / src / jalview / util / Comparison.java
index 5605a53..5269d4f 100644 (file)
@@ -249,6 +249,18 @@ public class Comparison
   }
 
   /**
+   * Overloaded method signature to test whether a single sequence is nucleotide
+   * (that is, more than 85% CGTA)
+   * 
+   * @param seq
+   * @return
+   */
+  public static final boolean isNucleotide(SequenceI seq)
+  {
+    return isNucleotide(new SequenceI[] { seq });
+  }
+
+  /**
    * Answers true if more than 85% of the sequence residues (ignoring gaps) are
    * A, G, C, T or U, else false. This is just a heuristic guess and may give a
    * wrong answer (as AGCT are also amino acid codes).
@@ -403,4 +415,35 @@ public class Comparison
             .size()]);
     return isNucleotide(oneDArray);
   }
+
+  /**
+   * Compares two chars either case sensitively or case insensitively depending
+   * on the caseSensitive flag
+   * 
+   * @param c1
+   *          first char
+   * @param c2
+   *          second char to compare with
+   * @param caseSensitive
+   *          if true comparison will be case sensitive otherwise its not
+   * @return
+   */
+  public static boolean compareChars(char c1, char c2, boolean caseSensitive)
+  {
+    boolean sameCase = (Character.isUpperCase(c1) && Character
+            .isUpperCase(c2))
+            || (Character.isLowerCase(c1) && Character.isLowerCase(c2));
+    if (sameCase)
+    {
+      return c1 == c2;
+    }
+    else if (caseSensitive)
+    {
+      return false;
+    }
+    else
+    {
+      return Character.toUpperCase(c1) == Character.toUpperCase(c2);
+    }
+  }
 }