Class Appenders

java.lang.Object
org.sosy_lab.common.Appenders

public final class Appenders extends Object
Utility class providing Appenders for various cases.
  • Method Details

    • createAppender

      public static Appender createAppender(@Nullable Object o)
      Return an Appender for the given object. If the object is an Appender itself, it is returned. Otherwise an appender that calls Object.toString() is returned (c.f. fromToStringMethod(Object).
      Parameters:
      o - The object which will be dumped, may be null.
      Returns:
      an Appender instance
    • appendTo

      public static void appendTo(Appendable output, @Nullable Object o) throws IOException
      Write the given object into the given output. If the object is an Appender, its Appender.appendTo(Appendable) method is called, otherwise the Object.toString() method is called. The object may be null, 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 an Appender dump itself into a StringBuilder. This method is similar to passing the StringBuilder to the Appender.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)
      Return an Appender that writes an Iterable into the output using a given Joiner.
      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 Appender instance
    • forMap

      public static Appender forMap(Joiner.MapJoiner joiner, Map<?,?> map)
      Return an Appender that writes a Map into the output using a given Joiner.
      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 Appender instance
    • fromToStringMethod

      public static Appender fromToStringMethod(@Nullable Object o)
      Return an Appender that writes the result of the Object.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 null is passed, the resulting appender will write "null". If an object is passed, the appender will call the Object.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 Appender instance
    • concat

      public static Appender concat(Iterable<Appender> pAppenders)
      Create a new Appender that consists of the sequential concatenation of multiple appenders. The given iterable is traversed once each time the resulting appender's Appender.appendTo(Appendable) method is called. The iterable may not contain nulls or be null itself..
    • concat

      public static Appender concat(Appender... pAppenders)
      Create a new Appender that 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 an Appender into a string by calling it's Appender.appendTo(Appendable) method.

      Note that the contract of Appender specifies that you should be able to call Object.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 an Appender by delegating to this method.

      Parameters:
      a - The Appender to convert into a string.
      Returns:
      a string representation of the passed object.
    • toStringWithTruncation

      public static String toStringWithTruncation(Appender a, int truncateAt)
      Convert an Appender into a string by calling it's Appender.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 - The Appender to 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