mirror of
https://github.com/Noratrieb/UselessClasses.git
synced 2026-01-14 16:45:09 +01:00
IF(true, () -> github.deleteRepo(this));
This commit is contained in:
parent
d9f980f1a9
commit
7167e0ca80
2 changed files with 62 additions and 0 deletions
28
src/main/java/com/github/nilstrieb/uselessclasses/Ifs.java
Normal file
28
src/main/java/com/github/nilstrieb/uselessclasses/Ifs.java
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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]);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue