|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object info.monitorenter.util.StringUtil
public final class StringUtil
Nice static helpers for working with Strings.
Maybe not always the fastest solution to call in here, but working. Also usable for seeing examples and cutting code for manual inlining.
Method Summary | |
---|---|
static java.lang.String |
appendSpaces(java.lang.String s,
int count)
Appends the given amount of spaces to the String. |
static java.lang.String |
arrayToString(java.lang.Object isArr)
If the given Object is no Array, it's toString - method is invoked. |
static java.lang.String |
arrayToString(java.lang.Object isArr,
java.lang.String separator)
If the given Object is no Array, it's toString - method is invoked. |
static java.lang.String |
getNewLine()
Returns the system - dependent line separator. |
static StringUtil |
instance()
Returns the singleton instance of this class. |
static boolean |
isEmpty(java.lang.String test)
Returns true if the argument is null or consists of whitespaces only. |
static void |
listOfArraysToString(java.util.List<java.lang.Object> objects)
Little String output - helper that modifies the given LinkedList by getting it's Objects and replace them by their toString() - representation. |
static int |
longestStringRepresentation(java.util.List<java.lang.Object> objects)
Returns the maximum length of a Object.toString() result in
characters within the given List. |
static java.lang.String |
setSize(java.lang.String s,
int length)
Appends the necessary amount of spaces to the string until it has the givn length. |
static void |
toLongestString(java.util.List<java.lang.Object> objects)
Modifies the given LinkedList by getting it's Objects and replace them by their toString() - representation concatenated with the necessary amount of white spaces that every String in the List will have the same amount of characters. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static final java.lang.String appendSpaces(java.lang.String s, int count)
Not intended for big append -operations because in a loop alway just one space is added.
s
- the base String to append spaces to.count
- the amount of spaces to append.
public static final void listOfArraysToString(java.util.List<java.lang.Object> objects)
What is special?
If an Object in the given List is an Array (of Objects or primitive data
types) reflection will be used to create a String - representation of them.
The changes are reflected in the Objects that are in the given List. So
keep a reference to it. If you are sure, that your List does not contain
Arrays do not use this method to avoid overhead.
Avoid structural modifications (remove) of the list while using this method. This method or better: the given List is only thread - safe if the list is synchronized.
A clever VM (hotspot) will be able to inline this function because of void return.
objects
- the List of objects that will be changed to a list of the String
representation of the Objects with respect to special array
treatment.public static final java.lang.String arrayToString(java.lang.Object isArr)
isArr
- The Array to represent as String.
arrayToString(Object, String)
public static final java.lang.String arrayToString(java.lang.Object isArr, java.lang.String separator)
// Primitive arrays:
"["+isArr[0]+"<separator>"+isArr[1]+.. ..+isArr[isArr.length-1]+"]"
//Object arrays :
"["+isArr[0].toString()+"<separator>"+.. ..+isArr[isArr.length-1].toString+"]"
// Two or three - dimensional Arrays are not supported
//(should be reflected in a special output method, e.g.as a field)
// other Objects:
toString()
separator
- put in-between each array element in the resulting string.isArr
- The Array to represent as String.
public static java.lang.String getNewLine()
Only call this method once (not in a loop) and keep the result.
public static StringUtil instance()
This method is useless for now as all methods are static. It may be used in future if VM-global configuration will be put to the state of the instance.
#
public static boolean isEmpty(java.lang.String test)
test
- the String
to test.
public static final int longestStringRepresentation(java.util.List<java.lang.Object> objects)
Object.toString()
result in
characters within the given List.
No data is changed in the given List at all. But the String -
representation of all Objects, even Arrays is build to inspect.
Convention for creation fo String - representation:
Primitive Arrays : as performed by this classes @see #ArrayToString. Object Arrays : as performed by this classes @see #ArrayToString other Objects : toString() (as performed by this classes @see #ArrayToString).
objects
- the List<Object>
to inspect for the maximum
length of a Object.toString()
result.
public static final java.lang.String setSize(java.lang.String s, int length)
s
- the String to expand.length
- the desired length of the String to be returned.
public static final void toLongestString(java.util.List<java.lang.Object> objects)
Only use this method in following case:
What happens?
objects
- contains the Objects to replace by their toString()
representation.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |