diff --git a/pom.xml b/pom.xml
index 455256c..1039214 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
com.cognite.units
units-catalog
- 0.1.8
+ 0.1.9
${project.groupId}:${project.artifactId}
A comprehensive unit catalog for Cognite Data Fusion (CDF) with a focus on standardization, comprehensiveness, and consistency.
diff --git a/src/main/kotlin/com/cognite/units/UnitService.kt b/src/main/kotlin/com/cognite/units/UnitService.kt
index a433335..d6ec8eb 100644
--- a/src/main/kotlin/com/cognite/units/UnitService.kt
+++ b/src/main/kotlin/com/cognite/units/UnitService.kt
@@ -26,7 +26,10 @@ import kotlin.math.log10
import kotlin.math.pow
import kotlin.math.roundToLong
-class UnitService(unitsPath: URL, systemPath: URL) {
+class UnitService(units: String, systems: String) {
+
+ constructor(unitsPath: URL, systemPath: URL) : this(unitsPath.readText(), systemPath.readText())
+
companion object {
val service: UnitService by lazy {
UnitService(
@@ -42,8 +45,8 @@ class UnitService(unitsPath: URL, systemPath: URL) {
private val defaultUnitByQuantityAndSystem = mutableMapOf>()
init {
- loadUnits(unitsPath)
- loadSystem(systemPath)
+ loadUnits(units)
+ loadSystem(systems)
}
private fun sanitizeIdentifier(identifier: String): String {
@@ -102,8 +105,7 @@ class UnitService(unitsPath: URL, systemPath: URL) {
}
}
- private fun loadUnits(unitsPath: URL) {
- val units = unitsPath.readText()
+ private fun loadUnits(units: String) {
val mapper: ObjectMapper = jacksonObjectMapper()
// 1. Syntax Check: Every unit item in `units.json` must have the specified keys
@@ -144,8 +146,7 @@ class UnitService(unitsPath: URL, systemPath: URL) {
}
}
- private fun loadSystem(systemPath: URL) {
- val systems = systemPath.readText()
+ private fun loadSystem(systems: String) {
val mapper: ObjectMapper = jacksonObjectMapper()
val listOfSystems: List = mapper.readValue>(systems)
diff --git a/src/test/kotlin/UnitTest.kt b/src/test/kotlin/UnitTest.kt
index 2a17bed..1a3409b 100644
--- a/src/test/kotlin/UnitTest.kt
+++ b/src/test/kotlin/UnitTest.kt
@@ -32,6 +32,14 @@ class UnitTest {
UnitService.service
}
+ @Test
+ fun useStringConstructor() {
+ val units = UnitService::class.java.getResource("/units.json")!!.readText()
+ val systems = UnitService::class.java.getResource("/unitSystems.json")!!.readText()
+ val unitService = UnitService(units, systems)
+ unitService.getUnitByExternalId("temperature:deg_c")
+ }
+
@Test
fun convertBetweenUnits() {
val unitService = UnitService.service