Class AppendUtils
To use, let bean implement AppendMembers, and use
public void appendMembers(StringBuilder buf) { }
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringBuilder
appendAnonField
(StringBuilder buf, Object bean) Appends an anonymous field to a StringBuilder, i.e.static StringBuilder
appendBean
(StringBuilder buf, Object bean) Appends an object to a StringBuilder.static StringBuilder
appendCollection
(StringBuilder buf, String name, Collection<?> col) Appends a collection field to a StringBuilder.static StringBuilder
appendCollection
(StringBuilder buf, String name, Collection<?> col, int maxSize) Appends a collection field to a StringBuilder.static StringBuilder
appendField
(StringBuilder buf, String name, Object bean) Appends a named field to a StringBuilder.static StringBuilder
appendIdField
(StringBuilder buf, Object bean) Appends an 'id' field to a StringBuilder.static StringBuilder
appendUnlessEmpty
(StringBuilder buf, Object bean) Appends an object to a StringBuilder, unless the StringBuilder is empty.static String
Creates a String from an object by callingappendBean(java.lang.StringBuilder, java.lang.Object)
.
-
Constructor Details
-
AppendUtils
public AppendUtils()
-
-
Method Details
-
toString
Creates a String from an object by callingappendBean(java.lang.StringBuilder, java.lang.Object)
.- Parameters:
bean
- bean to write tostring for- Returns:
- a tostring representation of the given bean
-
appendBean
Appends an object to a StringBuilder.Uses
AppendMembers.appendMembers(java.lang.StringBuilder)
if implemented, otherwise just callsStringBuilder.append(Object)
- Parameters:
buf
- string bufferbean
- bean to append- Returns:
- The StringBuilder
-
appendIdField
Appends an 'id' field to a StringBuilder.The format used is the id value followed by a colon (:).
Useful as part of the implementation of
AppendMembers.appendMembers(java.lang.StringBuilder)
.- Parameters:
buf
- string bufferbean
- bean to add as ID- Returns:
- The StringBuilder
-
appendAnonField
Appends an anonymous field to a StringBuilder, i.e. a field with no name.Useful as part of the implementation of
AppendMembers.appendMembers(java.lang.StringBuilder)
.- Parameters:
buf
- string bufferbean
- bean to add as anonymous field- Returns:
- The StringBuilder
-
appendField
Appends a named field to a StringBuilder.The format used is the name followed by an equals sign (=) followed by the value.
Useful as part of the implementation of
AppendMembers.appendMembers(java.lang.StringBuilder)
.- Parameters:
buf
- string buffername
- name of fieldbean
- value of field- Returns:
- The StringBuilder
-
appendCollection
Appends a collection field to a StringBuilder.Only append when collection is not empty.
Useful as part of the implementation of
AppendMembers.appendMembers(java.lang.StringBuilder)
.- Parameters:
buf
- string buffername
- name of fieldcol
- collection to be appended- Returns:
- The StringBuilder
-
appendCollection
public static StringBuilder appendCollection(StringBuilder buf, String name, Collection<?> col, int maxSize) Appends a collection field to a StringBuilder.If the size of the collection is greater than maxSize only the size will be appended.
Only append when collection is not empty.
Useful as part of the implementation of
AppendMembers.appendMembers(java.lang.StringBuilder)
.- Parameters:
buf
- string buffername
- name of fieldcol
- collection to be appendedmaxSize
- maximum elements to be appended- Returns:
- The StringBuilder
-
appendUnlessEmpty
Appends an object to a StringBuilder, unless the StringBuilder is empty.- Parameters:
buf
- string bufferbean
- bean to add unless empty- Returns:
- The StringBuilder
-