Class Appenders
- java.lang.Object
-
- org.sosy_lab.common.Appenders
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classAppenders.AbstractAppenderBase implementation ofAppenderthat ensures that theAppenders.AbstractAppender.toString()method returns the same result thatAppender.appendTo(Appendable)produces in order to ensure that the contract ofAppenderis fulfilled.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidappendTo(Appendable output, @Nullable Object o)Write the given object into the given output.static StringBuilderappendTo(StringBuilder sb, Appender a)Let anAppenderdump itself into aStringBuilder.static Appenderconcat(Iterable<Appender> pAppenders)Create a newAppenderthat consists of the sequential concatenation of multiple appenders.static Appenderconcat(Appender... pAppenders)Create a newAppenderthat consists of the sequential concatenation of multiple appenders.static AppendercreateAppender(@Nullable Object o)Return anAppenderfor the given object.static AppenderforIterable(Joiner joiner, Iterable<?> it)static AppenderforMap(Joiner.MapJoiner joiner, Map<?,?> map)static AppenderfromToStringMethod(@Nullable Object o)Return anAppenderthat writes the result of theObject.toString()method of an object into the output.static StringtoString(Appender a)Convert anAppenderinto a string by calling it'sAppender.appendTo(Appendable)method.static StringtoStringWithTruncation(Appender a, int truncateAt)Convert anAppenderinto a string by calling it'sAppender.appendTo(Appendable)method.
-
-
-
Method Detail
-
createAppender
public static Appender createAppender(@Nullable Object o)
Return anAppenderfor the given object. If the object is anAppenderitself, it is returned. Otherwise an appender that callsObject.toString()is returned (c.f.fromToStringMethod(Object).- Parameters:
o- The object which will be dumped, may be null.- Returns:
- an
Appenderinstance
-
appendTo
public static void appendTo(Appendable output, @Nullable Object o) throws IOException
Write the given object into the given output. If the object is anAppender, itsAppender.appendTo(Appendable)method is called, otherwise theObject.toString()method is called. The object may benull, in this case"null"is written.- Parameters:
output- The appendable to write into.o- The object which will be dumped, may be null.- Throws:
IOException- If the appendable throws an IOException
-
appendTo
@CanIgnoreReturnValue public static StringBuilder appendTo(StringBuilder sb, Appender a)
Let anAppenderdump itself into aStringBuilder. This method is similar to passing theStringBuilderto theAppender.appendTo(Appendable)method, just without the checked exception.- Parameters:
sb- The StringBuilder that will receive the content.a- The Appender to dump into the StringBuilder.- Returns:
- The passed StringBuilder to allow for method chaining.
-
forIterable
public static Appender forIterable(Joiner joiner, Iterable<?> it)
- Parameters:
joiner- The joiner that will be used to create a string representation of the iterable.it- The iterable which will be dumped.- Returns:
- an
Appenderinstance
-
forMap
public static Appender forMap(Joiner.MapJoiner joiner, Map<?,?> map)
- Parameters:
joiner- The joiner that will be used to create a string representation of the map.map- The map which will be dumped.- Returns:
- an
Appenderinstance
-
fromToStringMethod
public static Appender fromToStringMethod(@Nullable Object o)
Return anAppenderthat writes the result of theObject.toString()method of an object into the output.This will not give the performance benefit that is expected from the use of appenders, and should only be used to adapt classes not implementing this interface themselves.
If
nullis passed, the resulting appender will write"null". If an object is passed, the appender will call theObject.toString()method once each time it is used (no caching is done).- Parameters:
o- The object which will be dumped, may be null.- Returns:
- an
Appenderinstance
-
concat
public static Appender concat(Iterable<Appender> pAppenders)
Create a newAppenderthat consists of the sequential concatenation of multiple appenders. The given iterable is traversed once each time the resulting appender'sAppender.appendTo(Appendable)method is called. The iterable may not contain nulls or be null itself..
-
concat
public static Appender concat(Appender... pAppenders)
Create a newAppenderthat consists of the sequential concatenation of multiple appenders.- Throws:
NullPointerException- if any of the provided appendables is null
-
toString
public static String toString(Appender a)
Convert anAppenderinto a string by calling it'sAppender.appendTo(Appendable)method.Note that the contract of
Appenderspecifies that you should be able to callObject.toString()on the object and get the same result, thus it should not be necessary to call this method from client code.However, it may be practical to implement the
Object.toString()method of anAppenderby delegating to this method.- Parameters:
a- TheAppenderto convert into a string.- Returns:
- a string representation of the passed object.
-
toStringWithTruncation
public static String toStringWithTruncation(Appender a, int truncateAt)
Convert anAppenderinto a string by calling it'sAppender.appendTo(Appendable)method.This method truncates the returned string at a given length, and tries to be more efficient than generating the full string and truncating it at the end (though no guarantees are made).
- Parameters:
a- TheAppenderto convert into a string.truncateAt- The maximum size of the returned string(>= 0)- Returns:
- a string representation of the passed object, with a maximum size of
truncateAt
-
-