From 430809b9f1213c8c9e02c0e74510b4eabe925d14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yannick=20Mo=CC=88ller?= Date: Wed, 14 Aug 2024 17:20:42 +0200 Subject: [PATCH 1/2] adjust Value.ignore() to make ignoring of other types than String available Sometimes we have a JDBC Row where 0 value means "null" but ignoring does only work with strings until now. object.as(Row.class).getValue("value").ignore(BigDecimal.ZERO) should ignore a found 0 without calling Value.of(object.as(Row.class).getValue().asString().ignore("0") --- src/main/java/sirius/kernel/commons/Value.java | 4 ++-- src/test/kotlin/sirius/kernel/commons/ValueTest.kt | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/java/sirius/kernel/commons/Value.java b/src/main/java/sirius/kernel/commons/Value.java index 6b0f0c65..566ad277 100644 --- a/src/main/java/sirius/kernel/commons/Value.java +++ b/src/main/java/sirius/kernel/commons/Value.java @@ -234,11 +234,11 @@ public void ifPresent(@Nonnull Processor extractor, @Nonnull Callb * Otherwise, the current value is returned. */ @Nonnull - public Value ignore(@Nonnull String... ignoredValues) { + public Value ignore(@Nonnull Object... ignoredValues) { if (isEmptyString()) { return this; } - for (String val : ignoredValues) { + for (Object val : ignoredValues) { if (data.equals(val)) { return Value.EMPTY; } diff --git a/src/test/kotlin/sirius/kernel/commons/ValueTest.kt b/src/test/kotlin/sirius/kernel/commons/ValueTest.kt index 448b6085..d62d01b4 100644 --- a/src/test/kotlin/sirius/kernel/commons/ValueTest.kt +++ b/src/test/kotlin/sirius/kernel/commons/ValueTest.kt @@ -267,4 +267,15 @@ class ValueTest { assertEquals("x", Value.of("x").tryAppend(" ", null).asString()) assertEquals("x y", Value.of("x").tryAppend(" ", "y").asString()) } + + @Test + fun `Test ignore of objects`() { + assertTrue(Value.of("A").ignore("A", "B").isEmptyString) + assertTrue(Value.of("A").ignore("B", "C").isFilled) + assertTrue(Value.of("0").ignore("0").isEmptyString) + assertTrue(Value.of("0").ignore(BigDecimal.ZERO).isFilled) + assertTrue(Value.of("0").ignore("0").isEmptyString) + assertTrue(Value.of(BigDecimal.ZERO).ignore(BigDecimal.ZERO).isEmptyString) + assertTrue(Value.of(BigDecimal.valueOf(0)).ignore(BigDecimal.ZERO).isEmptyString) + } } From 432d9bccc731f587e34fdb01f79c2cc75bba0ba9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yannick=20Mo=CC=88ller?= Date: Wed, 14 Aug 2024 17:30:23 +0200 Subject: [PATCH 2/2] add some more inversed tests and adjust a doubled test --- src/test/kotlin/sirius/kernel/commons/ValueTest.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/test/kotlin/sirius/kernel/commons/ValueTest.kt b/src/test/kotlin/sirius/kernel/commons/ValueTest.kt index d62d01b4..1da28051 100644 --- a/src/test/kotlin/sirius/kernel/commons/ValueTest.kt +++ b/src/test/kotlin/sirius/kernel/commons/ValueTest.kt @@ -274,8 +274,11 @@ class ValueTest { assertTrue(Value.of("A").ignore("B", "C").isFilled) assertTrue(Value.of("0").ignore("0").isEmptyString) assertTrue(Value.of("0").ignore(BigDecimal.ZERO).isFilled) - assertTrue(Value.of("0").ignore("0").isEmptyString) + assertTrue(Value.of("1").ignore("0").isFilled) + assertTrue(Value.of(BigDecimal.ONE).ignore("1").isFilled) assertTrue(Value.of(BigDecimal.ZERO).ignore(BigDecimal.ZERO).isEmptyString) + assertTrue(Value.of(BigDecimal.ZERO).ignore("0").isFilled) assertTrue(Value.of(BigDecimal.valueOf(0)).ignore(BigDecimal.ZERO).isEmptyString) + assertTrue(Value.of(BigDecimal.valueOf(1)).ignore(BigDecimal.ZERO).isFilled) } }