java.lang.Object
org.tquadrat.foundation.lang.DebugOutput
@UtilityClass
@ClassVersion(sourceVersion="$Id: DebugOutput.java 1084 2024-01-03 15:31:20Z tquadrat $")
@API(status=STABLE,
since="0.1.0")
public final class DebugOutput
extends Object
Some functions for DEBUG and TEST output to the console.
- Author:
- Thomas Thrien (thomas.thrien@tquadrat.org)
- Version:
- $Id: DebugOutput.java 1084 2024-01-03 15:31:20Z tquadrat $
- Since:
- 0.1.0
- UML Diagram
-
UML Diagram for "org.tquadrat.foundation.lang.DebugOutput"
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic final Optional
<StackTraceElement> findCaller
(String methodName, Class<?> owningClass) This method will find the caller for the method that is identified by its name and class, and returns the appropriate stack trace element.static final void
If the System property "isDebug" is set and the given condition resolves totrue
, execute the givenFunction
and call the specifiedPrinter
to write the result.static final void
static final void
static final void
If the System property "isDebug" is set and the givencondition
resolves totrue
, execute the givenFunction
and call the specifiedPrinter
to write result.static final void
static final void
If the System property "isTest" is set and the given condition resolves totrue
, execute the givenSupplier
and call the specifiedPrinter
to write the result.static final void
static final void
static final void
If the System property "isTest" is set and the givencondition
resolves totrue
, execute the givenFunction
and call the specifiedPrinter
to write the result.static final void
If the System property "isTest" is set, execute the givenFunction
and call the specifiedPrinter
to write the result.static final boolean
isDebug()
Returns the DEBUG flag.static final boolean
isTest()
Returns the TEST flag.static final void
setPrinter
(Printer printer) Assigns thePrinter
for the DEBUG/TEST output.
-
Field Details
-
m_Printer
The printer. -
m_IsDebug
The DEBUG flag.- See Also:
-
m_IsTest
The TEST flag.- See Also:
-
-
Constructor Details
-
DebugOutput
private DebugOutput()No instance is allowed for this class!
-
-
Method Details
-
findCaller
@API(status=STABLE, since="0.1.0") public static final Optional<StackTraceElement> findCaller(String methodName, Class<?> owningClass) This method will find the caller for the method that is identified by its name and class, and returns the appropriate stack trace element.
The return value is empty when the provided method is not on the stack trace.
- Parameters:
methodName
- The name of the method that we need the caller for.owningClass
- The class for the called method.- Returns:
- An instance of
Optional
that holds the stack trace element for the caller.
-
ifDebug
- Parameters:
message
- The message; it is a format as defined forFormatter
.args
- Optional argument for thesupplier
.- See Also:
-
ifDebug
@API(status=STABLE, since="0.1.0") public static final void ifDebug(Function<Object[], String> supplier, Object... args) - Parameters:
supplier
- TheFunction
for the output.args
- Optional argument for thesupplier
.- See Also:
-
ifDebug
@API(status=STABLE, since="0.1.0") public static final void ifDebug(BooleanSupplier condition, Function<Object[], String> supplier, Object... args) If the System property "isDebug" is set and the givencondition
resolves totrue
, execute the givenFunction
and call the specifiedPrinter
to write result.- Parameters:
condition
- Only iftrue
, there will be an output.supplier
- TheSupplier
for the output.args
- Optional argument for thesupplier
.- See Also:
-
ifDebug
@API(status=STABLE, since="0.1.0") public static final void ifDebug(boolean condition, Function<Object[], String> supplier, Object... args) If the System property "isDebug" is set and the given condition resolves totrue
, execute the givenFunction
and call the specifiedPrinter
to write the result.- Parameters:
condition
- Only iftrue
, there will be an output.supplier
- TheSupplier
for the output.args
- Optional argument for thesupplier
.- See Also:
-
ifDebug
If the System property "isDebug" is set, a call to
e.printStackTrace()
is made.Use this to provide a view to an otherwise ignored exception.
- Parameters:
e
- The exception.- See Also:
-
ifTest
- Parameters:
message
- The message; it is a format as defined forFormatter
.args
- Optional argument for thesupplier
.- See Also:
-
ifTest
@API(status=STABLE, since="0.1.0") public static final void ifTest(Function<Object[], String> supplier, Object... args) If the System property "isTest" is set, execute the givenFunction
and call the specifiedPrinter
to write the result.- Parameters:
supplier
- TheSupplier
for the output.args
- Optional argument for thesupplier
.- See Also:
-
ifTest
@API(status=STABLE, since="0.1.0") public static final void ifTest(BooleanSupplier condition, Function<Object[], String> supplier, Object... args) If the System property "isTest" is set and the givencondition
resolves totrue
, execute the givenFunction
and call the specifiedPrinter
to write the result.- Parameters:
condition
- Only iftrue
, there will be an output.supplier
- TheSupplier
for the output.args
- Optional argument for thesupplier
.- See Also:
-
ifTest
@API(status=STABLE, since="0.1.0") public static final void ifTest(boolean condition, Function<Object[], String> supplier, Object... args) If the System property "isTest" is set and the given condition resolves totrue
, execute the givenSupplier
and call the specifiedPrinter
to write the result.- Parameters:
condition
- Only iftrue
, there will be an output.supplier
- TheSupplier
for the output.args
- Optional argument for thesupplier
.- See Also:
-
ifTest
If the System property "isTest" is set, a call to
e.printStackTrace()
is made.Use this to get a view to an otherwise ignored exception.
- Parameters:
e
- The exception.- See Also:
-
isDebug
Returns the DEBUG flag.- Returns:
true
if the DEBUG flag is set,false
otherwise.- See Also:
-
isTest
Returns the TEST flag.- Returns:
true
if the TEST flag is set,false
otherwise.- See Also:
-
setPrinter
Assigns the
Printer
for the DEBUG/TEST output.The default implementation writes to
System.out
.- Parameters:
printer
- The printer
-