net.sourceforge.argval.utils
Class StringUtil

java.lang.Object
  extended by net.sourceforge.argval.utils.StringUtil

public final class StringUtil
extends Object

Utility class for String related functions.


Field Summary
static String LINE_SEPARATOR
           
 
Method Summary
static int charCount(String text, char ch)
           
static List<String> convertToList(String text)
           
static List<String> convertToList(String text, String separator)
           
static Set<String> convertToSet(String text)
           
static Set<String> convertToSet(String text, String separator)
          Converts the text into separated String instance, based on the separator.
static List<Integer> getCharIndexList(String text, char ch)
           
static String getClassName(Class<?> clazz)
          Returns the class name, without the package prefix.
static String getPackageName(Class<?> clazz)
          Returns the package name, without the class name.
static String polish(String text)
          Trims spaces on the outside of the text and in the case of an empty string null is returned.
static String polish(String text, String defaultText)
          Returns the polished text, see polish(String), or when that leads to null the default text.
static String remove(String text, String toRemove)
          Cleans up the text, by removing the toRemove instance(s).
static String removeCharacter(String text, char character)
          Removes the character instances from the given text.
static String removeCharacter(String text, char[] characterArray)
          Removes all the given characters from the given text.
static List<String> toHexList(byte[] byteArray)
           
static List<String> toHexList(String hexStr)
           
static String toHexString(byte[] byteArray)
          Converts a byte array into a hex string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LINE_SEPARATOR

public static final String LINE_SEPARATOR
Method Detail

polish

public static String polish(String text)
Trims spaces on the outside of the text and in the case of an empty string null is returned.

Parameters:
text - The text to polish.
Returns:
The text without leading and trailing spaces that remain or null, when no characters are left.

polish

public static String polish(String text,
                            String defaultText)
Returns the polished text, see polish(String), or when that leads to null the default text.

Parameters:
text - The text to polish.
defaultText - The default text to return, if the polished text, result in to null.
Returns:
The polished text, or when that's equal to null, the default text.

convertToSet

public static Set<String> convertToSet(String text,
                                       String separator)
Converts the text into separated String instance, based on the separator.

Example: convertToSet("Winnie The Pooh;Piglet;Tigger;Rabbit", ";") will return a Set instance containing the Strings:

Parameters:
text - The text to separate.
separator - The separator String instance.
Returns:
The Set containing the separated Strings.

convertToSet

public static Set<String> convertToSet(String text)

convertToList

public static List<String> convertToList(String text,
                                         String separator)

convertToList

public static List<String> convertToList(String text)

removeCharacter

public static String removeCharacter(String text,
                                     char character)
Removes the character instances from the given text.

Example: removeCharacter("ISBN: 0-596-10094-9", '-') will return "ISBN: 0596100949"

Parameters:
text - The text to filter.
character - The character to remove.
Returns:
Returns the text, with out all the instance of the given charater.

removeCharacter

public static String removeCharacter(String text,
                                     char[] characterArray)
Removes all the given characters from the given text.

Exmaple: removeCharacter("ISBN: 0-596-10094-9", new char[] { '-', ':' } ) will return "ISBN 0596100949"

Parameters:
text - The text to filter.
character - The character to remove.
Returns:
The clean text, which doesn;t contain any of the given characters any more.

remove

public static String remove(String text,
                            String toRemove)
Cleans up the text, by removing the toRemove instance(s).

This can be used to remove unwanted Strings from a text.

   // Remove "ISBN:" from the text
   StringUtil.remove("ISBN: 0-596-10094-9", "ISBN:");
 
This will return the text " 0-596-10094-9".

Parameters:
text - The text, which needs to be clean up.
toRemove - The character sequence which needs to be removed, from the given text.
Returns:
A new text, without the 'toRemove' string instances.

getClassName

public static String getClassName(Class<?> clazz)
Returns the class name, without the package prefix.

Parameters:
clazz - The class, from which to get it's name.
Returns:
The class name.

getPackageName

public static String getPackageName(Class<?> clazz)
Returns the package name, without the class name.

Parameters:
clazz - The class, from which to get it's package name.
Returns:
The package name.

charCount

public static int charCount(String text,
                            char ch)

getCharIndexList

public static List<Integer> getCharIndexList(String text,
                                             char ch)

toHexString

public static String toHexString(byte[] byteArray)
Converts a byte array into a hex string.

Parameters:
byteArray - The bytes.
Returns:
The hex representation of the bytes.

toHexList

public static List<String> toHexList(byte[] byteArray)

toHexList

public static List<String> toHexList(String hexStr)


Copyright © 2013 Verhagen Software. All Rights Reserved.