Package-level declarations

JVM information and other useful utilities. Includes basic program settings support at the api/core/com.hexagonkt.core/-jvm object (like loading and retrieving system settings).

Types

Link copied to clipboard
object ClasspathHandler : URLStreamHandler
Link copied to clipboard
class CodedException(val code: Int, message: String = "", cause: Throwable? = null) : RuntimeException

Exception with a numeric code.

Link copied to clipboard
object Jvm

Object with utilities to gather information about the running JVM.

Link copied to clipboard
abstract class MapResourceBundle(val map: Map<*, *>) : ListResourceBundle
Link copied to clipboard
class MultipleException(val causes: List<Throwable>, message: String = "") : RuntimeException

Exception with a list of causes. Cause is null as it can't be told which one of the list is the cause.

Link copied to clipboard
enum OsKind : Enum<OsKind>
Link copied to clipboard
class ResourceNotFoundException(message: String) : IOException

Properties

Link copied to clipboard
val ALL_INTERFACES: InetAddress

Internet address used to bind services to all local network interfaces.

Link copied to clipboard
val assertEnabled: Boolean

This flag is true when assertions are enabled in the JVM (-ea flag). Assertions are disabled by default in the JVM, but they are enabled (and should be that way) on the tests.

Link copied to clipboard
val countryCodes: Set<String>

Set of allowed country codes in this JVM.

Link copied to clipboard
val currencyCodes: Set<String>

Set of allowed currency codes in this JVM.

Link copied to clipboard
val fail: Nothing

Syntax sugar to throw errors.

Link copied to clipboard
val GMT_ZONE: ZoneId

GMT zone ID.

Link copied to clipboard
val languageCodes: Set<String>

Set of allowed language codes in this JVM.

Link copied to clipboard
val LOOPBACK_INTERFACE: InetAddress

Internet address used to bind services to the loop-back interface.

Functions

Link copied to clipboard
fun UUID.bytes(): ByteArray
Link copied to clipboard
fun check(message: String, vararg blocks: () -> Unit)

Execute a list of code block collecting the exceptions they may throw, in case there is any error, it throws a MultipleException with all the thrown exceptions.

Link copied to clipboard
fun <Z> Collection<Z>.checkSize(count: IntRange): Collection<Z>

Ensure a collection has a fixed number of elements.

Link copied to clipboard
fun countryOf(country: String): Locale
Link copied to clipboard
fun countryOfOrNull(country: String): Locale?
Link copied to clipboard
fun String.exec(workingDirectory: File = File(System.getProperty("user.dir")), timeout: Long = Long.MAX_VALUE, fail: Boolean = false): String

TODO Add use case and example in documentation. TODO Support multiple words parameters by processing " and '

fun List<String>.exec(workingDirectory: File = File(System.getProperty("user.dir")), timeout: Long = Long.MAX_VALUE, fail: Boolean = true): String
Link copied to clipboard
fun URL.exists(): Boolean
Link copied to clipboard
fun <T : Any> fieldsMapOf(vararg fields: Pair<KProperty1<T, *>, *>): Map<String, *>
Link copied to clipboard
fun <T : Any> fieldsMapOfNotNull(vararg fields: Pair<KProperty1<T, *>, *>): Map<String, *>
Link copied to clipboard
fun <V> Collection<V?>.filterNotEmpty(): Collection<V>
fun <K, V> Map<K, V?>.filterNotEmpty(): Map<K, V>
Link copied to clipboard
fun Collection<*>.filterNotEmptyRecursive(): Collection<*>
fun Map<*, *>.filterNotEmptyRecursive(): Map<*, *>
Link copied to clipboard
fun Throwable.filterStackTrace(prefix: String): Array<out StackTraceElement>

Return the stack trace array of the frames that starts with the given prefix.

Link copied to clipboard
fun URL.firstVariant(vararg suffixes: String): URL
Link copied to clipboard
fun freePort(): Int

Return a random free port (not used by any other local process).

Link copied to clipboard
inline operator fun <T : Any> Map<*, *>.get(key: KProperty1<*, *>): T?
Link copied to clipboard
fun Map<*, *>.getBoolean(key: KProperty1<*, *>): Boolean?
Link copied to clipboard
fun Map<*, *>.getBooleans(key: KProperty1<*, *>): Collection<Boolean>?
Link copied to clipboard
fun Map<*, *>.getBooleansOrEmpty(key: KProperty1<*, *>): Collection<Boolean>
Link copied to clipboard
fun Map<*, *>.getDouble(key: KProperty1<*, *>): Double?
Link copied to clipboard
fun Map<*, *>.getDoubles(key: KProperty1<*, *>): Collection<Double>?
Link copied to clipboard
fun Map<*, *>.getDoublesOrEmpty(key: KProperty1<*, *>): Collection<Double>
Link copied to clipboard
fun Map<*, *>.getFloat(key: KProperty1<*, *>): Float?
Link copied to clipboard
fun Map<*, *>.getFloats(key: KProperty1<*, *>): Collection<Float>?
Link copied to clipboard
fun Map<*, *>.getFloatsOrEmpty(key: KProperty1<*, *>): Collection<Float>
Link copied to clipboard
fun Map<*, *>.getInt(key: KProperty1<*, *>): Int?
Link copied to clipboard
fun Map<*, *>.getInts(key: KProperty1<*, *>): Collection<Int>?
Link copied to clipboard
fun Map<*, *>.getIntsOrEmpty(key: KProperty1<*, *>): Collection<Int>
Link copied to clipboard
fun Map<*, *>.getList(key: KProperty1<*, *>): Collection<*>?
Link copied to clipboard
fun Map<*, *>.getListOrEmpty(key: KProperty1<*, *>): Collection<*>
Link copied to clipboard
fun Map<*, *>.getLists(key: KProperty1<*, *>): Collection<List<*>>?
Link copied to clipboard
fun Map<*, *>.getListsOrEmpty(key: KProperty1<*, *>): Collection<Collection<*>>
Link copied to clipboard
fun Map<*, *>.getLong(key: KProperty1<*, *>): Long?
Link copied to clipboard
fun Map<*, *>.getLongs(key: KProperty1<*, *>): Collection<Long>?
Link copied to clipboard
fun Map<*, *>.getLongsOrEmpty(key: KProperty1<*, *>): Collection<Long>
Link copied to clipboard
fun Map<*, *>.getMap(key: KProperty1<*, *>): Map<String, *>?
Link copied to clipboard
fun Map<*, *>.getMapOrEmpty(key: KProperty1<*, *>): Map<String, *>
Link copied to clipboard
fun Map<*, *>.getMaps(key: KProperty1<*, *>): Collection<Map<String, *>>?
Link copied to clipboard
fun Map<*, *>.getMapsOrEmpty(key: KProperty1<*, *>): Collection<Map<String, *>>
Link copied to clipboard
inline fun <T : Any> Map<*, *>.getOrDefault(key: KProperty1<*, *>, default: T): T
Link copied to clipboard
inline fun <T : Any> Map<*, *>.getPath(vararg keys: Any): T?
Link copied to clipboard
fun Map<*, *>.getString(key: KProperty1<*, *>): String?
Link copied to clipboard
fun Map<*, *>.getStrings(key: KProperty1<*, *>): Collection<String>?
Link copied to clipboard
fun Map<*, *>.getStringsOrEmpty(key: KProperty1<*, *>): Collection<String>
Link copied to clipboard
fun inetAddress(vararg bytes: Byte): InetAddress

Syntactic sugar to create an Internet address.

Link copied to clipboard
fun isPortOpened(port: Int): Boolean

Check if a port is already opened.

