package de.accso.flexinale.shared_kernel;

import java.io.Serializable;

public interface RawWrapper<T> extends Serializable {
    T raw();

    default String print() { // unfortunately one cannot override toString() here, results in compiler error
        return raw().toString();
    }

    @SuppressWarnings("unchecked")
    static <T> T getRawOrNull(Object o) {
        if (o == null)
            return null;
        else
            try {
                RawWrapper<T> castedObject = (RawWrapper<T>)o;
                return castedObject.raw();
            }
            catch (ClassCastException ccex) {
                throw new DeveloperMistakeException(ccex);
            }
    }
}