net.aavalla.utils.general
Class StrUtils

java.lang.Object
  extended by net.aavalla.utils.general.StrUtils

public class StrUtils
extends java.lang.Object

Utilities for manipulating String objects.

Author:
Lari Natri

Constructor Summary
StrUtils()
           
 
Method Summary
static java.lang.String asString(double d)
           
static java.lang.String asString(double d, int minDecimals, int maxDecimals)
           
static java.lang.String catStrings(java.lang.Object[] strings, java.lang.String separator)
          Concatenates strings, puts separator between them and returns the result.
static java.lang.String catStringTimes(java.lang.String string, java.lang.String separator, int c)
          Returns a string concatenated with itself a number of times with a separator string added in between.
static boolean containsPattern(java.lang.String test, java.util.regex.Pattern pattern)
          Checks whether any substring in a string matches given pattern
static java.lang.String escapeUnwanted(java.lang.String source, java.util.regex.Pattern unwanted, java.lang.String escapePre, java.lang.String escapePost)
          Escapes any substrings matching given pattern
static java.lang.String removeUnwanted(java.lang.String source, java.util.regex.Pattern unwanted)
          Removes any substrings matching given pattern
static java.lang.String[] slice(java.lang.String sourceString, int sliceLength)
          Slices a string to substrings of given length and return them as an array of strings.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StrUtils

public StrUtils()
Method Detail

containsPattern

public static boolean containsPattern(java.lang.String test,
                                      java.util.regex.Pattern pattern)
Checks whether any substring in a string matches given pattern

Parameters:
test - string to test matching for
pattern - the pattern
Returns:
true, if matches are found, false otherwise

removeUnwanted

public static java.lang.String removeUnwanted(java.lang.String source,
                                              java.util.regex.Pattern unwanted)
Removes any substrings matching given pattern

Parameters:
source - source string to remove matches from
unwanted - pattern of unwanted substrings
Returns:
string with unwanted substrings removed

escapeUnwanted

public static java.lang.String escapeUnwanted(java.lang.String source,
                                              java.util.regex.Pattern unwanted,
                                              java.lang.String escapePre,
                                              java.lang.String escapePost)
Escapes any substrings matching given pattern

Parameters:
source - source string to escape
unwanted - unwanted pattern
escapePre - string to add before any unwanted pattern
escapePost - string to add after any unwanted pattern
Returns:
escaped string

catStrings

public static java.lang.String catStrings(java.lang.Object[] strings,
                                          java.lang.String separator)
Concatenates strings, puts separator between them and returns the result. Null Strings are ignored, but empty ones are "catenated" with separator between them.

Parameters:
strings - Array of Strings to catenate
separator - Added between concatenated strings
Returns:
Concatenated String

catStringTimes

public static java.lang.String catStringTimes(java.lang.String string,
                                              java.lang.String separator,
                                              int c)
Returns a string concatenated with itself a number of times with a separator string added in between. ' characters are doubled: "'" -> "''".

Parameters:
string - String to concatenate with itself
separator - Added between concatenated strings
c - Number of times
Returns:
Concatenated String

slice

public static java.lang.String[] slice(java.lang.String sourceString,
                                       int sliceLength)
Slices a string to substrings of given length and return them as an array of strings. Last string might be shorter.

Parameters:
sourceString - Original string
sliceLength - length of a slice
Returns:
sliced string

asString

public static java.lang.String asString(double d)

asString

public static java.lang.String asString(double d,
                                        int minDecimals,
                                        int maxDecimals)