From 6cf5a2bead75b8ecddbbd8f0290f1e8584697db2 Mon Sep 17 00:00:00 2001 From: David Denton Date: Thu, 4 Jan 2024 21:53:55 +0000 Subject: [PATCH] renames --- ...ksonDataContainer.kt => JsonNodeDataContainer.kt} | 12 ++++++------ ...ContainerTest.kt => JsonNodeDataContainerTest.kt} | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) rename data4k/src/main/kotlin/dev/forkhandles/data/{JacksonDataContainer.kt => JsonNodeDataContainer.kt} (86%) rename data4k/src/test/kotlin/dev/forkhandles/lens/{JacksonDataContainerTest.kt => JsonNodeDataContainerTest.kt} (84%) diff --git a/data4k/src/main/kotlin/dev/forkhandles/data/JacksonDataContainer.kt b/data4k/src/main/kotlin/dev/forkhandles/data/JsonNodeDataContainer.kt similarity index 86% rename from data4k/src/main/kotlin/dev/forkhandles/data/JacksonDataContainer.kt rename to data4k/src/main/kotlin/dev/forkhandles/data/JsonNodeDataContainer.kt index cf5c12a..d87c53f 100644 --- a/data4k/src/main/kotlin/dev/forkhandles/data/JacksonDataContainer.kt +++ b/data4k/src/main/kotlin/dev/forkhandles/data/JsonNodeDataContainer.kt @@ -19,15 +19,14 @@ import java.math.BigDecimal /** * Jackson JsonNode-based implementation of the DataContainer */ -abstract class JacksonDataContainer(input: JsonNode) : +abstract class JsonNodeDataContainer(input: JsonNode) : DataContainer( input, { content, it -> content.has(it) }, { content, it -> content[it]?.let(Companion::nodeToValue) }, { node: JsonNode, name, value -> - (node as? ObjectNode)?.also { - node.set(name, value.toNode()) - } ?: error("Invalid node type ${input::class.java}") + (node as? ObjectNode)?.also { node.set(name, value.toNode()) } + ?: error("Invalid node type ${input::class.java}") } ) { @@ -58,9 +57,10 @@ abstract class JacksonDataContainer(input: JsonNode) : is BigDecimal -> DecimalNode(this) is Double -> DoubleNode(this) is String -> TextNode(this) - is Iterable<*> -> ArrayNode(instance).also { - map { if (it is JsonNode) it else it.toNode() }.forEach(it::add) + is Iterable<*> -> ArrayNode(instance) + .also { map { if (it is JsonNode) it else it.toNode() }.forEach(it::add) } + else -> error("Cannot set value of type ${this::class.java}") } } diff --git a/data4k/src/test/kotlin/dev/forkhandles/lens/JacksonDataContainerTest.kt b/data4k/src/test/kotlin/dev/forkhandles/lens/JsonNodeDataContainerTest.kt similarity index 84% rename from data4k/src/test/kotlin/dev/forkhandles/lens/JacksonDataContainerTest.kt rename to data4k/src/test/kotlin/dev/forkhandles/lens/JsonNodeDataContainerTest.kt index bd8c81d..7275042 100644 --- a/data4k/src/test/kotlin/dev/forkhandles/lens/JacksonDataContainerTest.kt +++ b/data4k/src/test/kotlin/dev/forkhandles/lens/JsonNodeDataContainerTest.kt @@ -2,17 +2,17 @@ package dev.forkhandles.lens import com.fasterxml.jackson.databind.JsonNode import com.fasterxml.jackson.databind.ObjectMapper -import dev.forkhandles.data.JacksonDataContainer +import dev.forkhandles.data.JsonNodeDataContainer import java.math.BigDecimal -class JacksonDataContainerTest : DataContainerContract() { +class JsonNodeDataContainerTest : DataContainerContract() { - class SubNodeBacked(node: JsonNode) : JacksonDataContainer(node), SubClassFields { + class SubNodeBacked(node: JsonNode) : JsonNodeDataContainer(node), SubClassFields { override var string by required() override var noSuch by required() } - class NodeBacked(node: JsonNode) : JacksonDataContainer(node), MainClassFields { + class NodeBacked(node: JsonNode) : JsonNodeDataContainer(node), MainClassFields { override var string by required() override var boolean by required() override var int by required()