Link copied to clipboard
fun languageOf(language: String): Locale
Link copied to clipboard
fun languageOfOrNull(language: String): Locale?
Link copied to clipboard
fun localeOf(language: String = "", country: String = ""): Locale
Link copied to clipboard
fun localeOfOrNull(language: String = "", country: String = ""): Locale?
Link copied to clipboard
fun URL.localized(locale: Locale): URL
Link copied to clipboard
fun <K : Any> mapOfNotNull(vararg pairs: Pair<K, *>): Map<K, *>
Link copied to clipboard
fun merge(maps: Collection<Map<*, *>>): Map<*, *>
fun merge(mapA: Map<*, *>, mapB: Map<*, *>): Map<*, *>
Link copied to clipboard
fun <V> notEmpty(value: V?): Boolean
Link copied to clipboard
fun <K, V> Map<K, Collection<V>>.pairs(): Collection<Pair<K, V>>
Link copied to clipboard
fun parseDuration(text: String): Duration

Parse a time duration allowing a more relaxed format: with spaces or commas, lowercase characters and not forcing the text to start with 'P', however, the 'T' is still mandatory to separate date and time durations.

Link copied to clipboard
fun parseLocalDate(text: String): LocalDate

Parse a local date allowing only to specify the year or the year and the month. Missing month and day will be defaulted to january and one respectively.

Link copied to clipboard
fun parseLocale(languageCountry: String): Locale
Link copied to clipboard
fun parseLocaleOrNull(languageCountry: String): Locale?
Link copied to clipboard
fun parsePeriod(text: String): Period

Parse a time period allowing a more relaxed format: with spaces or commas, lowercase characters and not forcing the text to start with 'P'.

Link copied to clipboard
fun properties(url: URL): Map<String, String>

Load a '*.properties' file from a URL transforming the content into a plain map. If the resource can not be found, a com.hexagonkt.core.ResourceNotFoundException is thrown.

Link copied to clipboard
fun <K, V> Map<K, V>.require(name: K): V
Link copied to clipboard
fun Map<*, *>.requireBoolean(key: KProperty1<*, *>): Boolean
Link copied to clipboard
fun Map<*, *>.requireBooleans(key: KProperty1<*, *>): Collection<Boolean>
Link copied to clipboard
fun Map<*, *>.requireDouble(key: KProperty1<*, *>): Double
Link copied to clipboard
fun Map<*, *>.requireDoubles(key: KProperty1<*, *>): Collection<Double>
Link copied to clipboard
fun Map<*, *>.requireFloat(key: KProperty1<*, *>): Float
Link copied to clipboard
fun Map<*, *>.requireFloats(key: KProperty1<*, *>): Collection<Float>
Link copied to clipboard
fun <T : Any, N> T.requireGreater(field: KProperty1<T, Comparable<N>?>, min: N)
fun <T : Any, N> T.requireGreater(field: KProperty1<T, Comparable<N>?>, field2: KProperty1<T, N?>)
Link copied to clipboard
fun <T : Any, N> T.requireGreaterOrEquals(field: KProperty1<T, Comparable<N>?>, min: N)
fun <T : Any, N> T.requireGreaterOrEquals(field: KProperty1<T, Comparable<N>?>, field2: KProperty1<T, N?>)
Link copied to clipboard
fun Map<*, *>.requireInt(key: KProperty1<*, *>): Int
Link copied to clipboard
fun Map<*, *>.requireInts(key: KProperty1<*, *>): List<Int>
Link copied to clipboard
inline fun <T : Any> Map<*, *>.requireKey(key: KProperty1<*, *>): T
Link copied to clipboard
fun Map<*, *>.requireList(key: KProperty1<*, *>): Collection<*>
Link copied to clipboard
fun Map<*, *>.requireLists(key: KProperty1<*, *>): Collection<Collection<*>>
Link copied to clipboard
fun Map<*, *>.requireLong(key: KProperty1<*, *>): Long
Link copied to clipboard
fun Map<*, *>.requireLongs(key: KProperty1<*, *>): Collection<Long>
Link copied to clipboard
fun <T : Any, N> T.requireLower(field: KProperty1<T, Comparable<N>?>, min: N)
fun <T : Any, N> T.requireLower(field: KProperty1<T, Comparable<N>?>, field2: KProperty1<T, N?>)
Link copied to clipboard
fun <T : Any, N> T.requireLowerOrEquals(field: KProperty1<T, Comparable<N>?>, min: N)
fun <T : Any, N> T.requireLowerOrEquals(field: KProperty1<T, Comparable<N>?>, field2: KProperty1<T, N?>)
Link copied to clipboard
fun Map<*, *>.requireMap(key: KProperty1<*, *>): Map<String, *>
Link copied to clipboard
fun Map<*, *>.requireMaps(key: KProperty1<*, *>): Collection<Map<String, *>>
Link copied to clipboard
fun <T : Any> T.requireNotBlank(field: KProperty1<T, CharSequence?>)
Link copied to clipboard
fun <T : Any> T.requireNotBlanks(field: KProperty1<T, Collection<CharSequence>?>)
Link copied to clipboard
inline fun <T : Any> Map<*, *>.requirePath(vararg name: Any): T
Link copied to clipboard
fun Map<*, *>.requireString(key: KProperty1<*, *>): String
Link copied to clipboard
fun Map<*, *>.requireStrings(key: KProperty1<*, *>): Collection<String>
Link copied to clipboard
inline fun <T : ResourceBundle> resourceBundle(locale: Locale = Locale.getDefault()): ResourceBundle
fun <T : ResourceBundle> resourceBundle(type: KClass<T>, locale: Locale = Locale.getDefault()): ResourceBundle
Link copied to clipboard
fun URL.responseCode(): Int
Link copied to clipboard
fun URL.responseFound(): Boolean
Link copied to clipboard
fun URL.responseSuccessful(): Boolean
Link copied to clipboard
fun <T> retry(times: Int, delay: Long, block: () -> T): T

