Class StandardRepresentation

    • Constructor Detail

      • StandardRepresentation

        public StandardRepresentation()
    • Method Detail

      • resetDefaults

        public static void resetDefaults()
        It resets the static defaults for the standard representation.

        The following defaults will be reapplied:

        • maxLengthForSingleLineDescription = 80
        • maxElementsForPrinting = 1000
      • setMaxLengthForSingleLineDescription

        public static void setMaxLengthForSingleLineDescription​(int value)
      • getMaxLengthForSingleLineDescription

        public static int getMaxLengthForSingleLineDescription()
      • setMaxElementsForPrinting

        public static void setMaxElementsForPrinting​(int value)
      • getMaxElementsForPrinting

        public static int getMaxElementsForPrinting()
      • registerFormatterForType

        public static <T> void registerFormatterForType​(Class<T> type,
                                                        Function<T,​String> formatter)
        Registers new formatter for the given type. All instances of the given type will be formatted with the provided formatter.
        Type Parameters:
        T - the type to register a formatter for
        Parameters:
        type - the class of the type to register a formatter for
        formatter - the formatter
      • toStringOf

        public String toStringOf​(Object object)
        Returns standard the toString representation of the given object. It may or not the object's own implementation of toString.
        Specified by:
        toStringOf in interface Representation
        Parameters:
        object - the given object.
        Returns:
        the toString representation of the given object.
      • customFormat

        protected <T> String customFormat​(T object)
      • hasCustomFormatterFor

        protected boolean hasCustomFormatterFor​(Object object)
      • unambiguousToStringOf

        public String unambiguousToStringOf​(Object obj)
        Description copied from interface: Representation
        Returns the String representation of the given object with its type and hexadecimal identity hash code so that it can be differentiated from other objects with the same Representation.toStringOf(Object) representation.
        Specified by:
        unambiguousToStringOf in interface Representation
        Parameters:
        obj - the object to represent.
        Returns:
        the unambiguous toString representation of the given object.
      • fallbackToStringOf

        protected String fallbackToStringOf​(Object object)
        Returns the String representation of the given object. This method is used as a last resort if none of the StandardRepresentation predefined string representations were not called.
        Parameters:
        object - the object to represent (never null
        Returns:
        to toString representation for the given object
      • toStringOf

        protected String toStringOf​(Number number)
      • toStringOf

        protected String toStringOf​(Class<?> c)
      • toStringOf

        protected String toStringOf​(Date d)
      • toStringOf

        protected String toStringOf​(Float f)
      • toStringOf

        protected String toStringOf​(Long l)
      • toStringOf

        protected String toStringOf​(File file)
      • toStringOf

        protected String toStringOf​(Tuple tuple)
      • toStringOf

        protected String toStringOf​(MapEntry<?,​?> mapEntry)
      • toStringOf

        protected String toStringOf​(Map<?,​?> map)
      • toSortedMapIfPossible

        private static Map<?,​?> toSortedMapIfPossible​(Map<?,​?> map)
      • formatLines

        private String formatLines​(List<?> lines)
      • formatArray

        protected String formatArray​(Object o)
        Returns the String representation of the given array, or null if the given object is either null or not an array. This method supports arrays having other arrays as elements.
        Parameters:
        o - the object that is expected to be an array.
        Returns:
        the String representation of the given array.
      • multiLineFormat

        protected String multiLineFormat​(Object[] iterable,
                                         Set<Object[]> alreadyFormatted)
      • singleLineFormat

        protected String singleLineFormat​(Object[] iterable,
                                          Set<Object[]> alreadyFormatted)
      • smartFormat

        protected String smartFormat​(Object[] iterable)
      • formatPrimitiveArray

        protected String formatPrimitiveArray​(Object o)
      • multiLineFormat

        protected String multiLineFormat​(Iterable<?> iterable)
      • smartFormat

        protected String smartFormat​(Iterable<?> iterable)
        Returns the String representation of the given Iterable, or null if the given Iterable is null.

        The Iterable will be formatted to a single line if it does not exceed 100 char, otherwise each elements will be formatted on a new line with 4 space indentation.

        Parameters:
        iterable - the Iterable to format.
        Returns:
        the String representation of the given Iterable.
      • doesDescriptionFitOnSingleLine

        private static boolean doesDescriptionFitOnSingleLine​(String singleLineDescription)