diff --git a/src/main/java/com/github/nilstrieb/uselessclasses/Ifs.java b/src/main/java/com/github/nilstrieb/uselessclasses/Ifs.java new file mode 100644 index 0000000..02358a8 --- /dev/null +++ b/src/main/java/com/github/nilstrieb/uselessclasses/Ifs.java @@ -0,0 +1,28 @@ +package com.github.nilstrieb.uselessclasses; + +import java.util.function.Consumer; + +/** + * This class adds a brand new syntax for if-statements! + * You just need to statically import the methods + */ +public class Ifs { + public static void IF(boolean condition, Statements onTrue) { + IF(condition, onTrue, () -> {}); + } + + public static void IF(boolean condition, Statements onTrue, Statements onFalse) { + if(condition){ + onTrue.execute(); + } else { + onFalse.execute(); + } + } + + + + + interface Statements { + void execute(); + } +} diff --git a/src/main/test/com/github/nilstrieb/uselessclasses/IfsTest.java b/src/main/test/com/github/nilstrieb/uselessclasses/IfsTest.java new file mode 100644 index 0000000..3f6d47a --- /dev/null +++ b/src/main/test/com/github/nilstrieb/uselessclasses/IfsTest.java @@ -0,0 +1,34 @@ +package com.github.nilstrieb.uselessclasses; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +import static com.github.nilstrieb.uselessclasses.Ifs.IF; + +class IfsTest { + + @Test + void ifTest(){ + final int[] a = new int[1]; + + IF(true, () -> { + a[0] = 1; + }); + + assertEquals(1, a[0]); + } + + @Test + void ifElseTest(){ + final int[] a = new int[1]; + + IF(false, () -> { + a[0] = 1; + }, () -> { + a[0] = 2; + }); + + assertEquals(2, a[0]); + } +} \ No newline at end of file