1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package com.example.app
/**
* A generic stack implementation.
*/
class Stack<T> {
private val items = mutableListOf<T>()
fun push(item: T) {
items.add(item)
}
fun pop(): T? = items.removeLastOrNull()
fun peek(): T? = items.lastOrNull()
val size: Int get() = items.size
}
/**
* Configuration for the application.
*/
interface Config {
fun get(key: String): String?
fun getOrDefault(key: String, default: String): String
}
enum class LogLevel {
DEBUG,
INFO,
WARN,
ERROR
}
/**
* Simple logger with configurable level.
*/
class Logger(private val level: LogLevel = LogLevel.INFO) {
fun log(msg: String, msgLevel: LogLevel = LogLevel.INFO) {
if (msgLevel.ordinal >= level.ordinal) {
println("[${msgLevel.name}] $msg")
}
}
}
fun formatDuration(seconds: Long): String {
val hours = seconds / 3600
val minutes = (seconds % 3600) / 60
val secs = seconds % 60
return "${hours}h ${minutes}m ${secs}s"
}