|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectinfo.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 String |
appendSpaces(String s,
int count)
Appends the given amount of spaces to the String. |
static void |
arraysToString(List objects)
Little String output - helper that modifies the given LinkedList by getting it's Objects and replace them by their toString() - representation. |
static String |
arrayToString(Object isArr)
If the given Object is no Array, it's toString - method is invoked. |
static String |
getNewLine()
Returns the system - dependant line separator. |
static StringUtil |
instance()
Returns the singleton instance of this class. |
static boolean |
isEmpty(String test)
Returns true if the argument is null or consists of whitespaces only. |
static int |
longestStringRepresentation(List objects)
Returns the maximum length of a Object.toString() result in characters within the given
List. |
static String |
setSize(String s,
int length)
Appends the necessary amount of spaces to the string until it has the givn length. |
static void |
toLongestString(List objects)
Modifies the given LinkedList by getting it's Objects and replace them by their toString() - representation concatenated with the necessary amount of whitespaces 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 String appendSpaces(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 arraysToString(List objects)
What is special?
If an Object in the given List is an Array (of Objects or primitive datatypes) 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 String arrayToString(Object isArr)
// Primitive arrays:
"["+isArr[0]+","+isArr[1]+.. ..+isArr[isArr.length-1]+"]"
//Object arrays :
"["+isArr[0].toString()+","+.. ..+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()
isArr
- The Array to represent as String.
public static 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(String test)
test
- the String
to test.
public static final int longestStringRepresentation(List 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 lenght of a
Object.toString()
result.
public static final String setSize(String s, int length)
s
- the String to expand.length
- the desired length of the String to be returned.
public static final void toLongestString(List 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 All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |