public class CollectionFormatter extends Object
Constructor and Description |
---|
CollectionFormatter() |
Modifier and Type | Method and Description |
---|---|
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", " | ");
|
public static String format(Collection<?> collection, String property, String separator, boolean trim)
CollectionFormatter.format(myCollection, null, ",");
CollectionFormatter.format(myCollection, "personInCharge.name.firstName", ", ");
CollectionFormatter.format(myCollection, "relatedPeople(InCharge).name", ", ");
CollectionFormatter.format(myCollection, "subordinate[3].address(home).city", " | ");
collection
- The collection that will be formattedproperty
- 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.public static String format(Collection<?> collection, String property, String separator)
collection
- The collection that will be formattedproperty
- 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.public static String format(Collection<?> collection)
collection
- The collection that will be formattedpublic static String format(Collection<?> collection, boolean trim)
collection
- The collection that will be formattedtrim
- true if the elements' toString() need to be trimmed, false if not.public static String format(Collection<?> collection, String property)
collection
- The collection that will be formattedproperty
- The property of the collection's element that will be put into the result string.
Please see PropertyUtils.getProperty() of commons-beanutils for detail.public static String format(Collection<?> collection, String property, boolean trim)
collection
- The collection that will be formattedproperty
- 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.Copyright © 2014. All Rights Reserved.