IF(true, () -> github.deleteRepo(this));

This commit is contained in:
nora 2021-01-31 12:27:07 +01:00
parent d9f980f1a9
commit 7167e0ca80
2 changed files with 62 additions and 0 deletions

View file

@ -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();
}
}

View file

@ -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]);
}
}