Skip to content

Commit

Permalink
adjust Value.ignore() to make ignoring of other types than String ava…
Browse files Browse the repository at this point in the history
…ilable

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")
  • Loading branch information
ymo-sci committed Aug 14, 2024
1 parent f187eae commit 430809b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/main/java/sirius/kernel/commons/Value.java
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,11 @@ public <T> void ifPresent(@Nonnull Processor<Value, T> 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;
}
Expand Down
11 changes: 11 additions & 0 deletions src/test/kotlin/sirius/kernel/commons/ValueTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit 430809b

Please sign in to comment.