|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectclassUtils.pack.util.ObjectLister
public class ObjectLister
A class to list the elements of an array or a collection/enumeration into a string, each element divided by a separtor, by invoking either the toString() method or a given method with no parameters (and returning a String).
The default list(array)
method
uses toString to describe each object; the list(array, method name)
method attempts to locate a method with signature
public String <method name>()in each object in the array, and invokes it to describe each object.
For example, for the array String [] array { "Hello", "World" }
invoking new ObjectLister().list(array);
will produce
"Hello, World"
.
For the array Thread [] array = { new Thread("Thread 1"),
new Thread("Thread 2") }
, invoking
new ObjectLister().list(array, "getName");
will produce
"Thread 1, Thread 2"
.
Field Summary | |
---|---|
static java.lang.String |
DEFAULT_SEPARATOR
The default separator sequence ", " |
Constructor Summary | |
---|---|
ObjectLister()
Constructor for ObjectLister, which uses the default sequence DEFAULT_SEPARATOR as
separator. |
|
ObjectLister(boolean useToStringIfNotFound)
Constructor for ObjectLister, which uses the default sequence DEFAULT_SEPARATOR as
separator. |
|
ObjectLister(java.lang.String separator)
Constructor for ObjectLister. |
|
ObjectLister(java.lang.String separator,
boolean useToStringIfNotFound)
Constructor for ObjectLister. |
Method Summary | |
---|---|
static ObjectLister |
getInstance()
Returns the default instance, which uses DEFAULT_SEPARATOR . |
boolean |
isUseToStringIfNotFound()
Returns the useToStringIfNotFound. |
java.lang.String |
list(java.util.Collection coll)
Invoke list() using
the toString() method. |
java.lang.String |
list(java.util.Collection coll,
java.lang.String methodToUse)
Return a String containing a list of objects in the collection, obtained invoking the given method name on each element in the collection. |
java.lang.String |
list(java.util.Enumeration e)
Invoke list() using
the toString() method. |
java.lang.String |
list(java.util.Enumeration e,
java.lang.String methodToUse)
Return a String containing a list of objects in the enumeration, obtained invoking the given method name on each element in the enumeration. |
java.lang.String |
list(java.util.Map map)
Invoke list() using
the toString() method. |
java.lang.String |
list(java.util.Map map,
java.lang.String methodToUse)
Return a String containing a list of values in the map, obtained invoking the given method name on each element in the map. |
java.lang.String |
list(java.lang.Object[] array)
Invoke list() using
the toString() method. |
java.lang.String |
list(java.lang.Object[] array,
java.lang.String methodToUse)
Return a String containing a list of objects in the array, obtained invoking the given method name on each element in the array. |
static void |
main(java.lang.String[] args)
A test method |
void |
setUseToStringIfNotFound(boolean useToStringIfNotFound)
Sets the useToStringIfNotFound. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String DEFAULT_SEPARATOR
Constructor Detail |
---|
public ObjectLister(java.lang.String separator, boolean useToStringIfNotFound)
separator
- the separator to useuseToStringIfNotFound
- if true, when list(array, method name)
is invoked, toString() will be used if the given method
is not found in an object in the array to list. If false an exception will be raised.public ObjectLister(boolean useToStringIfNotFound)
DEFAULT_SEPARATOR
as
separator.
useToStringIfNotFound
- if true, when list(array, method name)
is invoked, toString() will be used if the given method
is not found in an object in the array to list. If false an exception will be raised.public ObjectLister(java.lang.String separator)
list(array, method name)
is invoked, toString() will be used if the given method
is not found in an object in the array to list.
separator
- the separator to usepublic ObjectLister()
DEFAULT_SEPARATOR
as
separator. When list(array, method name)
is invoked, toString() will be used if the given method
is not found in an object in the array to list.
Method Detail |
---|
public java.lang.String list(java.lang.Object[] array, java.lang.String methodToUse)
The method must return a String and have no parameters.
array
- the array to listmethodToUse
- the name of the method to use
java.lang.RuntimeException
- if a method with the given name,
which returns a String and has no parameter is not available in the objects
of the array.public java.lang.String list(java.lang.Object[] array)
list()
using
the toString() method.
array
- to be listed
public java.lang.String list(java.util.Collection coll, java.lang.String methodToUse)
The method must return a String and have no parameters.
coll
- the collection to listmethodToUse
- the name of the method to use
java.lang.RuntimeException
- if a method with the given name,
which returns a String and has no parameter is not available in the objects
of the collection.public java.lang.String list(java.util.Collection coll)
list()
using
the toString() method.
coll
- to be listed
public java.lang.String list(java.util.Enumeration e, java.lang.String methodToUse)
The method must return a String and have no parameters.
e
- the enumeration to listmethodToUse
- the name of the method to use
java.lang.RuntimeException
- if a method with the given name,
which returns a String and has no parameter is not available in the objects
of the enumeration.public java.lang.String list(java.util.Enumeration e)
list()
using
the toString() method.
e
- the enumeration to be listed
public java.lang.String list(java.util.Map map, java.lang.String methodToUse)
The method must return a String and have no parameters.
map
- the map to listmethodToUse
- the name of the method to use
java.lang.RuntimeException
- if a method with the given name,
which returns a String and has no parameter is not available in the objects
of the map.public java.lang.String list(java.util.Map map)
list()
using
the toString() method.
map
- to be listed
public boolean isUseToStringIfNotFound()
public void setUseToStringIfNotFound(boolean useToStringIfNotFound)
useToStringIfNotFound
- The useToStringIfNotFound to setpublic static void main(java.lang.String[] args)
public static ObjectLister getInstance()
DEFAULT_SEPARATOR
.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |