Merge branch 'develop' into spike/JAL-4047/JAL-4048_columns_in_sequenceID
[jalview.git] / src / jalview / util / StringUtils.java
index 7e1b8ad..89bc36d 100644 (file)
@@ -202,18 +202,18 @@ public class StringUtils
       jv.clear();
       if (DEBUG)
       {
-        System.err.println("Array from '" + delimiter
+        jalview.bin.Console.errPrintln("Array from '" + delimiter
                 + "' separated List:\n" + v.length);
         for (int i = 0; i < v.length; i++)
         {
-          System.err.println("item " + i + " '" + v[i] + "'");
+          jalview.bin.Console.errPrintln("item " + i + " '" + v[i] + "'");
         }
       }
       return v;
     }
     if (DEBUG)
     {
-      System.err.println(
+      jalview.bin.Console.errPrintln(
               "Empty Array from '" + delimiter + "' separated List");
     }
     return null;
@@ -249,13 +249,13 @@ public class StringUtils
       {
         System.err
                 .println("Returning '" + separator + "' separated List:\n");
-        System.err.println(v);
+        jalview.bin.Console.errPrintln(v);
       }
       return v.toString();
     }
     if (DEBUG)
     {
-      System.err.println(
+      jalview.bin.Console.errPrintln(
               "Returning empty '" + separator + "' separated List\n");
     }
     return "" + separator;
@@ -586,6 +586,15 @@ public class StringUtils
     return min < text.length() + 1 ? min : -1;
   }
 
+  public static boolean equalsIgnoreCase(String s1, String s2)
+  {
+    if (s1 == null || s2 == null)
+    {
+      return s1 == s2;
+    }
+    return s1.toLowerCase(Locale.ROOT).equals(s2.toLowerCase(Locale.ROOT));
+  }
+
   public static int indexOfFirstWhitespace(String text)
   {
     int index = -1;
@@ -600,6 +609,7 @@ public class StringUtils
 
   /*
    * implementation of String.replaceLast.
+   * Replaces only the last occurrence of toReplace in string with replacement.
    */
   public static String replaceLast(String string, String toReplace,
           String replacement)
@@ -607,13 +617,31 @@ public class StringUtils
     int pos = string.lastIndexOf(toReplace);
     if (pos > -1)
     {
-      return string.substring(0, pos) + replacement
-              + string.substring(pos + toReplace.length());
+      return new StringBuilder().append(string.substring(0, pos))
+              .append(replacement)
+              .append(string.substring(pos + toReplace.length()))
+              .toString();
     }
     else
     {
       return string;
     }
+
   }
 
+  /* 
+   * return the maximum length of a List of Strings
+   */
+  public static int maxLength(List<String> l)
+  {
+    int max = 0;
+    for (String s : l)
+    {
+      if (s == null)
+        continue;
+      if (s.length() > max)
+        max = s.length();
+    }
+    return max;
+  }
 }