io.datakernel.util.guice.OptionalDependency Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of datakernel-boot Show documentation
Show all versions of datakernel-boot Show documentation
An intelligent way of booting complex applications and services according to their dependencies
package io.datakernel.util.guice;
import com.google.inject.Inject;
import java.util.function.Consumer;
import java.util.function.Supplier;
public final class OptionalDependency {
@Inject(optional = true)
private T value;
public T get() {
return value;
}
public boolean isPresent() {
return value != null;
}
public void ifPresent(Consumer super T> consumer) {
if (value != null) {
consumer.accept(value);
}
}
public T orElse(T defaultValue) {
return value != null ? value : defaultValue;
}
public T orElseGet(Supplier defaultValue) {
return value != null ? value : defaultValue.get();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy