RosettaCodeData/Task/Extend-your-language/Java/extend-your-language-3.java

42 lines
1.0 KiB
Java

public class If2 {
private final boolean firstCondition;
private final boolean secondCondition;
public If2(boolean firstCondition, boolean secondCondition) {
this.firstCondition = firstCondition;
this.secondCondition = secondCondition;
}
public static If2 if2(boolean firstCondition, boolean secondCondition) {
return new If2(firstCondition, secondCondition);
}
public If2 then(Runnable runnable) {
if (firstCondition && secondCondition) {
runnable.run();
}
return this;
}
public If2 elseNone(Runnable runnable) {
if (!firstCondition && !secondCondition) {
runnable.run();
}
return this;
}
public If2 elseIfFirst(Runnable runnable) {
if (firstCondition && !secondCondition) {
runnable.run();
}
return this;
}
public If2 elseIfSecond(Runnable runnable) {
if (!firstCondition && secondCondition) {
runnable.run();
}
return this;
}
}