Package Torello.Java.Additional
Class AppendableLog
- java.lang.Object
-
- Torello.Java.Additional.AppendableLog
-
- All Implemented Interfaces:
java.lang.Appendable
public class AppendableLog extends java.lang.Object implements java.lang.Appendable
Appendable
Implementation:
This class implements and upgrades the Simple, Javajava.lang.Appendable
interface, providing additional features and improvements to it. TheAppendable
interace is a viable design-decsion possibility for outputing text-data to a log.
AnAppendable
is both blindingly easy, and highly customizable to use for third-party developers who may not be familiar with the internals of another developer's source-code.
This Class' Primary Addition toAppendable
:
AnAppendableLog
instance merely adds the features offered by theenum Verbosity
to make it easier to use anAppendable
implementation in a tool or application that outputs varying levels of verbosity when writing log-text to a user. Verbosity can actually be an invaluable concept for a program-designer who would like to make his utilities more manageable, and easier to understand and learn for other software developers.
There class also provides some basic indentation methods that are useful when outputing large numbers of related messages. Finally, there is the stipulation that the wrapped (internal)Appendable
used for output must be an instance ofAppendableSafe
rather than just the standardjava.lang.Appendable
.AppendableSafe
instances make it easier for a utility designer to avoid the (sometimes) messy, checked Java-ExceptionIOException
from cluttering up log-code, if he so choses.
Used in Java-HTML JAR Library:
This class was originally developed for use with the toolImageScraper
, and it's use can be seen by clicking through the source-code for that tool and its helper classes.Another Logging-Helper class. This interface builds on theAppendableSafe
class, and in this case it meaans that the internalAppendable
that is wrapped by this one is an instance ofAppendableSafe
- rather than the Standard-Javajava.lang.Appendable
interface.
The purpose of theAppendableSafe
class is merely to prevent Java's Checked-Exception'IOException'
, and replace it with any number of uncheckedThrowable
options. The purpose of this class is merely to add several convenience fields (hasLog
andlevel
) so that in the course of writing output-log code, a programmer is not bogged-down with 'Verbose Log Code' (Logging code that is, itself, extremely verbose-looking).- See Also:
ImageScraper
,AppendableSafe
Hi-Lited Source-Code:- View Here: Torello/Java/Additional/AppendableLog.java
- Open New Browser-Tab: Torello/Java/Additional/AppendableLog.java
File Size: 14,798 Bytes Line Count: 345 '\n' Characters Found
-
-
Constructor Summary
Constructors Constructor Description AppendableLog(Appendable appendable, Verbosity verbosity)
Construct an instance of this class.AppendableLog(AppendableSafe appendableSafe, Verbosity verbosity)
Construct an instance of this class.
-
Method Summary
Add Indentation and Append Methods Modifier and Type Method AppendableSafe
appendI12(String s)
AppendableSafe
appendI16(String s)
AppendableSafe
appendI4(String s)
AppendableSafe
appendI8(String s)
Methods to Check Field hasLog
andlevel
Modifier and Type Method boolean
levelEQ(int level)
boolean
levelGTEQ(int level)
Methods: interface java.lang.Appendable Modifier and Type Method AppendableSafe
append(char c)
AppendableSafe
append(CharSequence csq)
AppendableSafe
append(CharSequence csq, int start, int end)
-
-
-
Field Detail
-
I4
public static final java.lang.String I4
Four space-characters.- See Also:
- Constant Field Values
- Code:
- Exact Field Declaration Expression:
public static final String I4 = " ";
-
I8
public static final java.lang.String I8
Eight space-characters.- See Also:
- Constant Field Values
- Code:
- Exact Field Declaration Expression:
public static final String I8 = I4 + I4;
-
I12
public static final java.lang.String I12
Twelve space-characters.- See Also:
- Constant Field Values
- Code:
- Exact Field Declaration Expression:
public static final String I12 = I8 + I4;
-
I16
public static final java.lang.String I16
Sixteen space-characters.- See Also:
- Constant Field Values
- Code:
- Exact Field Declaration Expression:
public static final String I16 = I8 + I8;
-
log
public final AppendableSafe log
The actual log, itself.
This field may be passed and assigned null by the constructor. The user should be aware to take some care if null log's are allowed in your code. This just means that there are circumstances where logging is to be "turned off". In such cases, make sure to write code that chcks whether the log is null before printing to it. (Make sure to avoid throwingNullPointerException
)
This is an instance ofAppendableSafe
because the actual classjava.lang.Appendable
has methods all of which throwIOException
. TheAppendableSafe
class wraps those method calls and blocks the uncheckedIOException's
.- See Also:
AppendableSafe
- Code:
- Exact Field Declaration Expression:
public final AppendableSafe log;
-
hasLog
-
level
public final int level
This is nothing more than the enumVerbosity
fieldVerbosity.level
.
-
-
Constructor Detail
-
AppendableLog
public AppendableLog(java.lang.Appendable appendable, Verbosity verbosity)
Construct an instance of this class. The'appendable'
parameter, if non-null, is immediately wrapped into anAppendableSafe
instance, and configured to throwAppendableError
rather thanIOException
when / if the internal method throws anyIOException's
.- Parameters:
appendable
- This may be any instance ofjava.lang.Appendable
.verbosity
- An instance of theVerbosity
enum. If parameter'appendable'
is null, then this paramter may also be null. However if'appendable'
is non-null, then this may not be null either - or an exception shall throw.- Throws:
java.lang.NullPointerException
- If parameter'appendable'
is non-null, but parameter'verbosity'
is null, then aNullPointerException
will throw.
-
AppendableLog
public AppendableLog(AppendableSafe appendableSafe, Verbosity verbosity)
Construct an instance of this class. Since there are several ways to configure the internalAppendableSafe
instance, this constructor allows a user to simply pass an already built instance ofAppendableSafe
as a parameter.- Parameters:
appendableSafe
- This may be any instance ofAppendableSafe
. The primary purpose of this class is to shunt theIOException
that is thrown byjava.lang.Appendable
methods, and either suppress them, or re-wrap them into an unchecked-Throwable
.
Being able to leave off thethrows IOException
when writing log code makes the process much easier.verbosity
- An instance of theVerbosity
enum. If parameter'appendableSafe'
is null, then this paramter may also be null. However if'appendableSafe'
is non-null, then this may not be null either - or an exception shall throw.- Throws:
java.lang.NullPointerException
- If parameter'appendableSafe'
is non-null, but parameter'verbosity'
is null, then aNullPointerException
will throw.
-
-
Method Detail
-
append
public AppendableSafe append(char c)
Appends the specified character to thisAppendable
.
Description copied from class:java.lang.Appendable
, JDK 1.8- Specified by:
append
in interfacejava.lang.Appendable
- Parameters:
c
- The character to append- Returns:
- A reference to this
Appendable
. - Throws:
java.lang.NullPointerException
- If theAppendableSafe
instance field (log
) was passed null during construction of'this'
instance.- Code:
- Exact Method Body:
return this.log.append(c);
-
append
public AppendableSafe append(java.lang.CharSequence csq)
Appends the specified character sequence to thisAppendable
.
Depending on which class implements the character sequence'csq'
, the entire sequence may not be appended. For instance, if'csq'
is a'CharBuffer'
the subsequence to append is defined by the buffer's position and limit.
Description copied from class:java.lang.Appendable
, JDK 1.8- Specified by:
append
in interfacejava.lang.Appendable
- Parameters:
csq
- The character sequence to append. If csq is null, then the four characters "null" are appended to thisAppendable
.- Returns:
- A reference to this
Appendable
. - Throws:
java.lang.NullPointerException
- If theAppendableSafe
instance field (log
) was passed null during construction of'this'
instance.- Code:
- Exact Method Body:
return this.log.append(csq);
-
append
public AppendableSafe append(java.lang.CharSequence csq, int start, int end)
Appends a subsequence of the specified character sequence to thisAppendable
.
An invocation of this method of the formout.append(csq, start, end)
when'csq'
is not null, behaves in exactly the same way as the invocation:
Java Line of Code:
out.append(csq.subSequence(start, end))
Description copied from class:java.lang.Appendable
, JDK 1.8- Specified by:
append
in interfacejava.lang.Appendable
- Parameters:
csq
- The character sequence from which a subsequence will be appended. If csq is null, then the four characters "null" are appended to thisAppendable
.start
- The index of the first character in the subsequenceend
- The index of the character following the last character in the subsequence- Returns:
- A reference to this
Appendable
. - Throws:
java.lang.NullPointerException
- If theAppendableSafe
instance field (log
) was passed null during construction of'this'
instance.- Code:
- Exact Method Body:
return this.log.append(csq, start, end);
-
appendI4
public AppendableSafe appendI4(java.lang.String s)
Appends four character spaces of indentation, and then appendsString
-parameter's'
.- Returns:
- A reference to this
Appendable
. - Throws:
java.lang.NullPointerException
- If theAppendableSafe
instance field (log
) was passed null during construction of'this'
instance.- Code:
- Exact Method Body:
return this.log.append(I4).append(s);
-
appendI8
public AppendableSafe appendI8(java.lang.String s)
Appends eight character spaces of indentation, and then appendsString
-parameter's'
.- Returns:
- A reference to this
Appendable
. - Throws:
java.lang.NullPointerException
- If theAppendableSafe
instance field (log
) was passed null during construction of'this'
instance.- Code:
- Exact Method Body:
return this.log.append(I8).append(s);
-
appendI12
public AppendableSafe appendI12(java.lang.String s)
Appends twelve character spaces of indentation, and then appendsString
-parameter's'
.- Returns:
- A reference to this
Appendable
. - Throws:
java.lang.NullPointerException
- If theAppendableSafe
instance field (log
) was passed null during construction of'this'
instance.- Code:
- Exact Method Body:
return this.log.append(I12).append(s);
-
appendI16
public AppendableSafe appendI16(java.lang.String s)
Appends sixteen character spaces of indentation, and then appendsString
-parameter's'
.- Returns:
- A reference to this
Appendable
. - Throws:
java.lang.NullPointerException
- If theAppendableSafe
instance field (log
) was passed null during construction of'this'
instance.- Code:
- Exact Method Body:
return this.log.append(I16).append(s);
-
levelEQ
public boolean levelEQ(int level)
Quick check that can be used to test whether or not to print to a log. The purpose of an instance ofVerbosity
is that logging information is only printed to an output log if the user has requested a certain level of verbosity.
This method will returnTRUE
if the user has requested logging, and this instance' internallevel
field is equal to parameter'level'
.- Parameters:
level
- An integer that should correspond to the enumVerbosity
internal fieldVerbosity.level
.- Returns:
TRUE
if -
ReturnsFALSE
otherwise- Code:
- Exact Method Body:
if (hasLog) return (this.level == level); return false;
-
levelGTEQ
public boolean levelGTEQ(int level)
Quick check that can be used to test whether or not to print to a log. The purpose of an instance ofVerbosity
is that logging information is only printed to an output log if the user has requested a certain level of verbosity.
This method will returnTRUE
if the user has requested logging, and this instance' internallevel
field is greater than or equal to parameter'level'
.- Parameters:
level
- An integer that should correspond to the enumVerbosity
internal fieldVerbosity.level
.- Returns:
TRUE
if -
ReturnsFALSE
otherwise- Code:
- Exact Method Body:
if (hasLog) return (this.level >= level); return false;
-
-