All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.pincette.util.When Maven / Gradle / Ivy

There is a newer version: 2.5.0
Show newest version
package net.pincette.util;

import static net.pincette.util.Util.tryToDoRethrow;

import net.pincette.function.RunnableWithException;

/**
 * Lets you write conditional statements without blocks. which can be useful for consumers and
 * runnables. Exampe:
 *
 * 

{@code () -> when().run(() -> ).orElse(() -> ) } * * @author Werner Donn\u00e9 */ public class When { private final boolean condition; private When(final boolean condition) { this.condition = condition; } public static When when(final boolean condition) { return new When(condition); } public void orElse(final RunnableWithException runnable) { if (!condition) { tryToDoRethrow(runnable); } } public When run(final RunnableWithException runnable) { if (condition) { tryToDoRethrow(runnable); } return this; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy