Package net.sf.freecol.common.util
Class LogBuilder
- java.lang.Object
-
- net.sf.freecol.common.util.LogBuilder
-
public class LogBuilder extends java.lang.Object
A 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 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
-
-
-
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
- TheObject
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
- TheStringBuilder
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
- TheCollection
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
- OptionalObject
s 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
- TheLogger
to 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
- TheObject
s to add.- Returns:
- The widened string.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-