Top Description Fields Constructors Methods
org.springframework.core.style

public Class SimpleValueStyler

extends DefaultValueStyler
Class Inheritance
Imports
java.lang.reflect.Method, java.util.Arrays, .Collection, .Map, .StringJoiner, java.util.function.Function, java.util.stream.Collectors

ValueStyler that converts objects to String form — generally for debugging purposes — using simple styling conventions that mimic the toString() styling conventions for standard JDK implementations of collections, maps, and arrays.

Uses the reflective visitor pattern underneath the hood to nicely encapsulate styling algorithms for each type of styled object.

Favor SimpleValueStyler over DefaultValueStyler when you wish to use styling similar to the JDK or when you need configurable control over the styling of classes and methods.

Author
Sam Brannen
Since
6.0

Field Summary

Modifier and TypeField and Description
private final Function<Class<?>, String>
public static final Function<Class<?>, String>
public static final Function<Method, String>
DEFAULT_METHOD_STYLER

Default Method styling function: converts the supplied Method to a simple string representation of the method's signature in the form of <method name>(<parameter types>), where <parameter types> is a comma-separated list of the simple names of the parameter types.

private final Function<Method, String>

Constructor Summary

AccessConstructor and Description
public
SimpleValueStyler()

Create a SimpleValueStyler using the DEFAULT_CLASS_STYLER and DEFAULT_METHOD_STYLER.

public
SimpleValueStyler(Function<Class<?>, String>
a function that applies styling to a Class
classStyler
,
Function<Method, String>
a function that applies styling to a Method
methodStyler
)

Create a SimpleValueStyler using the supplied class and method stylers.

Method Summary

Modifier and TypeMethod and Description
protected String
styleArray(Object[] array)

Overrides org.springframework.core.style.DefaultValueStyler.styleArray.

Generate a styled version of the supplied array.
protected String
styleClass(Class<?> clazz)

Overrides org.springframework.core.style.DefaultValueStyler.styleClass.

Generate a styled version of the supplied Class.
protected String
styleCollection(Collection<?> collection)

Overrides org.springframework.core.style.DefaultValueStyler.styleCollection.

Generate a styled version of the supplied Collection.
protected <K, V> String
styleMap(Map<K, V> map)

Overrides org.springframework.core.style.DefaultValueStyler.styleMap.

Generate a styled version of the supplied Map.
protected String
styleMethod(Method method)

Overrides org.springframework.core.style.DefaultValueStyler.styleMethod.

Generate a styled version of the supplied Method.
protected String
styleNull()

Overrides org.springframework.core.style.DefaultValueStyler.styleNull.

Generate a styled version of null.
protected String
styleString(String str)

Overrides org.springframework.core.style.DefaultValueStyler.styleString.

Generate a styled version of the supplied String.
private static String
Inherited from org.springframework.core.style.DefaultValueStyler:
stylestyleMapEntrystyleObject

Field Detail

classStylerback to summary
private final Function<Class<?>, String> classStyler
DEFAULT_CLASS_STYLERback to summary
public static final Function<Class<?>, String> DEFAULT_CLASS_STYLER

Default Class styling function: Class#getCanonicalName().

DEFAULT_METHOD_STYLERback to summary
public static final Function<Method, String> DEFAULT_METHOD_STYLER

Default Method styling function: converts the supplied Method to a simple string representation of the method's signature in the form of <method name>(<parameter types>), where <parameter types> is a comma-separated list of the simple names of the parameter types.

For example, if the supplied method is a reference to String#getBytes(java.nio.charset.Charset), this function will return "getBytes(Charset)".

methodStylerback to summary
private final Function<Method, String> methodStyler

Constructor Detail

SimpleValueStylerback to summary
public SimpleValueStyler()

Create a SimpleValueStyler using the DEFAULT_CLASS_STYLER and DEFAULT_METHOD_STYLER.

SimpleValueStylerback to summary
public SimpleValueStyler(Function<Class<?>, String> classStyler, Function<Method, String> methodStyler)

Create a SimpleValueStyler using the supplied class and method stylers.

Parameters
classStyler:Function<Class<?>, String>

a function that applies styling to a Class

methodStyler:Function<Method, String>

a function that applies styling to a Method

Method Detail

styleArrayback to summary
protected String styleArray(Object[] array)

Overrides org.springframework.core.style.DefaultValueStyler.styleArray.

Doc from org.springframework.core.style.DefaultValueStyler.styleArray.

Generate a styled version of the supplied array.

Returns:String

a styled version of the supplied array

Annotations
@Override
styleClassback to summary
protected String styleClass(Class<?> clazz)

Overrides org.springframework.core.style.DefaultValueStyler.styleClass.

Doc from org.springframework.core.style.DefaultValueStyler.styleClass.

Generate a styled version of the supplied Class.

The default implementation delegates to ClassUtils#getShortName(Class).

Returns:String

a styled version of the supplied class

Annotations
@Override
styleCollectionback to summary
protected String styleCollection(Collection<?> collection)

Overrides org.springframework.core.style.DefaultValueStyler.styleCollection.

Doc from org.springframework.core.style.DefaultValueStyler.styleCollection.

Generate a styled version of the supplied Collection.

Returns:String

a styled version of the supplied collection

Annotations
@Override
styleMapback to summary
protected <K, V> String styleMap(Map<K, V> map)

Overrides org.springframework.core.style.DefaultValueStyler.styleMap.

Doc from org.springframework.core.style.DefaultValueStyler.styleMap.

Generate a styled version of the supplied Map.

Returns:String

a styled version of the supplied map

Annotations
@Override
styleMethodback to summary
protected String styleMethod(Method method)

Overrides org.springframework.core.style.DefaultValueStyler.styleMethod.

Doc from org.springframework.core.style.DefaultValueStyler.styleMethod.

Generate a styled version of the supplied Method.

The default implementation returns the method's name and the short name of the method's declaring class, separated by the "@" symbol.

Returns:String

a styled version of the supplied method

Annotations
@Override
styleNullback to summary
protected String styleNull()

Overrides org.springframework.core.style.DefaultValueStyler.styleNull.

Doc from org.springframework.core.style.DefaultValueStyler.styleNull.

Generate a styled version of null.

The default implementation returns "[null]".

Returns:String

a styled version of null

Annotations
@Override
styleStringback to summary
protected String styleString(String str)

Overrides org.springframework.core.style.DefaultValueStyler.styleString.

Doc from org.springframework.core.style.DefaultValueStyler.styleString.

Generate a styled version of the supplied String.

The default implementation returns the supplied string wrapped in single quotes.

Returns:String

a styled version of the supplied string

Annotations
@Override
toSimpleMethodSignatureback to summary
private static String toSimpleMethodSignature(Method method)