commit 02/09/2025
This commit is contained in:
@@ -21,7 +21,8 @@ class Somecodes {
|
||||
val processor: CentralProcessor = si.hardware.processor
|
||||
val memory : GlobalMemory = si.hardware.memory
|
||||
val datetimeformat1: DateTimeFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss")
|
||||
|
||||
val dateformat1: DateTimeFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy")
|
||||
val timeformat1: DateTimeFormatter = DateTimeFormatter.ofPattern("hh:mm:ss")
|
||||
const val KB_threshold = 1024.0
|
||||
const val MB_threshold = KB_threshold * 1024.0
|
||||
const val GB_threshold = MB_threshold * 1024.0
|
||||
@@ -67,6 +68,10 @@ class Somecodes {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get CPU usage using OSHI library.
|
||||
* @param cb A callback function that receives the CPU usage as a string.
|
||||
*/
|
||||
fun getCPUUsage(cb : Consumer<String>){
|
||||
CoroutineScope(Dispatchers.Default).launch {
|
||||
val prev = processor.systemCpuLoadTicks
|
||||
@@ -106,16 +111,60 @@ class Somecodes {
|
||||
, (usedMemory.toDouble() / totalMemory * 100))
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a value is a valid non-blank string.
|
||||
* @param value The value to check.
|
||||
* @return True if the value is a non-blank string, false otherwise.
|
||||
*/
|
||||
fun ValidString(value: Any) : Boolean {
|
||||
return value is String && value.isNotBlank()
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a string is a valid file path and the file exists.
|
||||
* @param value The string to check.
|
||||
* @return True if the string is a valid file path, false otherwise.
|
||||
*/
|
||||
fun ValidFile(value : String) : Boolean {
|
||||
if (value.isNotBlank()){
|
||||
return Files.exists(Path.of(value))
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a string is a valid date in the format "dd/MM/yyyy".
|
||||
* @param value The string to check.
|
||||
* @return True if the string is a valid date, false otherwise.
|
||||
*/
|
||||
fun ValidDate(value: String): Boolean{
|
||||
return try{
|
||||
if (ValidString(value)){
|
||||
dateformat1.parse(value)
|
||||
true
|
||||
} else throw Exception()
|
||||
|
||||
} catch (_: Exception){
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a string is a valid time in the format "hh:mm:ss".
|
||||
* @param value The string to check.
|
||||
* @return True if the string is a valid time, false otherwise.
|
||||
*/
|
||||
fun ValidTime(value: String): Boolean{
|
||||
return try{
|
||||
if (ValidString(value)){
|
||||
timeformat1.parse(value)
|
||||
true
|
||||
} else throw Exception()
|
||||
|
||||
} catch (_: Exception){
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user