Interface Printable
- All Known Implementing Classes:
KeyPath,KeyPath.Immut,KeyPath.Mut,Printable.Abstract
This interface exposes multiple printing methods, each named with "print." No matter the printing method used, the content generated by each method must be the same result. For example, the following assertion should pass:
Printable printable = ...;
StringBuilder builder = new StringBuilder();
printable.printTo(builder);
assert printable.printString().equals(builder.toString());
Purpose
A Printable is typically passed to a method which expects to display information somewhere. The purpose is
to provide late resolution and type-based concatenation of error messages, as opposed to eager construction of
strings. Many error messages can be quite long, and might be better streamed.
Mutability
Mutability is left intentionally undefined. Instances of this type are not usually stored, but passed and consumed, which means that consumers will (usually) need to call one of the "print" methods at most once.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic classA base implementation forPrintable. -
Method Summary
Modifier and TypeMethodDescriptionstatic @NonNull PrintableJoins multiple printable values, appending them one after the other.static @NonNull PrintablepreBuilt(@NonNull CharSequence content) Makes a simple implementation based on an existing string.@NonNull StringGets the printed content as a stringvoidprintTo(@NonNull Appendable output) Prints to the given appendablevoidprintTo(@NonNull StringBuilder output) Prints to the given builder@NonNull StringtoString()Gets a string representation.
-
Method Details
-
printString
@NonNull String printString()Gets the printed content as a string- Returns:
- printed string
-
printTo
Prints to the given appendable- Parameters:
output- where to place the message- Throws:
IOException- if the output threw this error, it is propagated
-
printTo
Prints to the given builder- Parameters:
output- where to place the message
-
toString
@NonNull String toString()Gets a string representation.Implementations are strongly encouraged (but not required) to return the same value as fo
printString() -
preBuilt
Makes a simple implementation based on an existing string. The argument will be yielded by each of the printing methods.- Parameters:
content- the prebuilt string or character sequence- Returns:
- a printable using it
-
join
Joins multiple printable values, appending them one after the other.This method creates a new
Printablewhich combines the arguments in the sequence they are provided. If the returned result is printed, it will be identically to printing each of the arguments in a loop.If the caller modifies the
valuesarray after calling this function, it is not defined whether such modification will affect or not affect the returnedPrintable.- Parameters:
values- the values to join together- Returns:
- a printable which prints each of the arguments, in sequence
-