io.atleon.core.AbstractDelegatingAlo Maven / Gradle / Ivy
package io.atleon.core;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Supplier;
/**
* Partial implementation of {@link DelegatingAlo} that supports both decoration and adaptation.
*
* @param The type of data item exposed by this {@link AbstractDelegatingAlo}
* @param The type of data item actually referenced by this {@link AbstractDelegatingAlo}'s delegate
*/
public abstract class AbstractDelegatingAlo implements DelegatingAlo {
protected final Alo delegate;
protected AbstractDelegatingAlo(Alo delegate) {
this.delegate = delegate;
}
@Override
public String toString() {
return getClass().getSimpleName() + "{delegate=" + delegate + "}";
}
@Override
public void runInContext(Runnable runnable) {
delegate.runInContext(runnable);
}
@Override
public R supplyInContext(Supplier supplier) {
return delegate.supplyInContext(supplier);
}
@Override
public AloFactory> fanInPropagator(List extends Alo>> alos) {
return delegate.fanInPropagator(alos);
}
@Override
public AloFactory propagator() {
return delegate.propagator();
}
@Override
public Runnable getAcknowledger() {
return delegate.getAcknowledger();
}
@Override
public Consumer super Throwable> getNacknowledger() {
return delegate.getNacknowledger();
}
@Override
public Alo getDelegate() {
return delegate;
}
protected static > void doOnDelegator(Alo> alo, Class type, Consumer consumer) {
if (type.isInstance(alo)) {
consumer.accept(type.cast(alo));
} else if (alo instanceof DelegatingAlo) {
doOnDelegator(DelegatingAlo.class.cast(alo).getDelegate(), type, consumer);
}
}
}