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

io.datakernel.util.guice.OptionalDependency Maven / Gradle / Ivy

Go to download

An intelligent way of booting complex applications and services according to their dependencies

There is a newer version: 3.1.0
Show newest version
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 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