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

io.descoped.dc.api.node.builder.AbstractBaseNode Maven / Gradle / Ivy

The newest version!
package io.descoped.dc.api.node.builder;

import io.descoped.dc.api.node.Base;

import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Consumer;

/**
 * Base for node implementation classes
 */
public abstract class AbstractBaseNode implements Base {

    @Override
    public boolean instanceOf(Class nodeClass) {
        return this.getClass().isAssignableFrom(nodeClass);
    }

    @Override
    public  R cast(Class nodeClass) {
        return nodeClass.cast(this);
    }

    @Override
    public  void given(Class isInstanceOfNodeClass, Consumer then) {
        if (instanceOf(isInstanceOfNodeClass)) {
            then.accept(cast(isInstanceOfNodeClass));
        }
    }

    @Override
    public  void given(Class isInstanceOfNodeClass, AtomicBoolean andIfNotHandled, Consumer then) {
        if (instanceOf(isInstanceOfNodeClass) && !andIfNotHandled.get()) {
            then.accept(cast(isInstanceOfNodeClass));
            andIfNotHandled.set(true);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy