Change logic of AttributesBuilder. It no longer exposes the constructor

This commit is contained in:
Alexander Nozik 2024-03-27 09:11:35 +03:00
parent 214467d21c
commit 3b74968f9a

View File

@ -14,8 +14,6 @@ public class AttributesBuilder<out O> internal constructor(
private val map: MutableMap<Attribute<*>, Any?>, private val map: MutableMap<Attribute<*>, Any?>,
) : Attributes { ) : Attributes {
public constructor() : this(mutableMapOf())
override fun toString(): String = "Attributes(value=${content.entries})" override fun toString(): String = "Attributes(value=${content.entries})"
override fun equals(other: Any?): Boolean = other is Attributes && Attributes.equals(this, other) override fun equals(other: Any?): Boolean = other is Attributes && Attributes.equals(this, other)
override fun hashCode(): Int = content.hashCode() override fun hashCode(): Int = content.hashCode()
@ -61,5 +59,9 @@ public class AttributesBuilder<out O> internal constructor(
public fun build(): Attributes = AttributesImpl(map) public fun build(): Attributes = AttributesImpl(map)
} }
public inline fun <O> Attributes(builder: AttributesBuilder<O>.() -> Unit): Attributes = /**
AttributesBuilder<O>().apply(builder).build() * Create [Attributes] with a given [builder]
* @param O the type for which attributes are built. The type is used only during compilation phase for static extension dispatch
*/
public fun <O> Attributes(builder: AttributesBuilder<O>.() -> Unit): Attributes =
AttributesBuilder<O>(mutableMapOf()).apply(builder).build()