|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.sadun.util.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"
.
By default, the method to invoke is made accessible to the client code
regardless of its protection status. Use setSetAccessible()
to disable such behaviour. If disabled, the
failOnUnaccessible
property may be
used to cause the list to raise an excepion when a method is not accessible
(by default, an explicit mention of the fact will appear in the list).
Field Summary | |
static char |
DEFAULT_QUOTE_CHAR
The default quote char, '"e;' |
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(char quoteChar)
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, which does not fail if the method to use is not accessible. |
|
ObjectLister(java.lang.String separator,
boolean useToStringIfNotFound,
boolean failIfUnaccessible)
Constructor for ObjectLister. |
|
ObjectLister(java.lang.String separator,
char quoteChar)
Constructor for ObjectLister. |
|
ObjectLister(java.lang.String separator,
char quoteChar,
boolean useToStringIfNotFound)
Constructor for ObjectLister, which does not fail if the method to use is not accessible. |
|
ObjectLister(java.lang.String separator,
char quoteChar,
boolean useToStringIfNotFound,
boolean failIfUnaccessible)
Constructor for ObjectLister. |
Method Summary | |
static ObjectLister |
getDefaultHTMLInstance()
Return the default instance separating listed elements with a &ĝlt;br> HTML element |
static ObjectLister |
getInstance()
Returns the default instance, which uses DEFAULT_SEPARATOR . |
boolean |
isFailOnUnaccessible()
|
boolean |
isSetAccessible()
|
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 enum)
Invoke list()
using the toString() method. |
java.lang.String |
list(java.util.Enumeration enum,
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.Iterator iterator)
Invoke list()
using the toString() method. |
java.lang.String |
list(java.util.Iterator iterator,
java.lang.String methodToUse)
Return a String containing a list of objects in the iterator, obtained invoking the given method name on each element. |
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 |
println(java.util.Collection coll)
Invoke list() and print the result on
System.out. |
void |
println(java.util.Collection coll,
java.lang.String methodToUse)
Invoke list() and print the result on
System.out. |
void |
println(java.util.Enumeration enum)
Invoke list() and print the result on
System.out. |
void |
println(java.util.Enumeration enum,
java.lang.String methodToUse)
Invoke list() and print the result on
System.out. |
void |
println(java.util.Map map)
Invoke list() and print the result on System.out. |
void |
println(java.util.Map map,
java.lang.String methodToUse)
Invoke list() and print the result on
System.out. |
void |
println(java.lang.Object[] array)
Invoke list() and print the result on
System.out. |
void |
println(java.lang.Object[] array,
java.lang.String methodToUse)
Invoke list() and print the result on
System.out. |
void |
setFailOnUnaccessible(boolean failOnUnaccessible)
|
void |
setSetAccessible(boolean setAccessible)
|
void |
setUseToStringIfNotFound(boolean useToStringIfNotFound)
Sets the useToStringIfNotFound. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final char DEFAULT_QUOTE_CHAR
public static final java.lang.String DEFAULT_SEPARATOR
Constructor Detail |
public ObjectLister(java.lang.String separator, char quoteChar, boolean useToStringIfNotFound, boolean failIfUnaccessible)
separator
- the separator to usequoteChar
- the quotation charachter to use. If 0, no quotes are used.useToStringIfNotFound
- if true, when
{@link #list(java.lang.Object[], java.lang.String)failIfUnaccessible
- if true an exception is thrown if the method to use
for listing is not accessible. 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, boolean useToStringIfNotFound, boolean failIfUnaccessible)
separator
- the separator to useuseToStringIfNotFound
- if true, when
{@link #list(java.lang.Object[], java.lang.String)failIfUnaccessible
- if true an exception is thrown if the method to use
for listing is not accessible. 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, 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(java.lang.String separator, char quoteChar, boolean useToStringIfNotFound)
separator
- the separator to usequoteChar
- the quotation charachter to use. If 0, no quotes are used.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(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(java.lang.String separator, char quoteChar)
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 usequoteChar
- the quotation charachter to use. If 0, no quotes are used.public 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.
public ObjectLister(char quoteChar)
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.
quoteChar
- the quotation charachter to use. If 0, no quotes are used.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.
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.
public java.lang.String list(java.util.Iterator iterator, java.lang.String methodToUse)
The method must return a String and have no parameters.
iterator
- the iterator to be listedmethodToUse
- 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.Iterator iterator)
list()
using the toString() method.
iterator
- the iterator to be listed
public java.lang.String list(java.util.Enumeration enum, java.lang.String methodToUse)
The method must return a String and have no parameters.
enum
- 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 enum)
list()
using the toString() method.
enum
- the enumeration to be listed
public void println(java.lang.Object[] array, java.lang.String methodToUse)
list()
and print the result on
System.out.
array
- see list()
methodToUse
- see list()
public void println(java.lang.Object[] array)
list()
and print the result on
System.out.
array
- see list()
public void println(java.util.Collection coll, java.lang.String methodToUse)
list()
and print the result on
System.out.
coll
- see list()
methodToUse
- see list()
public void println(java.util.Collection coll)
list()
and print the result on
System.out.
coll
- see list()
public void println(java.util.Enumeration enum, java.lang.String methodToUse)
list()
and print the result on
System.out.
enum
- see list()
methodToUse
- see list()
public void println(java.util.Enumeration enum)
list()
and print the result on
System.out.
enum
- see list()
public void println(java.util.Map map, java.lang.String methodToUse)
list()
and print the result on
System.out.
map
- see list()
methodToUse
- see list()
public void println(java.util.Map map)
list()
and print the result on System.out.
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.
public boolean isUseToStringIfNotFound()
public void setUseToStringIfNotFound(boolean useToStringIfNotFound)
useToStringIfNotFound
- The useToStringIfNotFound to setpublic static ObjectLister getInstance()
DEFAULT_SEPARATOR
.
public static void main(java.lang.String[] args) throws java.lang.NoSuchMethodException, java.lang.reflect.InvocationTargetException
java.lang.NoSuchMethodException
java.lang.reflect.InvocationTargetException
public boolean isSetAccessible()
public void setSetAccessible(boolean setAccessible)
setAccessible
- public boolean isFailOnUnaccessible()
public void setFailOnUnaccessible(boolean failOnUnaccessible)
failOnUnaccessible
- public static ObjectLister getDefaultHTMLInstance()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |