Class ToStringUtils

java.lang.Object
dev.daymor.sakuraboot.util.ToStringUtils

public class ToStringUtils extends Object
Util class for toString methods.
Since:
0.1.0
  • Constructor Details

    • ToStringUtils

      public ToStringUtils()
  • Method Details

    • toString

      public String toString(String className, Collection<org.apache.commons.lang3.tuple.Pair<String,Object>> fields)
      This method help print nice toString for an object and remove the null fields. If a field is a container and is bigger than three elements, it will print an ellipse.
      Parameters:
      className - The name of the class to print.
      fields - The fields of the class to print.
      Returns:
      A pretty print toString.
    • toString

      public String toString(String className, Collection<org.apache.commons.lang3.tuple.Pair<String,Object>> fields, int maxContainerSize)
      This method help print nice toString for an object and remove the null fields.
      Parameters:
      className - The name of the class to print.
      fields - The fields of the object to print.
      maxContainerSize - The maximum number of elements to print for a container. (-1 for printing all the elements)
      Returns:
      A pretty print toString.
    • toStringPrintNullFields

      public String toStringPrintNullFields(String className, Collection<org.apache.commons.lang3.tuple.Pair<String,Object>> fields)
      This method help print nice toString for an object and keep the null fields. If a field is a container and is bigger than three elements, it will print an ellipse.
      Parameters:
      className - The name of the class to print.
      fields - The fields of the class to print.
      Returns:
      A pretty print toString.
    • toStringPrintNullFields

      public String toStringPrintNullFields(String className, Collection<org.apache.commons.lang3.tuple.Pair<String,Object>> fields, int maxContainerSize)
      This method help print nice toString for an object and keep the null fields.
      Parameters:
      className - The name of the class to print.
      fields - The fields of the object to print.
      maxContainerSize - The maximum number of elements to print for a container. (-1 for printing all the elements)
      Returns:
      A pretty print toString.
    • objectToString

      public String objectToString(@Nullable Object object)
      Method to print the toString of an object, including container. If a field is a container and is bigger than three elements, it will print an ellipse.
      Parameters:
      object - The object to be convert toString.
      Returns:
      The toString of the given object.
    • objectToString

      public String objectToString(@Nullable Object object, int maxContainerSize)
      Method to print the toString of an object, including container. If a field is a container and is bigger than three elements, it will print an ellipse.
      Parameters:
      object - The object to be convert toString.
      maxContainerSize - The maximum number of elements to print for a container. (-1 for printing all the elements)
      Returns:
      The toString of the given object.
    • getListFieldsForToString

      public List<org.apache.commons.lang3.tuple.Pair<String,Object>> getListFieldsForToString(Object object, List<org.apache.commons.lang3.tuple.Pair<String,Object>> list, Collection<String> excludedFields)
      Helper method to get the list of fields for toString. Only get the fields present in the class and not in the superclass.
      Parameters:
      object - The object to get the list of fields.
      list - The list of fields to print.
      excludedFields - The list of fields to exclude
      Returns:
      The list of fields for toString.