persch.cc:​~/www (master *%)$ mdcat stardust.md

Stardust

Stardust is a software library containing a lot of powerful features that make the programmer’s life much easier. Stardust is my main project that I’ve been working on for many years. I’m developing the library with Kotlin as a multi-platform project with Java and JavaScript as target platforms.

Some interesting features of the Stardust library are described in the following sections.

String Building

String formatting was yesterday — with Kotlin’s type-safe builders, we have new capabilities to build things directly with Kotlin code, where we formally had to use a format string. The Stardust library provides type-safe builders to comfortably create strings especially for the localization of multilingual applications.

lrope {
    val count = items.size

    +"Your shopping cart "

    if(count > 0) {
        +"contains "

        if(count > 1)
            format(count, formats.numbers.fullFixed(0))
        else
            +"one"

        +" item"
        plural(count, "s")
    } else
        +"is empty"

    +"."
}

// If `items` would contain exactly one element, the result would be:
// Your shopping cart contains one item.

Collections

Stardust contains additional collections and provides useful features for manipulation and conversion of mutable and immutable collections.

val immutableList = immutableListOf(1, 2, 3, 4, 5)

val mutableList = immutableList.mutableCopy { add(6) }

mutableList.add(7)

println(mutableList) // [1, 2, 3, 4, 5, 6, 7]

Date and Time

Stardust provides date and time classes with comfortable handling.

val date = Dates.utcCurrent()
println(date) // e.g. 2020-10-19

val dateTime = DateTimes.utcNow()
println(dateTime) // e.g. 2020-10-19 18:42:12.191 UTC

val ts = dateTime.minus(date.toUtcDateTime())
println(ts) // e.g. 0.18:42:12.191

Event Handling

Kotlin doesn’t have a built-in event mechanism, but events are an important design pattern. Because of this, the Stardust library contains a thread-safe event mechanism.

// Subscribe an event
action.subscribe { _, arg -> println(arg.value) }

// Raise an event
actionSource.raise(this, EventArgument("Hello!"))

UUID Utilities

The UUID utilities enable the support for name based UUIDs of the versions 3 and 5 as well as the unofficial versions 6 and 7, supporting SHA-256 resp. SHA3-256.

// Create a UUID using SHA3-256 with a DNS specification
val uuid = nameUUID7(NameUUIDNamespace.DNS, "www.example.com")

println(uuid) // fc506eca-a1f4-7315-87c8-c71449dfd324

// Get the version information of the UUID
val info = uuid.versionInfo()

println("Version: ${info.version}, Variant: ${info.variant}")
// Output: Version: V7, Variant: IETF

Helper Classes

The Stardust library contains objects that define all available charsets, locales, and time zones.

val utf_8 = Charsets.utf_8

val en_US = Locales.en_US

val berlin = ZoneIds.europe_berlin

persch.cc:​~/www (master *%)$ mdcat footer.md

Copyright © Jan Martin Persch
All rights reserved.

Powered by the Thunderstruck website engine