package com.brilliance.mda.runtime.mda.impl;

import com.brilliance.mda.runtime.mda.IValue;

/**
 * @Description
 * @Author s_guodong
 * @Date 2022/11/11
 */
public class SimpleValue<E> implements IValue<E> {
    E value;

    Class clazz;

    public SimpleValue() {
        this.clazz = Object.class;
    }

    public SimpleValue(E value, Class clazz) {
        this.value = value;
        this.clazz = clazz;
    }

    public SimpleValue(Class clazz) {
        this(null, clazz);
    }

    public SimpleValue(E value) {
        this(value, (value == null) ? Object.class : value.getClass());
    }

    public E setValue(E value) {
        this.value = value;
        return this.value;
    }

    public E getValue() {
        return this.value;
    }

    public Class getDataType() {
        return this.clazz;
    }

    public int compareTo(IValue<E> o) {
        if (o == null)
            return 1;
        E nValue = (E)o.getValue();
        if (this.value == null || nValue == null)
            return (this.value == null) ? -1 : 1;
        return this.value.toString().compareTo(nValue.toString());
    }
}
