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

prompto.value.BaseValue Maven / Gradle / Ivy

The newest version!
package prompto.value;

import java.util.Map;
import java.util.function.Consumer;

import prompto.error.NotStorableError;
import prompto.error.PromptoError;
import prompto.runtime.Context;
import prompto.store.IStorable;
import prompto.type.IType;

import com.fasterxml.jackson.core.JsonGenerator;

public abstract class BaseValue implements IValue {
	
	IType type;
	
	protected BaseValue(IType type) {
		this.type = type;
	}
	
	@Override
	public boolean isMutable() {
		return false;
	}
	
	@Override
	public void setType(IType type) {
		this.type = type;
	}
	
	@Override
	public IType getType() {
		return type;
	}
	
	@Override
	public boolean roughly(Context context, IValue value) throws PromptoError {
		return this.equals(value);
	}

	@SuppressWarnings("unchecked")
	@Override
	public ISliceable asSliceable(Context context) throws PromptoError {
		return (this instanceof ISliceable) ? (ISliceable)this : null;
	}
	
	@Override
	public void toJsonStream(Context context, JsonGenerator generator, boolean withType, Map data) throws PromptoError {
		throw new UnsupportedOperationException("toJson not supported by " + this.getClass().getSimpleName());
	}
	
	@Override
	public void collectStorables(Consumer collector) throws NotStorableError {
		// nothing to do
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy