org.omnaest.utils.strings
Class StringUtils

java.lang.Object
  extended by org.omnaest.utils.strings.StringUtils

public class StringUtils
extends Object

Utility class for supporting the work with Strings

Author:
Omnaest

Field Summary
static String DEFAULT_LINESEPARATOR
           
 
Constructor Summary
StringUtils()
           
 
Method Summary
static int count(String text, String regExSubstring)
          Counts the number of matching substrings within the given text.
static boolean endsWithStartOfOther(String text, String textOther)
          Returns true if the given text ends with the start of the other given text.
static
<E> String[]
formatPerArrayElement(Locale locale, String format, E... elements)
          Similar to formatPerArrayElement(String, Object...) using String.format(Locale, String, Object...) instead.
static
<E> String[]
formatPerArrayElement(String format, E... elements)
          Formats an given array into a String array using String.format(String, Object...)
static String insertString(String baseString, String insertString, int insertPosition, boolean overwrite)
           
static int maximumWidth(Iterable<String> iterable)
          Determines the maximum width of the given Iterable String elements
static String percentageBar(double value, int width)
          Returns a percentage bar looking like:
[====o ]
static String repeat(CharSequence token, int repeats)
          Repeats the given CharSequence
static String setFixedWitdth(String value, int width)
           
static String[] split(String text, char delimiter, char quote)
          Simple form of the StrTokenizer
static String[] splitByInterval(String text, int interval)
          Splits a given String text by an interval.
static String stringJoin(String[] strings, String delimiter)
           
static Iterable<String> tokenizerPatternBased(CharSequence charSequence, String regexDelimiter)
          Returns a new Iterable instance for the given CharSequence which uses the given regular expression delimiter to produce tokens.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_LINESEPARATOR

public static final String DEFAULT_LINESEPARATOR
Constructor Detail

StringUtils

public StringUtils()
Method Detail

endsWithStartOfOther

public static boolean endsWithStartOfOther(String text,
                                           String textOther)
Returns true if the given text ends with the start of the other given text. E.g. "bcd" will start with the and of "abc"

Parameters:
text -
textOther -
Returns:

stringJoin

public static String stringJoin(String[] strings,
                                String delimiter)
Parameters:
strings -
delimiter -
Returns:

insertString

public static String insertString(String baseString,
                                  String insertString,
                                  int insertPosition,
                                  boolean overwrite)

setFixedWitdth

public static String setFixedWitdth(String value,
                                    int width)
Parameters:
value -
width -
Returns:

maximumWidth

public static int maximumWidth(Iterable<String> iterable)
Determines the maximum width of the given Iterable String elements

Parameters:
iterable -
Returns:

repeat

public static String repeat(CharSequence token,
                            int repeats)
Repeats the given CharSequence

Parameters:
token -
repeats -
Returns:

percentageBar

public static String percentageBar(double value,
                                   int width)
Returns a percentage bar looking like:
[====o ]

Parameters:
value -
width -
Returns:

splitByInterval

public static String[] splitByInterval(String text,
                                       int interval)
Splits a given String text by an interval.

E.g. "This is a text" is split into "Thi","s i","s a", " te", "xt"

A given interval will be reduced to 1 if it is lower than that and reduced to the length of the text if it is larger than that.

Parameters:
text -
interval -
Returns:

split

public static String[] split(String text,
                             char delimiter,
                             char quote)
Simple form of the StrTokenizer

Parameters:
text -
delimiter -
quote -
Returns:

count

public static int count(String text,
                        String regExSubstring)
Counts the number of matching substrings within the given text. As substring a regular expression is expected, please use Pattern.quote(String) if a substring contains special characters.

 count("ab ab","ab") = 2
 count("abab","ab") = 2
 count("ababab","abab") = 1
 count("ababab ababab","abab") = 2
 count("aba bab","abab") = 0
 

Parameters:
text -
regExSubstring -
Returns:

tokenizerPatternBased

public static Iterable<String> tokenizerPatternBased(CharSequence charSequence,
                                                     String regexDelimiter)
Returns a new Iterable instance for the given CharSequence which uses the given regular expression delimiter to produce tokens.

If the given CharSequence or the given delimiter is null this returns null.

Example:
 StringUtils.tokenizerPatternBased( "a;b", ";" )  => "a","b"
 StringUtils.tokenizerPatternBased( null, ";" )   => null
 StringUtils.tokenizerPatternBased( "a;b", null ) => null
 

Parameters:
charSequence -
regexDelimiter -
Returns:

formatPerArrayElement

public static <E> String[] formatPerArrayElement(String format,
                                                 E... elements)
Formats an given array into a String array using String.format(String, Object...)

Parameters:
format -
elements - has to be a non primitive array
Returns:

formatPerArrayElement

public static <E> String[] formatPerArrayElement(Locale locale,
                                                 String format,
                                                 E... elements)
Similar to formatPerArrayElement(String, Object...) using String.format(Locale, String, Object...) instead.

Parameters:
locale - Locale
format -
elements -
Returns:


Copyright © 2013. All Rights Reserved.