diff --git a/src/main/java/net/kemitix/conditional/Condition.java b/src/main/java/net/kemitix/conditional/Condition.java index c8c2e9c..6213b62 100644 --- a/src/main/java/net/kemitix/conditional/Condition.java +++ b/src/main/java/net/kemitix/conditional/Condition.java @@ -29,7 +29,7 @@ package net.kemitix.conditional; public interface Condition { /** - * Create a new {@code Condition}. + * Create a new {@code Condition} for the clause. * * @param clause the condition to test * @@ -42,6 +42,17 @@ public interface Condition { return new FalseCondition(); } + /** + * Create a new {@code Condition} for the boolean opposite of the clause. + * + * @param clause the condition to test + * + * @return the Condition + */ + static Condition whereNot(boolean clause) { + return where(!clause); + } + /** * Logically AND combine the current {@code Condition} with the clause. * @@ -51,6 +62,17 @@ public interface Condition { */ Condition and(boolean clause); + /** + * Logically AND combine the current {@code Condition} with boolean opposite of the clause. + * + * @param clause the condition to test + * + * @return the Condition + */ + default Condition andNot(boolean clause) { + return and(!clause); + } + /** * Logically OR combine the current {@code Condition} with the clause. * @@ -60,6 +82,17 @@ public interface Condition { */ Condition or(boolean clause); + /** + * Logically OR combine the current {@code Condition} with the boolean opposite of the clause. + * + * @param clause the condition to test + * + * @return the Condition + */ + default Condition orNot(boolean clause) { + return or(!clause); + } + /** * Perform this response if the {@code Condition} is {@code true}. * diff --git a/src/test/java/net/kemitix/conditional/ConditionalTest.java b/src/test/java/net/kemitix/conditional/ConditionalTest.java index 9e21aaf..87209cc 100644 --- a/src/test/java/net/kemitix/conditional/ConditionalTest.java +++ b/src/test/java/net/kemitix/conditional/ConditionalTest.java @@ -115,6 +115,35 @@ public class ConditionalTest { thenTheOtherwiseResponseRuns(); } + @Test + public void whereNotFalseThenRuns() { + //when + Condition.whereNot(false) + .then(thenResponse); + //then + thenTheThenResponseRuns(); + } + + @Test + public void whereTrueAndNotFalseThenRuns() { + //when + Condition.where(true) + .andNot(false) + .then(thenResponse); + //then + thenTheThenResponseRuns(); + } + + @Test + public void whereFalseOrNotFalseThenRuns() { + //when + Condition.where(false) + .orNot(false) + .then(thenResponse); + //then + thenTheThenResponseRuns(); + } + private void whenOr(final boolean firstClause, final boolean secondClause) { Condition.where(firstClause) .or(secondClause)