Class ParameterFormatter
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static final class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final DateTimeFormatterprivate static final charprivate static final char(package private) static final StringSeparator for error messages.(package private) static final StringPrefix for errors.(package private) static final StringSeparator for errors.(package private) static final StringSuffix for errors.private static final char(package private) static final StringPrefix for recursion.(package private) static final StringSuffix for recursion.private static final Logger -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) static ParameterFormatter.MessagePatternAnalysisanalyzePattern(String pattern, int argCount) Analyzes – finds argument placeholder (i.e., "{}") occurrences, etc.(package private) static voidanalyzePattern(String pattern, int argCount, ParameterFormatter.MessagePatternAnalysis analysis) Analyzes – finds argument placeholder (i.e., "{}") occurrences, etc.private static voidappendArray(boolean[] a, StringBuilder str) private static voidappendArray(byte[] a, StringBuilder str) private static voidappendArray(char[] a, StringBuilder str) private static voidappendArray(double[] a, StringBuilder str) private static voidappendArray(float[] a, StringBuilder str) (package private) static voidappendArray(int[] a, StringBuilder str) private static voidappendArray(long[] a, StringBuilder str) private static voidappendArray(short[] a, StringBuilder str) private static voidappendArray(Object o, StringBuilder str, Set<Object> dejaVu, Class<?> oClass) private static voidappendCollection(Object o, StringBuilder str, Set<Object> dejaVu) Specialized handler forCollections.private static booleanappendDate(Object o, StringBuilder str) private static voidappendMap(Object o, StringBuilder str, Set<Object> dejaVu) Specialized handler forMaps.private static voidappendPotentiallyRecursiveValue(Object o, StringBuilder str, Set<Object> dejaVu) private static booleanappendSpecialTypes(Object o, StringBuilder str) cloneDejaVu(Set<Object> dejaVu) private static voidcopyMessagePatternContainingEscapes(StringBuilder buffer, String pattern, int startIndex, int endIndex) (package private) static StringThis method performs a deep toString of the given Object.(package private) static StringFormat the given pattern using provided arguments.(package private) static voidformatMessage(StringBuilder buffer, String pattern, Object[] args, int argCount, ParameterFormatter.MessagePatternAnalysis analysis) Format the given pattern using provided arguments into the buffer pointed.private static voidformatMessageContainingEscapes(StringBuilder buffer, String pattern, Object[] args, int argCount, ParameterFormatter.MessagePatternAnalysis analysis) private static voidformatMessageContainingNoEscapes(StringBuilder buffer, String pattern, Object[] args, int argCount, ParameterFormatter.MessagePatternAnalysis analysis) getOrCreateDejaVu(Set<Object> dejaVu) private static voidhandleErrorInObjectToString(Object o, StringBuilder str, Throwable t) (package private) static StringidentityToString(Object obj) This method returns the same as if Object.toString() would not have been overridden in obj.private static booleanisLastArgumentThrowable(Object[] args, int argCount) private static booleanReturnstrueif the specified object is an array, a Map or a Collection.(package private) static voidrecursiveDeepToString(Object o, StringBuilder str) This method performs a deeptoString()of the givenObject.private static voidrecursiveDeepToString(Object o, StringBuilder str, Set<Object> dejaVu) This method performs a deeptoString()of the givenObject.private static voidtryObjectToString(Object o, StringBuilder str)
-
Field Details
-
RECURSION_PREFIX
-
RECURSION_SUFFIX
-
ERROR_PREFIX
-
ERROR_SEPARATOR
-
ERROR_MSG_SEPARATOR
-
ERROR_SUFFIX
-
DELIM_START
private static final char DELIM_START- See Also:
-
DELIM_STOP
private static final char DELIM_STOP- See Also:
-
ESCAPE_CHAR
private static final char ESCAPE_CHAR- See Also:
-
DATE_FORMATTER
-
STATUS_LOGGER
-
-
Constructor Details
-
ParameterFormatter
private ParameterFormatter()
-
-
Method Details
-
analyzePattern
Analyzes – finds argument placeholder (i.e., "{}") occurrences, etc. – the given message pattern.Only "{}" strings are treated as argument placeholders. Escaped or incomplete argument placeholders will be ignored. Some invalid argument placeholder examples:
{ } foo\{} {bar {buzz}- Parameters:
pattern- a message pattern to be analyzedargCount- The number of arguments to be formatted. For instance, for a parametrized message containing 7 placeholders in the pattern and 4 arguments for formatting, analysis will only need to store the index of the first 4 placeholder characters. A negative value indicates no limit.- Returns:
- the analysis result
-
analyzePattern
static void analyzePattern(String pattern, int argCount, ParameterFormatter.MessagePatternAnalysis analysis) Analyzes – finds argument placeholder (i.e., "{}") occurrences, etc. – the given message pattern.Only "{}" strings are treated as argument placeholders. Escaped or incomplete argument placeholders will be ignored. Some invalid argument placeholder examples:
{ } foo\{} {bar {buzz}- Parameters:
pattern- a message pattern to be analyzedargCount- The number of arguments to be formatted. For instance, for a parametrized message containing 7 placeholders in the pattern and 4 arguments for formatting, analysis will only need to store the index of the first 4 placeholder characters. A negative value indicates no limit.analysis- an object to store the results
-
format
Format the given pattern using provided arguments.- Parameters:
pattern- a formatting patternargs- arguments to be formatted- Returns:
- the formatted message
- Throws:
IllegalArgumentException- on invalid input
-
formatMessage
static void formatMessage(StringBuilder buffer, String pattern, Object[] args, int argCount, ParameterFormatter.MessagePatternAnalysis analysis) Format the given pattern using provided arguments into the buffer pointed.- Parameters:
buffer- a buffer the formatted output will be written topattern- a formatting patternargs- arguments to be formatted- Throws:
IllegalArgumentException- on invalid input
-
isLastArgumentThrowable
-
formatMessageContainingNoEscapes
private static void formatMessageContainingNoEscapes(StringBuilder buffer, String pattern, Object[] args, int argCount, ParameterFormatter.MessagePatternAnalysis analysis) -
formatMessageContainingEscapes
private static void formatMessageContainingEscapes(StringBuilder buffer, String pattern, Object[] args, int argCount, ParameterFormatter.MessagePatternAnalysis analysis) -
copyMessagePatternContainingEscapes
private static void copyMessagePatternContainingEscapes(StringBuilder buffer, String pattern, int startIndex, int endIndex) -
deepToString
This method performs a deep toString of the given Object. Primitive arrays are converted using their respective Arrays.toString methods while special handling is implemented for "container types", i.e. Object[], Map and Collection because those could contain themselves.It should be noted that neither AbstractMap.toString() nor AbstractCollection.toString() implement such a behavior. They only check if the container is directly contained in itself, but not if a contained container contains the original one. Because of that, Arrays.toString(Object[]) isn't safe either. Confusing? Just read the last paragraph again and check the respective toString() implementation.
This means, in effect, that logging would produce a usable output even if an ordinary System.out.println(o) would produce a relatively hard-to-debug StackOverflowError.
- Parameters:
o- The object.- Returns:
- The String representation.
-
recursiveDeepToString
This method performs a deeptoString()of the givenObject.Primitive arrays are converted using their respective
Arrays.toString()methods, while special handling is implemented for container types, i.e.Object[],MapandCollection, because those could contain themselves.It should be noted that neither
AbstractMap.toString()norAbstractCollection.toString()implement such a behavior. They only check if the container is directly contained in itself, but not if a contained container contains the original one. Because of that,Arrays.toString(Object[])isn't safe either. Confusing? Just read the last paragraph again and check the respectivetoString()implementation.This means, in effect, that logging would produce a usable output even if an ordinary
System.out.println(o)would produce a relatively hard-to-debugStackOverflowError.- Parameters:
o- theObjectto convert into aStringstr- theStringBuilderthatowill be appended to
-
recursiveDeepToString
This method performs a deeptoString()of the givenObject.Primitive arrays are converted using their respective
Arrays.toString()methods, while special handling is implemented for container types, i.e.Object[],MapandCollection, because those could contain themselves.dejaVuis used in case of those container types to prevent an endless recursion.It should be noted that neither
AbstractMap.toString()norAbstractCollection.toString()implement such a behavior. They only check if the container is directly contained in itself, but not if a contained container contains the original one. Because of that,Arrays.toString(Object[])isn't safe either. Confusing? Just read the last paragraph again and check the respectivetoString()implementation.This means, in effect, that logging would produce a usable output even if an ordinary
System.out.println(o)would produce a relatively hard-to-debugStackOverflowError.- Parameters:
o- theObjectto convert into aStringstr- theStringBuilderthatowill be appended todejaVu- a set of container objects directly or transitively containingo
-
appendSpecialTypes
-
appendDate
-
isMaybeRecursive
Returnstrueif the specified object is an array, a Map or a Collection. -
appendPotentiallyRecursiveValue
private static void appendPotentiallyRecursiveValue(Object o, StringBuilder str, Set<Object> dejaVu) -
appendArray
-
appendMap
Specialized handler forMaps. -
appendCollection
Specialized handler forCollections. -
getOrCreateDejaVu
-
createDejaVu
-
cloneDejaVu
-
tryObjectToString
-
handleErrorInObjectToString
-
identityToString
This method returns the same as if Object.toString() would not have been overridden in obj.Note that this isn't 100% secure as collisions can always happen with hash codes.
Copied from Object.hashCode():
As much as is reasonably practical, the hashCode method defined by class
Objectdoes return distinct integers for distinct objects. (This is typically implemented by converting the internal address of the object into an integer, but this implementation technique is not required by the Java™ programming language.)- Parameters:
obj- the Object that is to be converted into an identity string.- Returns:
- the identity string as also defined in Object.toString()
-
appendArray
- See Also:
-
appendArray
- See Also:
-
appendArray
- See Also:
-
appendArray
- See Also:
-
appendArray
- See Also:
-
appendArray
- See Also:
-
appendArray
- See Also:
-
appendArray
- See Also:
-