Class JK
It offers functionalities related to logging, configuration, resource handling, debugging, and more.
- Version:
- 1.0
- Author:
- Dr. Jalal H. Kiswani
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
Represents a separator used to separate values in CSV files.static JKLocale
Represents the default locale used for various operations in the application.static final String
Represents a separator used to separate fields in output.static final String
Represents a separator used in file paths for the current framework.static final String
Represents the line separator. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
addToSystemConfig
(String generalSystemPropertiesPrefix, JKConfig prop) This method adds properties from the providedJKConfig
instance to the system properties, with the given prefix.static void
addToSystemConfig
(String prefix, Properties prop) This method adds the key-value pairs from the providedProperties
object to the system properties with the specified prefix added to the keys.static String
buildToString
(Object... params) This method returns a formatted string that concatenates the provided parameters.static boolean
...static void
checkMe()
This method marks a section of code that needs review or checking.static void
close()
This method shuts down the executor service used for running asynchronous tasks.static void
close
(InputStream in) This method closes the provided input stream.static String
This method concatenates the string representations of the provided objects into a single string.static String
This method combines the provided strings into a single comma-separated value (CSV) string.static void
debug()
This method activates the debug mode for the application.static void
This method logs a formatted message with the provided format and values using the logger at the DEBUG level.static boolean
...static void
This method logs an error message and throws an IllegalStateException.static RuntimeException
This method creates and throws aJKException
with the provided message.static RuntimeException
This method creates and throws aJKException
with the provided message.static boolean
This method checks whether a file with the specified name exists.static <T> T
This method returns the first element from the given list.static void
fixMe()
This method marks a section of code that needs attention or fixing.static void
This method marks a section of code that needs attention or fixing, with a custom message.static String
get()
This method gets the version of the application.static String
This method retrieves the name of the application.static String
This method gets the build time of the application.static Class<?>
This method returns theClass
object for the given class name using the current thread's context class loader.static InputStream
getInputStream
(String fileName) This method retrieves an input stream for the specified file name.static String
This method gets the time stamp of class load time.This method retrieves the cache containing hash codes of messages that have been printed usingprintOnce(Object)
.static String
getProperty
(String name) This method gets the value of the system property associated with the specified name.static String
getProperty
(String name, String defaultValue) This method gets the value of the system property associated with the specified name.static Reader
This method retrieves a reader for the specified file.protected static Scanner
This method retrieves a scanner for reading input from the console.static int
This method gets the size of the provided collection.static URL
This method retrieves a URL object for the specified path.static Class<?>
getWrapperForPrimitive
(Class<?> clas) This method returns the wrapper class for a given primitive class.static void
This method handles the provided Throwable by logging the exception details and passing it to the exception handling mechanism.static void
This method throws anIllegalStateException
with a default message indicating that the method is not implemented yet.static void
implementMe
(String msg) This method throws anIllegalStateException
with the specified message, indicating that the method is not implemented yet.static void
init()
This method initializes the JK framework.protected static void
initInfo()
This method is responsible for initializing information related to build time and load time of the JK framework.static boolean
This method checks whether the application is in debug mode.static boolean
This method checks whether the JK Framework been initialized or not.static boolean
This method checks whether the application is configured as a multi-tenant application.static boolean
isPrimitive
(Class<?> type) This method checks whether the provided class is a primitive type.static boolean
This method checks if the application is currently in test context.static void
line()
This method prints a separator line consisting of dashes to the console.static void
This method logs a formatted message with the provided format and values using the logger at the INFO level.static void
This main method prints the application name to the console.static <T> T
newInstance
(Class<T> class1) This method creates a new instance of the specified class using its no-argument constructor.static <T> T
newInstance
(String className) This method creates a new instance of the specified class using its name.static <T> List<T>
newInstances
(Class<T> clas, int count) This method creates and returns a list of new instances of a specified class.static void
This method throws anIllegalStateException
with a message indicating that the method is not needed anymore.static void
This method checks whether the given object is not null.static void
This method prints multiple objects to the standard output.static void
This method prints the elements of a list along with a specified name.static void
This method prints the key-value pairs of a map along with a specified name.static void
This method prints the elements of a list.static void
This method prints the elements of a nested list with a specified prefix.static void
This method prints the key-value pairs from a map in a formatted manner.static void
printBlock
(Object... params) This method prints a block of text with a separator line above and below it.static void
This method prints a message only once, preventing duplicate printouts of the same message.static void
This method prints the stack trace of the current exception to the standard error stream.static int
This method generates a random integer within the range of 0 (inclusive) toInteger.MAX_VALUE
(exclusive).static int
randomNumber
(int min, int max) This method generates a random integer within the specified range.static char[]
readPassword
(String msg) This method reads a password input from the console.static String
readString
(String msg) This method reads a line of input from the console or scanner and returns it as a string.static void
restart()
This method is yet To Be Implemented (TBI).static void
This method executes the provided Runnable in a separate asynchronous thread.static void
setAppName
(String appName) This method sets the application name.static void
setDebugMode
(boolean debugMode) This method sets the debug mode for the application.static void
setDefaultLocale
(JKLocale locale) This method sets the default locale to the provided locale.static void
setMultiTenantApp
(boolean multiTenantApp) This method sets the application's multi-tenant configuration.static void
This method sets the application to be in test context.static void
sleep
(int millis) This method cause the current thread to sleep for the specified number of milliseconds.static void
testMe()
This method marks a section of code that needs testing or verification.static void
This method marks a section of code that needs testing or verification, with a custom message.static RuntimeException
This method throws a runtime exception while handling a throwable.static void
This method throws a runtime exception with a provided message and the given throwable as the cause.static int
This method converts an Object to an integer value.static <T> List<T>
toList
(T... objects) This method converts a variable number of objects into a list.This method converts an array of objects into a map, assuming that the array contains pairs of key-value entries.static Map
This method creates a map by pairing keys and values from arrays.static Set<?>
This method converts an array of objects into a set.static Class<?>
This method returns theClass
object for the given class name.static void
...
-
Field Details
-
NEW_LINE
Represents the line separator. -
FIELD_SEPARATOR
Represents a separator used to separate fields in output.- See Also:
-
CSV_SEPARATOR
Represents a separator used to separate values in CSV files.- See Also:
-
FILE_SEPRATOR
Represents a separator used in file paths for the current framework. -
DEFAULT_LOCALE
Represents the default locale used for various operations in the application.
-
-
Constructor Details
-
JK
public JK()
-
-
Method Details
-
debug
public static void debug()This method activates the debug mode for the application. -
error
This method logs an error message and throws an IllegalStateException.- Parameters:
format
- Specifies the error message format.params
- Specifies the parameters to format the message.
-
print
This method prints multiple objects to the standard output.- Parameters:
params
- Specifies the objects to print.
-
print
This method prints the key-value pairs from a map in a formatted manner.- Parameters:
prop
- Specifies the map containing key-value pairs to be printed.
-
print
This method prints the elements of a list along with a specified name.- Parameters:
name
- Specifies the name associated with the list.list
- Specifies the list of objects to be printed.
-
print
This method prints the key-value pairs of a map along with a specified name.- Parameters:
name
- Specifies the name associated with the map.map
- Specifies the map containing key-value pairs to be printed.
-
print
This method prints the elements of a list.- Parameters:
list
- Specifies the list of objects to be printed.
-
print
This method prints the elements of a nested list with a specified prefix.- Parameters:
finalList
- Specifies the list containing nested lists to be printed.prefix
- Specifies the prefix to be added before each element in the nested list.
-
buildToString
This method returns a formatted string that concatenates the provided parameters.- Parameters:
params
- Specifies the objects to concatenate.- Returns:
- a string containing the concatenation of the provided parameters.
-
concat
This method concatenates the string representations of the provided objects into a single string.- Parameters:
params
- Specifies the objects to be concatenated.- Returns:
- a concatenated string representation of the objects.
-
handle
This method handles the provided Throwable by logging the exception details and passing it to the exception handling mechanism.If in debug mode, the stack trace of the exception is also printed.
- Parameters:
t
- Specifies the Throwable to be handled.
-
line
public static void line()This method prints a separator line consisting of dashes to the console. -
printBlock
This method prints a block of text with a separator line above and below it.- Parameters:
params
- Specifies the objects to be printed in the block.
-
throww
This method throws a runtime exception while handling a throwable.- Parameters:
t
- Specifies the throwable to be wrapped in a runtime exception.- Returns:
- an instance of
RuntimeException
.
-
toMap
This method creates a map by pairing keys and values from arrays.- Parameters:
keys
- Specifies an array containing keys to be used in the map.values
- Specifies an array containing values to be associated with the keys.- Returns:
- a map containing key-value pairs derived from the input arrays.
-
main
This main method prints the application name to the console.- Parameters:
args
- the command-line arguments.
-
randomNumber
public static int randomNumber()This method generates a random integer within the range of 0 (inclusive) toInteger.MAX_VALUE
(exclusive).- Returns:
- a random integer.
-
randomNumber
public static int randomNumber(int min, int max) This method generates a random integer within the specified range.- Parameters:
min
- Specifies the minimum value (inclusive) of the range.max
- Specifies the maximum value (exclusive) of the range.- Returns:
- a random integer within the specified range.
-
getInputStream
This method retrieves an input stream for the specified file name.- Parameters:
fileName
- Specifies the name of the file for which to obtain an input stream.- Returns:
- the input stream for the specified file.
-
newInstance
This method creates a new instance of the specified class using its name.- Type Parameters:
T
- Specifies the type of the class to instantiate.- Parameters:
className
- Specifies the fully qualified name of the class to instantiate.- Returns:
- the new instance of the specified class.
-
setDefaultLocale
This method sets the default locale to the provided locale.- Parameters:
locale
- Specifies the new default locale.
-
restart
public static void restart()This method is yet To Be Implemented (TBI).The behavior, parameters, return value, and exceptions are subject to change in future implementations.
-
exception
This method creates and throws aJKException
with the provided message.- Parameters:
message
- Specifies the exception message.- Returns:
- this method always throws an exception, so it is unreachable
-
ex
This method creates and throws aJKException
with the provided message.- Parameters:
message
- Specifies the exception message.- Returns:
- this method always throws an exception, so it is unreachable
-
implementMe
public static void implementMe()This method throws anIllegalStateException
with a default message indicating that the method is not implemented yet.This method is used to mark functionality that should be implemented in the future.
-
notNeededAnyMore
public static void notNeededAnyMore()This method throws anIllegalStateException
with a message indicating that the method is not needed anymore.This method is used to mark functionality that was previously used but is no longer required.
-
printStackTrace
public static void printStackTrace()This method prints the stack trace of the current exception to the standard error stream.This method is used to print the stack trace of the current exception to aid in debugging.
-
notNull
This method checks whether the given object is not null.If the object is null, it throws an IllegalStateException with the message "This object cannot be null".
- Parameters:
object
- Specifies the object to be checked for null.
-
isDebugMode
public static boolean isDebugMode()This method checks whether the application is in debug mode.This is determined by the
debugMode
flag or whether the logger is in debug level.- Returns:
- true, if the application is in debug mode, false otherwise.
-
log
This method logs a formatted message with the provided format and values using the logger at the INFO level.- Parameters:
format
- Specifies the format string for the log message.values
- Specifies the values to be formatted into the message.
-
debug
This method logs a formatted message with the provided format and values using the logger at the DEBUG level.- Parameters:
format
- Specifies the format string for the log message.values
- Specifies the values to be formatted into the message.
-
csv
This method combines the provided strings into a single comma-separated value (CSV) string.- Parameters:
msgs
- Specifies the strings to be combined.- Returns:
- the CSV string containing the provided strings separated by commas.
-
addToSystemConfig
This method adds the key-value pairs from the providedProperties
object to the system properties with the specified prefix added to the keys.- Parameters:
prefix
- Specifies the prefix to be added to the keys when adding them to the system properties.prop
- Specifies theProperties
object containing the key-value pairs to be added.
-
readString
This method reads a line of input from the console or scanner and returns it as a string.- Parameters:
msg
- Specifies the message to be displayed as a prompt to the user.- Returns:
- the user's input as a string.
-
getScanner
This method retrieves a scanner for reading input from the console.- Returns:
- a scanner instance for reading input from the console.
-
readPassword
This method reads a password input from the console.- Parameters:
msg
- Specifies the message to display before input.- Returns:
- a character array representing the entered password.
-
printOnce
This method prints a message only once, preventing duplicate printouts of the same message.- Parameters:
msg
- Specifies the message to print.
-
getMessagesCache
This method retrieves the cache containing hash codes of messages that have been printed usingprintOnce(Object)
.- Returns:
- the cache containing hash codes of printed messages.
- See Also:
-
fixMe
public static void fixMe()This method marks a section of code that needs attention or fixing.This method is used to indicate areas of code that require further development or correction..
-
fixMe
This method marks a section of code that needs attention or fixing, with a custom message.This method is used to indicate areas of code that require further development or correction, along with providing a custom message for additional context.
- Parameters:
msg
- Specifies the custom message describing the issue that needs attention or fixing.
-
testMe
public static void testMe()This method marks a section of code that needs testing or verification.This method is used to indicate areas of code that require testing or verification.
It logs a message indicating that the code segment should be tested.
-
testMe
This method marks a section of code that needs testing or verification, with a custom message.This method is used to indicate areas of code that require testing or verification, along with providing a custom message for additional context.
- Parameters:
message
- Specifies the custom message describing the area of code that needs testing or verification.
-
checkMe
public static void checkMe()This method marks a section of code that needs review or checking.This method is used to indicate areas of code that require manual review or checking.
It logs a message indicating that the code segment should be reviewed.
-
getReader
This method retrieves a reader for the specified file.- Parameters:
fileName
- Specifies the name of the file to be read.- Returns:
- the
Reader
for reading the contents of the specified file.
-
getURL
This method retrieves a URL object for the specified path.- Parameters:
path
- Specifies the path to the resource.- Returns:
- a URL object representing the specified resource path.
-
exists
This method checks whether a file with the specified name exists.- Parameters:
fileName
- Specifies the name of the file to check.- Returns:
- true, if the file exists, false otherwise.
-
getAppName
This method retrieves the name of the application.- Returns:
- the name of the application as defined in configuration or based on the main class name.
-
throww
This method throws a runtime exception with a provided message and the given throwable as the cause.- Parameters:
e
- Specifies the throwable to be used as the cause of the exception.msg
- Specifies the message to be included in the exception.
-
close
This method closes the provided input stream.- Parameters:
in
- Specifies the input stream to be closed.
-
sleep
public static void sleep(int millis) This method cause the current thread to sleep for the specified number of milliseconds.- Parameters:
millis
- Specifies the number of milliseconds to sleep.
-
implementMe
This method throws anIllegalStateException
with the specified message, indicating that the method is not implemented yet.- Parameters:
msg
- Specifies the message indicating that the method is not implemented.
-
getWrapperForPrimitive
This method returns the wrapper class for a given primitive class.- Parameters:
clas
- Specifies the primitive class for which to retrieve the wrapper class.- Returns:
- the corresponding wrapper class for the given primitive class, or
null
if the input class is not a primitive.
-
isPrimitive
This method checks whether the provided class is a primitive type.- Parameters:
type
- Specifies the class to check for being a primitive type.- Returns:
- true, if the provided class is a primitive type, false otherwise.
-
type
This method returns theClass
object for the given class name.- Parameters:
clasName
- Specifies the fully qualified name of the class.- Returns:
- the class object for the specified class name or
null
if the class is not found.
-
getClass
This method returns theClass
object for the given class name using the current thread's context class loader.- Parameters:
className
- the class name- Returns:
- the class
-
newInstance
This method creates a new instance of the specified class using its no-argument constructor.- Type Parameters:
T
- Specifies the type of the class.- Parameters:
class1
- Specifies the class to create an instance of.- Returns:
- a new instance of the specified class, or
null
if an exception occurs.
-
isTestContext
public static boolean isTestContext()This method checks if the application is currently in test context.- Returns:
- true, if the application is in test context, false otherwise.
-
setTestContext
public static void setTestContext()This method sets the application to be in test context.Note: this may have security issues and should be used with caution.
-
addToSystemConfig
This method adds properties from the providedJKConfig
instance to the system properties, with the given prefix.- Parameters:
generalSystemPropertiesPrefix
- Specifies the prefix to be added to the property names when added to the system properties.prop
- Specifies theJKConfig
instance containing the properties to be added to the system properties.
-
toMap
This method converts an array of objects into a map, assuming that the array contains pairs of key-value entries.- Parameters:
list
- Specifies the array of objects where elements at even indices are keys and elements at odd indices are values.- Returns:
- the map containing the key-value pairs extracted from the input array.
-
toList
This method converts a variable number of objects into a list.- Type Parameters:
T
- Specifies the type of objects in the list.- Parameters:
objects
- Specifies the objects to be converted into a list.- Returns:
- the list containing the provided objects.
-
isMultiTenantApp
public static boolean isMultiTenantApp()This method checks whether the application is configured as a multi-tenant application.- Returns:
- true, if the application is configured as a multi-tenant application, false otherwise.
-
setMultiTenantApp
public static void setMultiTenantApp(boolean multiTenantApp) This method sets the application's multi-tenant configuration.- Parameters:
multiTenantApp
- Indicates whether to configure the application as a multi-tenant or not.
-
setAppName
This method sets the application name.- Parameters:
appName
- Specifies the name to set as the application's name.
-
setDebugMode
public static void setDebugMode(boolean debugMode) This method sets the debug mode for the application.- Parameters:
debugMode
- Indicates whether to enable or disable the debug mode.
-
toSet
This method converts an array of objects into a set.- Parameters:
obj
- Specifies the array of objects to be converted to a set.- Returns:
- the set containing the elements from the input array.
-
init
public static void init()This method initializes the JK framework.This method initializes various aspects of the JK framework, such as setting system properties, configuring logging, validating licenses, and more.
It should be called only once to ensure proper initialization of the framework.
-
initInfo
protected static void initInfo()This method is responsible for initializing information related to build time and load time of the JK framework.It sets the build time, build version, and load time information based on available build properties.
If the build properties file is not found, it logs a message indicating that the file is missing.
-
newInstances
This method creates and returns a list of new instances of a specified class.- Type Parameters:
T
- Specifies the type of objects to create instances of.- Parameters:
clas
- Specifies the class of objects to create instances of.count
- Specifies the number of instances to create.- Returns:
- a list containing the newly created instances.
-
first
This method returns the first element from the given list.- Type Parameters:
T
- Specifies the type of elements in the list.- Parameters:
list
- Specifies the list from which to retrieve the first element.- Returns:
- the first element in the list, or null if the list is empty.
-
getProperty
This method gets the value of the system property associated with the specified name.- Parameters:
name
- Specifies the name of the system property.- Returns:
- the string value of the system property, or null if the property doesn't exist.
-
getProperty
This method gets the value of the system property associated with the specified name.If the property is not found, returns the specified default value.
- Parameters:
name
- Specifies the name of the system property.defaultValue
- Specifies the default value to return if the property doesn't exist.- Returns:
- the string value of the system property, or the default value if the property doesn't exist.
-
getBuildTime
This method gets the build time of the application.- Returns:
- the build time of the application.
-
get
This method gets the version of the application.- Returns:
- the version of the application
-
getLoadTime
This method gets the time stamp of class load time.- Returns:
- the time stamp of class load time.
-
runAsync
This method executes the provided Runnable in a separate asynchronous thread.The runnable may execute in a new thread, in a pooled thread, or in the calling thread, at the discretion of the Executor implementation.
- Parameters:
runnable
- Specifies the runnable instance to execute.
-
toInt
This method converts an Object to an integer value.- Parameters:
obj
- Specifies the Object to convert to an integer.- Returns:
- the integer value of the Object.
-
getSize
This method gets the size of the provided collection.- Parameters:
c
- Specifies the collection to get size of.- Returns:
- the size of the collection, or
0
if itsnull
or empty.
-
close
public static void close()This method shuts down the executor service used for running asynchronous tasks.It is recommended to call this method before the application exits to ensure proper cleanup of resources.
-
isInitizlied
public static boolean isInitizlied()This method checks whether the JK Framework been initialized or not.- Returns:
- true, if the framework has been initialized, false otherwise.
-
e
...- Parameters:
f
- ...- Returns:
- ...
-
c
...- Parameters:
f
- ...t
- ...- Returns:
- ...
-
v
...- Parameters:
f
- ...p
- ...
-