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
AppendableImplementation:
This class implements and upgrades the Simple, Javajava.lang.Appendableinterface, providing additional features and improvements to it. TheAppendableinterace is a viable design-decsion possibility for outputing text-data to a log.
AnAppendableis 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:
AnAppendableLoginstance merely adds the features offered by theenum Verbosityto make it easier to use anAppendableimplementation 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)Appendableused for output must be an instance ofAppendableSaferather than just the standardjava.lang.Appendable.AppendableSafeinstances make it easier for a utility designer to avoid the (sometimes) messy, checked Java-ExceptionIOExceptionfrom 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 theAppendableSafeclass, and in this case it meaans that the internalAppendablethat is wrapped by this one is an instance ofAppendableSafe- rather than the Standard-Javajava.lang.Appendableinterface.
The purpose of theAppendableSafeclass is merely to prevent Java's Checked-Exception'IOException', and replace it with any number of uncheckedThrowableoptions. The purpose of this class is merely to add several convenience fields (hasLogandlevel) 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,810 Bytes Line Count: 345 '\n' Characters Found
-
-
Constructor Summary
Constructors Constructor AppendableLog(Appendable appendable, Verbosity verbosity)AppendableLog(AppendableSafe appendableSafe, Verbosity verbosity)
-
Method Summary
Add Indentation and Append Methods Modifier and Type Method AppendableSafeappendI12(String s)AppendableSafeappendI16(String s)AppendableSafeappendI4(String s)AppendableSafeappendI8(String s)Methods to Check Field hasLogandlevelModifier and Type Method booleanlevelEQ(int level)booleanlevelGTEQ(int level)Methods: interface java.lang.Appendable Modifier and Type Method AppendableSafeappend(char c)AppendableSafeappend(CharSequence csq)AppendableSafeappend(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 ofAppendableSafebecause the actual classjava.lang.Appendablehas methods all of which throwIOException. TheAppendableSafeclass 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 enumVerbosityfieldVerbosity.level.- Code:
- Exact Field Declaration Expression:
public final int 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 anAppendableSafeinstance, and configured to throwAppendableErrorrather thanIOExceptionwhen / if the internal method throws anyIOException's.- Parameters:
appendable- This may be any instance ofjava.lang.Appendable.verbosity- An instance of theVerbosityenum. 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 aNullPointerExceptionwill throw.
-
AppendableLog
public AppendableLog(AppendableSafe appendableSafe, Verbosity verbosity)
Construct an instance of this class. Since there are several ways to configure the internalAppendableSafeinstance, this constructor allows a user to simply pass an already built instance ofAppendableSafeas a parameter.- Parameters:
appendableSafe- This may be any instance ofAppendableSafe. The primary purpose of this class is to shunt theIOExceptionthat is thrown byjava.lang.Appendablemethods, and either suppress them, or re-wrap them into an unchecked-Throwable.
Being able to leave off thethrows IOExceptionwhen writing log code makes the process much easier.verbosity- An instance of theVerbosityenum. 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 aNullPointerExceptionwill 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:
appendin interfacejava.lang.Appendable- Parameters:
c- The character to append- Returns:
- A reference to this
Appendable. - Throws:
java.lang.NullPointerException- If theAppendableSafeinstance 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:
appendin 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 theAppendableSafeinstance 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:
appendin 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 theAppendableSafeinstance 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 theAppendableSafeinstance 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 theAppendableSafeinstance 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 theAppendableSafeinstance 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 theAppendableSafeinstance 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 ofVerbosityis that logging information is only printed to an output log if the user has requested a certain level of verbosity.
This method will returnTRUEif the user has requested logging, and this instance' internallevelfield is equal to parameter'level'.- Parameters:
level- An integer that should correspond to the enumVerbosityinternal fieldVerbosity.level.- Returns:
TRUEif -
ReturnsFALSEotherwise- 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 ofVerbosityis that logging information is only printed to an output log if the user has requested a certain level of verbosity.
This method will returnTRUEif the user has requested logging, and this instance' internallevelfield is greater than or equal to parameter'level'.- Parameters:
level- An integer that should correspond to the enumVerbosityinternal fieldVerbosity.level.- Returns:
TRUEif -
ReturnsFALSEotherwise- Code:
- Exact Method Body:
if (hasLog) return (this.level >= level); return false;
-
-