package leigh.mecha.nodegraph;

import leigh.eo.EO;
import leigh.eo.EOLoop;

import java.io.Serializable;

/**
 * Simple implementation of {@link Attribute} for statically defined values.
 *
 * @author Alex Leigh
 */
public class StaticAttribute implements Attribute {
    private final Serializable value;

    public StaticAttribute(Serializable value) {
        this.value = value;
    }

    @Override
    public Serializable getSingleValue(ProcessorState state) {
        return value;
    }

    @Override
    public EO getObjectValue(ProcessorState state) {
        if (value != null && value instanceof EO) return (EO) value;
        return null;
    }

    public EOLoop getObjectsValue(ProcessorState state) {
        if (value != null && value instanceof EOLoop) return (EOLoop) value;
        return null;
    }

    public Serializable getValue() {
        return value;
    }

    @Override
    public String toString() {
        return "StaticAttribute{" +
                "value=" + value +
                '}';
    }
}
