Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.ensembl.util
Class StringUtil

    java.lang.Object
      org.ensembl.util.StringUtil

public class StringUtil
extends java.lang.Object

String Utility methods.

Version:
  $Revision: 1.32 $

Field Summary
`static java.util.Comparator` | `LENGTH_ORDER` Comparator which orders strings by length.

Constructor Summary
`StringUtil()`

Method Summary
`static java.lang.String` | `arrayToString(int[][] matrix)`
`static java.lang.String` | `briefOrUnset(java.lang.String s)` Converts s into a string representation of at most 10 characters or "unset" if s is null.
`static java.lang.String` | `capitaliseFirstLetter(java.lang.String s)` Capitalise first letter.
`static int` | `compare(java.lang.String str1, java.lang.String str2)` String comparison which handles null values.
`static java.lang.String` | `formatForPrinting(java.lang.Object o)` Convenience method which automatically calls o.toString() and delegates formatting to sister method.
`static java.lang.String` | `formatForPrinting(java.lang.String string)`
`static int` | `indexOfFirstDigit(java.lang.String s)`
`static int` | `parseInt(java.lang.String value)` Converts string to int.
`static java.lang.String` | `readTextFile(java.lang.String f)` Read a text file into a String.
`static java.lang.String` | `setOrUnset(java.lang.Object o)`
`static java.lang.String` | `sizeOrUnset(java.util.Collection c)`
`static boolean` | `stringInArray(java.lang.String str, java.lang.String[] a, boolean caseSensitive)` Check if a String is in an array of Strings.
`static java.lang.String` | `stringOrUnset(java.lang.String s)`
`static java.lang.String` | `toString(java.util.Collection collection)`
`static java.lang.String` | `toString(java.util.Collection collection, java.lang.String separator)`
`static java.lang.String` | `toString(int[] array)`
`static java.lang.String` | `toString(long[] array)` Convenience method for converting an array of longs into a string of numbers separated by commas.
`static java.lang.String` | `toString(long[] array, boolean ignoreZeroes)` Convenience method for converting an array of longs into a string of numbers separated by commas.
`static java.lang.String` | `toString(java.lang.Object[] array)`
`static java.lang.String` | `toString(java.lang.Object[] array, java.lang.String separator)`
`static java.lang.String` | `toString(java.lang.String[] array)`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### LENGTH_ORDER

    public static final java.util.Comparator LENGTH_ORDER

  Comparator which orders strings by length.

Constructor Detail

### StringUtil

    public StringUtil()

Method Detail

### parseInt

    public static int parseInt(java.lang.String value)
                        throws java.text.ParseException

  Converts string to int. In addition to handling 'normal' integers such 23452 it understands:
  - postfixes "m", "M", "mb", "MB" and "k", "kb", "K", "KB" e.g. 11m, 11.5mb, 11k.
  - commas e.g. 3,000 and 11,000,000

  Throws:
    `java.text.ParseException`

### formatForPrinting

    public static java.lang.String formatForPrinting(java.lang.String string)

### formatForPrinting

    public static java.lang.String formatForPrinting(java.lang.Object o)

  Convenience method which automatically calls o.toString() and delegates formatting to sister method.

### arrayToString

    public static java.lang.String arrayToString(int[][] matrix)

### toString

    public static java.lang.String toString(long[] array)

  Convenience method for converting an array of longs into a string of numbers separated by commas.

  Parameters:
    `array` - longs to be converted to a string
  Returns:
    string of numbers separated by commas or an empty string if the array is null, empty.

### toString

    public static java.lang.String toString(long[] array,
                                            boolean ignoreZeroes)

  Convenience method for converting an array of longs into a string of numbers separated by commas.

  Parameters:
    `array` - longs to be converted to a string
    `ignoreZeroes` - whether zeros should be excluded from the string
  Returns:
    string of numbers separated by commas or an empty string if the array is null, empty or full of zeroes and ignoreZeroes=true.

### toString

    public static java.lang.String toString(int[] array)

### toString

    public static java.lang.String toString(java.lang.String[] array)

### toString

    public static java.lang.String toString(java.util.Collection collection)

### toString

    public static java.lang.String toString(java.util.Collection collection,
                                            java.lang.String separator)

### toString

    public static java.lang.String toString(java.lang.Object[] array)

### toString

    public static java.lang.String toString(java.lang.Object[] array,
                                            java.lang.String separator)

### indexOfFirstDigit

    public static int indexOfFirstDigit(java.lang.String s)

  Returns:
    index of the first digit fround in the string, -1 if none found.

### compare

    public static final int compare(java.lang.String str1,
                                    java.lang.String str2)

  String comparison which handles null values. Basically the same as String.compare() except that "null" is a valid value which comes before ANY string and two "nulls" are equal.

### sizeOrUnset

    public static java.lang.String sizeOrUnset(java.util.Collection c)

  Returns:
    size as string or "null" if c==null.

### stringOrUnset

    public static java.lang.String stringOrUnset(java.lang.String s)

  Returns:
    s if not null else "unset".

### setOrUnset

    public static java.lang.String setOrUnset(java.lang.Object o)

  Returns:
    "set" if not null, "unset" if null.

### briefOrUnset

    public static java.lang.String briefOrUnset(java.lang.String s)

  Converts s into a string representation of at most 10 characters or "unset" if s is null.

  Returns:
    unset of s==null, or first few chars followed by "...", e.g. briefOrUnset("aactctgaaattcg") = "aactctgaaa..."

### capitaliseFirstLetter

    public static java.lang.String capitaliseFirstLetter(java.lang.String s)

  Capitalise first letter.

### readTextFile

    public static java.lang.String readTextFile(java.lang.String f)

  Read a text file into a String.

### stringInArray

    public static boolean stringInArray(java.lang.String str,
                                        java.lang.String[] a,
                                        boolean caseSensitive)

  Check if a String is in an array of Strings. The whole array is searched (until a match is found); this is quite slow but does not require the array to be sorted in any way beforehand.

  Parameters:
    `str` - The String to search for.
    `a` - The array to search through.
    `caseSensitive` - If true, case sensitive searching is done.
  Returns:
    true if str is in a.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD