gate.util
Class Strings

java.lang.Object
  extended by gate.util.Strings

public class Strings
extends Object

Some utilities for use with Strings.


Constructor Summary
Strings()
           
 
Method Summary
static String addLineNumbers(String text)
          Helper method to add line numbers to a string
static String addLineNumbers(String text, int startLine)
           
static String addPadding(String pad, int n)
          Add n pad characters to pad.
static String crop(String text, int maxLength)
          Crop the text in the middle if too long.
static String getFileSep()
          Get local fashion for file separators (e.g. "/").
static String getNl()
          Get local fashion for newlines.
static String getPathSep()
          Get local fashion for path separators (e.g. ":").
static String humanReadableByteCount(long bytes, boolean base10)
          Converts a size given as a number of bytes (e.g. a file size) to a human-readable string.
static Map<String,String> toMap(String string)
          Get back a Map of String*String from its String representation.
static LinkedHashSet<String> toSet(String string, String separator)
          Get back a Set of String from its String representation.
static String toString(LinkedHashSet<String> set)
          Create a String representation of a Set of String with the format [value, value].
static String toString(Map<String,String> map)
          Create a String representation of a Map of String*String with the format {key=value, key=value}.
static String toString(Object object)
          Convert about any object to a human readable string.
static String unescape(String str)
          A method to unescape Java strings, returning a string containing escape sequences into the respective character. i.e. "\" followed by "t" is turned into the tab character.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Strings

public Strings()
Method Detail

getNl

public static String getNl()
Get local fashion for newlines.


getPathSep

public static String getPathSep()
Get local fashion for path separators (e.g. ":").


getFileSep

public static String getFileSep()
Get local fashion for file separators (e.g. "/").


addPadding

public static String addPadding(String pad,
                                int n)
Add n pad characters to pad.


addLineNumbers

public static String addLineNumbers(String text)
Helper method to add line numbers to a string


addLineNumbers

public static String addLineNumbers(String text,
                                    int startLine)

unescape

public static String unescape(String str)
A method to unescape Java strings, returning a string containing escape sequences into the respective character. i.e. "\" followed by "t" is turned into the tab character.

Parameters:
str - the string to unescape
Returns:
a new unescaped string of the one passed in

humanReadableByteCount

public static String humanReadableByteCount(long bytes,
                                            boolean base10)
Converts a size given as a number of bytes (e.g. a file size) to a human-readable string.

Parameters:
bytes - the size to be converted.
base10 - if true then the multiplier used is 10^3 (i.e. 1000 bytes are reported as 1kB, etc.); otherwise 1024 is used as a multiplier (1024 bytes is 1KiB, etc.).
Returns:
a human readable version of a file size

toString

public static String toString(Object object)
Convert about any object to a human readable string.
Use Arrays.deepToString(Object[]) to convert an array or a collection.

Parameters:
object - object to be converted to a string
Returns:
a string representation of the object, the empty string if null.

toString

public static String toString(LinkedHashSet<String> set)
Create a String representation of a Set of String with the format [value, value]. Escape with a backslash the separator character.

Parameters:
set - set to convert to one String
Returns:
a String that represent the set
See Also:
toSet(String, String)

toString

public static String toString(Map<String,String> map)
Create a String representation of a Map of String*String with the format {key=value, key=value}. Escape with a backslash the separator characters.

Parameters:
map - map to convert to one String
Returns:
a String that represent the map
See Also:
toMap(String)

toSet

public static LinkedHashSet<String> toSet(String string,
                                          String separator)
Get back a Set of String from its String representation. Unescape backslashed separator characters.

Parameters:
string - String to convert to a List
separator - String that delimits the element of the set
Returns:
a linked hashset
See Also:
toString(java.util.LinkedHashSet)

toMap

public static Map<String,String> toMap(String string)
Get back a Map of String*String from its String representation. Unescape backslashed separator characters.

Parameters:
string - String to convert to a Map
Returns:
a Map
See Also:
toString(java.util.Map)

crop

public static String crop(String text,
                          int maxLength)
Crop the text in the middle if too long.

Parameters:
text - text to crop
maxLength - maximum length of the text
Returns:
cropped text if needed otherwise the same text