Execute a lambda until no exception is thrown or a number of times is reached.

Link copied to clipboard
fun String.shell(workingDirectory: File = File(System.getProperty("user.dir")), timeout: Long = Long.MAX_VALUE, fail: Boolean = false): String

Executes a command in a shell (allowing to use pipes, redirections, etc.).

Link copied to clipboard
fun UUID.toBase64(): String
Link copied to clipboard
fun LocalDate.toDate(): Date

Convert a local date to a date.

fun LocalDateTime.toDate(): Date

Convert a local date time to a date.

fun ZonedDateTime.toDate(): Date

Convert a zoned date time to a date.

Link copied to clipboard
fun Date.toLocalDate(): LocalDate

Convert a date to a local date.

fun Int.toLocalDate(): LocalDate

Parse a date from a formatted integer with this format: YYYYMMDD.

Link copied to clipboard
fun Date.toLocalDateTime(): LocalDateTime

Convert a date to a local date time.

fun Long.toLocalDateTime(): LocalDateTime

Parse a date time from a formatted number with this format: YYYYMMDDHHmmss.

Link copied to clipboard
fun Int.toLocalTime(): LocalTime

Parse a time from a formatted integer with this format: HHmmssSSS.

Link copied to clipboard
fun LocalDate.toNumber(): Int

Convert a date to an integer with the following format: YYYYMMDD.

fun LocalDateTime.toNumber(): Long

Convert a date time to a number with the following format: YYYYMMDDHHmmss.

fun LocalTime.toNumber(): Int

Convert a time to an integer with the following format: HHmmssSSS.

Link copied to clipboard
fun Throwable.toText(prefix: String = ""): String

Return this throwable as a text.

Link copied to clipboard
fun Period.toTotalDays(): Double

Calculate the aproximate number of days comprised in a time period.

Link copied to clipboard
fun urlOf(url: String): URL
Link copied to clipboard
fun uuid(bytes: ByteArray): UUID
fun uuid(text: String): UUID
Link copied to clipboard
fun LocalDateTime.withZone(zoneId: ZoneId = Jvm.timeZone.toZoneId()): ZonedDateTime

Return the date time in a given time zone for a local date time.