net.sf.jabb.util.text
Class CollectionFormatter

java.lang.Object
  extended by net.sf.jabb.util.text.CollectionFormatter

public class CollectionFormatter
extends Object

Handles the formatting of collections.

Author:
James Hu

Constructor Summary
CollectionFormatter()
           
 
Method Summary
static String format(Collection<?> collection)
          Format a collection's elements to ',' separated string with trimming on the elements' toString().
static String format(Collection<?> collection, boolean trim)
          Format a collection's elements to ',' separated string.
static String format(Collection<?> collection, String property)
          Format a collection's elements' properties to ',' separated string, with trimming on the elements' properties
static String format(Collection<?> collection, String property, boolean trim)
          Format a collection's elements' properties to ',' separated string, with trimming on the elements' properties
static String format(Collection<?> collection, String property, String separator)
          Format a collection's elements' properties to delimiter separated string, with trimming on the elements' properties
static String format(Collection<?> collection, String property, String separator, boolean trim)
          Format a collection's elements' properties to delimiter separated string.
Usage examples:
CollectionFormatter.format(myCollection, null, ","); CollectionFormatter.format(myCollection, "personInCharge.name.firstName", ", "); CollectionFormatter.format(myCollection, "relatedPeople(InCharge).name", ", "); CollectionFormatter.format(myCollection, "subordinate[3].address(home).city", " | ");
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CollectionFormatter

public CollectionFormatter()
Method Detail

format

public static String format(Collection<?> collection,
                            String property,
                            String separator,
                            boolean trim)
Format a collection's elements' properties to delimiter separated string.
Usage examples:
CollectionFormatter.format(myCollection, null, ","); CollectionFormatter.format(myCollection, "personInCharge.name.firstName", ", "); CollectionFormatter.format(myCollection, "relatedPeople(InCharge).name", ", "); CollectionFormatter.format(myCollection, "subordinate[3].address(home).city", " | ");

Parameters:
collection - The collection that will be formatted
property - The property of the collection's element that will be put into the result string. Please see PropertyUtils.getProperty() of commons-beanutils for detail. Use null if the element itself needs to be put into the result string.
separator - Used in the result string to separate each element.
trim - true if the property need to be trimmed, false if not.
Returns:
A string containing separated properties of the collection's elements

format

public static String format(Collection<?> collection,
                            String property,
                            String separator)
Format a collection's elements' properties to delimiter separated string, with trimming on the elements' properties

Parameters:
collection - The collection that will be formatted
property - The property of the collection's element that will be put into the result string. Please see PropertyUtils.getProperty() of commons-beanutils for detail.
separator - Used in the result string to separate each element.
Returns:
A string containing separated properties of the collection's elements

format

public static String format(Collection<?> collection)
Format a collection's elements to ',' separated string with trimming on the elements' toString().

Parameters:
collection - The collection that will be formatted
Returns:
A string containing separated properties of the collection's elements

format

public static String format(Collection<?> collection,
                            boolean trim)
Format a collection's elements to ',' separated string.

Parameters:
collection - The collection that will be formatted
trim - true if the elements' toString() need to be trimmed, false if not.
Returns:
A string containing separated properties of the collection's elements

format

public static String format(Collection<?> collection,
                            String property)
Format a collection's elements' properties to ',' separated string, with trimming on the elements' properties

Parameters:
collection - The collection that will be formatted
property - The property of the collection's element that will be put into the result string. Please see PropertyUtils.getProperty() of commons-beanutils for detail.
Returns:
A string containing separated properties of the collection's elements

format

public static String format(Collection<?> collection,
                            String property,
                            boolean trim)
Format a collection's elements' properties to ',' separated string, with trimming on the elements' properties

Parameters:
collection - The collection that will be formatted
property - The property of the collection's element that will be put into the result string. Please see PropertyUtils.getProperty() of commons-beanutils for detail.
trim - true if the elements' toString() need to be trimmed, false if not.
Returns:
A string containing separated properties of the collection's elements


Copyright © 2012. All Rights Reserved.