Skip to content

Commit

Permalink
Merge pull request #534 from scireum/feature/ymo/ignore
Browse files Browse the repository at this point in the history
adjust Value.ignore() to make ignoring of other types than String available
  • Loading branch information
ymo-sci authored Aug 15, 2024
2 parents f187eae + 432d9bc commit 4e95c29
Show file tree
Hide file tree
Showing 2 changed files with 16 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
14 changes: 14 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,18 @@ 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("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)
}
}

0 comments on commit 4e95c29

Please sign in to comment.