Package net.sf.freecol.common.util
Class LogBuilder
- java.lang.Object
-
- net.sf.freecol.common.util.LogBuilder
-
public class LogBuilder extends java.lang.ObjectA class to wrap a StringBuilder for log generation purposes.
-
-
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 voidadd(java.lang.Object... objects)Add objects to the buffer.<T> voidaddCollection(java.lang.String delim, java.util.Collection<T> c)Add a delimited collection to the buffer.private static voidaddInternal(java.lang.StringBuilder sb, java.lang.Object... objects)Add objects to a string builder.voidaddStackTrace()Add a stack trace to the buffer.booleangrew(java.lang.Object... objects)Check if a buffer has grown since marked, and optionally insert text at that point.voidlog(java.util.logging.Logger logger, java.util.logging.Level level)Output to a logger.voidmark()Remember a position in a buffer.private static java.lang.Stringo2s(java.lang.Object o)Convert a simple object to a string suitable for a log buffer.voidshrink(java.lang.String delim)Shorten a buffer by a trailing delimiter.intsize()Get the amount of accumulated data.java.lang.StringtoString()voidtruncate(int size)Truncate the buffer to a given size.static java.lang.Stringwide(int size, java.lang.Object... objects)Add a group of objects to the buffer at a particular width
-
-
-
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- TheObjectto 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- TheStringBuilderto 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- TheCollectionof 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- OptionalObjects 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- TheLoggerto write to.level- The loggingLevel.
-
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- TheObjects to add.- Returns:
- The widened string.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-