com.alee.utils
Class TextUtils

java.lang.Object
  extended by com.alee.utils.TextUtils

public final class TextUtils
extends java.lang.Object

This class provides a set of utilities to work with various text usage cases.

Author:
Mikle Garin

Constructor Summary
TextUtils()
           
 
Method Summary
static java.lang.String createString(java.lang.String character, int length)
          Creates new string filled with specified amount of same characters.
static
<E extends java.lang.Enum<E>>
java.lang.String
enumListToString(java.util.List<E> enumList)
          Converts list of enumeration constants into string with list of enumeration constants and returns it.
static
<E extends java.lang.Enum<E>>
java.util.List<E>
enumStringToList(java.lang.String enumString, java.lang.Class<E> enumClass)
          Converts string with list of enumeration constants into real list of enumeration constants and returns it.
static java.lang.Integer findFirstNumber(java.lang.String text)
          Returns first number found in text.
static java.lang.String generateId()
          Returns random ID with default prefix and suffix.
static java.lang.String generateId(java.lang.String prefix)
          Returns random ID with specified prefix and default suffix.
static java.lang.String generateId(java.lang.String prefix, java.lang.String suffix)
          Returns random ID with specified prefix and suffix.
static java.lang.String getWord(java.lang.String text, int location)
          Returns a word from text at the specified location.
static int getWordEnd(java.lang.String text, int location)
          Returns a word end index at the specified location.
static int getWordStart(java.lang.String text, int location)
          Returns a word start index at the specified location.
static
<T> java.lang.String
listToString(java.util.List<T> list, java.lang.String separator, TextProvider<T> textProvider)
          Returns single text combined using list of strings and specified separator.
static java.lang.String listToString(java.util.List list, java.lang.String separator)
          Returns single text combined using list of strings and specified separator.
static java.awt.Point parsePoint(java.lang.String text)
          Returns point extracted from text.
static java.awt.Point parsePoint(java.lang.String text, java.lang.String separator)
          Returns point extracted from text.
static java.lang.String removeControlSymbols(java.lang.String text)
          Returns text with all control symbols removed.
static java.lang.String removeFirstLines(java.lang.String text, int count)
          Returns text with first lines removed.
static java.lang.String shortenText(java.lang.String text, int maxLength, boolean addDots)
          Returns shortened text.
static java.lang.String shortenTextEnd(java.lang.String text, int maxLength, boolean addDots)
          Returns shortened text.
static java.util.List<java.lang.String> split(java.lang.String text, java.lang.String separator)
          Returns a list of text parts splitted using specified separator.
static java.util.List<java.lang.Integer> stringToIntList(java.lang.String string, java.lang.String separator)
          Returns a list of integer parts splitted using specified separator.
static java.util.List<java.lang.String> stringToList(java.lang.String string, java.lang.String separator)
          Returns a list of text parts splitted using specified separator.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TextUtils

public TextUtils()
Method Detail

findFirstNumber

public static java.lang.Integer findFirstNumber(java.lang.String text)
Returns first number found in text.

Parameters:
text - text to search through
Returns:
first found number

getWord

public static java.lang.String getWord(java.lang.String text,
                                       int location)
Returns a word from text at the specified location.

Parameters:
text - text to retrieve the word from
location - word location
Returns:
word

getWordStart

public static int getWordStart(java.lang.String text,
                               int location)
Returns a word start index at the specified location.

Parameters:
text - text to retrieve the word start index from
location - word location
Returns:
word start index

getWordEnd

public static int getWordEnd(java.lang.String text,
                             int location)
Returns a word end index at the specified location.

Parameters:
text - text to retrieve the word end index from
location - word location
Returns:
word end index

removeFirstLines

public static java.lang.String removeFirstLines(java.lang.String text,
                                                int count)
Returns text with first lines removed.

Parameters:
text - text to crop
count - lines count to crop
Returns:
cropped text

split

