Property

abstract class Property(val encoding: String)(source)

Abstraction for modeling type-safe properties of the ApiKey implementation.

Implementations should also model an "Unknown" value in the event new properties are added, such that older versions of the implementation remain functional.

e.g.

public abstract class MyProperty private constructor(
    encoding: String,
): ApiKey.Property(encoding) {

    public data object AUTHENTICATION: MyProperty("AUTHENTICATION")
    public class Something(public val count: Int): MyProperty("SOMETHING:$count")
    public class Unknown internal constructor(value: String): MyProperty(value)

    public companion object: Decoder() {

        @Throws(IllegalArgumentException::class)
        public override fun decode(value: String): MyProperty = when {
            value == AUTHENTICATION.encoding -> AUTHENTICATION
            value.startsWith("SOMETHING") -> Something(value.substringAfter(':').toInt())
            else -> Unknown(value)
        }
    }
}

Throws

IllegalArgumentException

when:

  • Implementing class is an anonymous object

  • encoding is blank

  • encoding is multiple lines

  • encoding contains invalid UTF-8 characters or sequences

Constructors

Link copied to clipboard
protected constructor(encoding: String)

Types

Link copied to clipboard
abstract class Decoder<P : ApiKey.Property>

An abstraction for transforming a property's encoding value to its Property type.

Properties

Link copied to clipboard
@JvmField
val encoding: String