Class LogBuilder


  • public class LogBuilder
    extends java.lang.Object
    A class to wrap a StringBuilder for log generation purposes.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.List<java.lang.Integer> points
      The remembered buffer index.
      private java.lang.StringBuilder sb
      The string builder to use.
    • Constructor Summary

      Constructors 
      Constructor Description
      LogBuilder​(int size)
      Create a new LogBuilder that can only be used as a buffer.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(java.lang.Object... objects)
      Add objects to the buffer.
      <T> void addCollection​(java.lang.String delim, java.util.Collection<T> c)
      Add a delimited collection to the buffer.
      private static void addInternal​(java.lang.StringBuilder sb, java.lang.Object... objects)
      Add objects to a string builder.
      void addStackTrace()
      Add a stack trace to the buffer.
      boolean grew​(java.lang.Object... objects)
      Check if a buffer has grown since marked, and optionally insert text at that point.
      void log​(java.util.logging.Logger logger, java.util.logging.Level level)
      Output to a logger.
      void mark()
      Remember a position in a buffer.
      private static java.lang.String o2s​(java.lang.Object o)
      Convert a simple object to a string suitable for a log buffer.
      void shrink​(java.lang.String delim)
      Shorten a buffer by a trailing delimiter.
      int size()
      Get the amount of accumulated data.
      java.lang.String toString()
      void truncate​(int size)
      Truncate the buffer to a given size.
      static java.lang.String wide​(int size, java.lang.Object... objects)
      Add a group of objects to the buffer at a particular width
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • sb

        private final java.lang.StringBuilder sb
        The string builder to use.
      • points

        private final java.util.List<java.lang.Integer> points
        The remembered buffer index.
    • Constructor Detail

      • LogBuilder

        public LogBuilder​(int size)
        Create a new LogBuilder that can only be used as a buffer.
        Parameters:
        size - An initial size for the buffer.
    • Method Detail

      • o2s

        private static java.lang.String o2s​(java.lang.Object o)
        Convert a simple object to a string suitable for a log buffer.
        Parameters:
        o - The Object to convert.
        Returns:
        The simple string result.
      • addInternal

        private static void addInternal​(java.lang.StringBuilder sb,
                                        java.lang.Object... objects)
        Add objects to a string builder.
        Parameters:
        sb - The StringBuilder to add to.
        objects - The objects to add.
      • add

        public void add​(java.lang.Object... objects)
        Add objects to the buffer.
        Parameters:
        objects - The objects to add.
      • addCollection

        public <T> void addCollection​(java.lang.String delim,
                                      java.util.Collection<T> c)
        Add a delimited collection to the buffer.
        Type Parameters:
        T - The collection member type.
        Parameters:
        delim - An internal delimiter.
        c - The Collection of objects to add.
      • addStackTrace

        public void addStackTrace()
        Add a stack trace to the buffer.
      • truncate

        public void truncate​(int size)
        Truncate the buffer to a given size.
        Parameters:
        size - The size to truncate to.
      • mark

        public void mark()
        Remember a position in a buffer.
      • grew

        public boolean grew​(java.lang.Object... objects)
        Check if a buffer has grown since marked, and optionally insert text at that point.
        Parameters:
        objects - Optional Objects to insert if the buffer has grown.
        Returns:
        True if the buffer grew (before inserting).
      • shrink

        public void shrink​(java.lang.String delim)
        Shorten a buffer by a trailing delimiter. (Cheats, does not really check that the delimiter is there)
        Parameters:
        delim - The delimiter to remove.
      • log

        public void log​(java.util.logging.Logger logger,
                        java.util.logging.Level level)
        Output to a logger.
        Parameters:
        logger - The Logger to write to.
        level - The logging Level.
      • size

        public int size()
        Get the amount of accumulated data.
        Returns:
        The amount of data accumulated so far.
      • wide

        public static java.lang.String wide​(int size,
                                            java.lang.Object... objects)
        Add a group of objects to the buffer at a particular width
        Parameters:
        size - The width to set.
        objects - The Objects to add.
        Returns:
        The widened string.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object