public static java.util.List<java.lang.String> split(java.lang.String text,
                                                     java.lang.String separator)
Returns a list of text parts splitted using specified separator.

Parameters:
text - text to split
separator - text parts separator
Returns:
list of splitted parts

parsePoint

public static java.awt.Point parsePoint(java.lang.String text)
Returns point extracted from text.

Parameters:
text - text to extract point from
Returns:
extracted point

parsePoint

public static java.awt.Point parsePoint(java.lang.String text,
                                        java.lang.String separator)
Returns point extracted from text.

Parameters:
text - text to extract point from
separator - point values separator
Returns:
extracted point

removeControlSymbols

public static java.lang.String removeControlSymbols(java.lang.String text)
Returns text with all control symbols removed. This method works faster than simple replaceAll("\\p{Cntrl}", "").

Parameters:
text - text to modify
Returns:
text without conytol symbols

shortenText

public static java.lang.String shortenText(java.lang.String text,
                                           int maxLength,
                                           boolean addDots)
Returns shortened text.

Parameters:
text - text to shorten
maxLength - maximum shortened text lenght
addDots - add dots at the end of the text when shortened
Returns:
shortened text

shortenTextEnd

public static java.lang.String shortenTextEnd(java.lang.String text,
                                              int maxLength,
                                              boolean addDots)
Returns shortened text.

Parameters:
text - text to shorten
maxLength - maximum shortened text lenght
addDots - add dots at the end of the text when shortened
Returns:
shortened text

stringToList

public static java.util.List<java.lang.String> stringToList(java.lang.String string,
                                                            java.lang.String separator)
Returns a list of text parts splitted using specified separator.

Parameters:
string - text to split
separator - text parts separator
Returns:
list of splitted parts

stringToIntList

public static java.util.List<java.lang.Integer> stringToIntList(java.lang.String string,
                                                                java.lang.String separator)
Returns a list of integer parts splitted using specified separator.

Parameters:
string - text to split
separator - text parts separator
Returns:
list of splitted parts

listToString

public static java.lang.String listToString(java.util.List list,
                                            java.lang.String separator)
Returns single text combined using list of strings and specified separator.

Parameters:
list - list to combine into single text
separator - text parts separator
Returns:
single text

listToString

public static <T> java.lang.String listToString(java.util.List<T> list,
                                                java.lang.String separator,
                                                TextProvider<T> textProvider)
Returns single text combined using list of strings and specified separator.

Parameters:
list - list to combine into single text
separator - text parts separator
textProvider - text provider
Returns:
single text

enumListToString

public static <E extends java.lang.Enum<E>> java.lang.String enumListToString(java.util.List<E> enumList)
Converts list of enumeration constants into string with list of enumeration constants and returns it.

Type Parameters:
E - enumeration type
Parameters:
enumList - enumeration constants list
Returns:
string with list of enumeration constants

enumStringToList

public static <E extends java.lang.Enum<E>> java.util.List<E> enumStringToList(java.lang.String enumString,
                                                                               java.lang.Class<E> enumClass)
Converts string with list of enumeration constants into real list of enumeration constants and returns it.

Type Parameters:
E - enumeration type
Parameters:
enumString - enumeration constants string list
enumClass - enumeration class
Returns:
list of enumeration constants

createString

public static java.lang.String createString(java.lang.String character,
                                            int length)
Creates new string filled with specified amount of same characters.

Parameters:
character - character to fill string with
length - string length
Returns:
new string filled with specified amount of same characters

generateId

public static java.lang.String generateId()
Returns random ID with default prefix and suffix.

Returns:
ID

generateId

public static java.lang.String generateId(java.lang.String prefix)
Returns random ID with specified prefix and default suffix.

Parameters:
prefix - id prefix
Returns:
ID

generateId

public static java.lang.String generateId(java.lang.String prefix,
                                          java.lang.String suffix)
Returns random ID with specified prefix and suffix.

Parameters:
prefix - id prefix
suffix - id suffix
Returns:
ID