package org.allmyinfo.operation.factory.json;

import org.allmyinfo.json.JsonEntity;
import org.allmyinfo.json.JsonNumber;
import org.allmyinfo.operation.meta.FactoryContext;
import org.allmyinfo.operation.meta.OperandDescriptor;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;

public class Int8JsonStaticOperandReader implements JsonStaticOperandReader {
	Int8JsonStaticOperandReader() {
	}

	@Override
	@Nullable
	public Object readStaticOperand(final @NonNull FactoryContext context,
			final @NonNull OperandDescriptor operand, final @NonNull JsonEntity operandJE) {
		if (!(operandJE instanceof JsonNumber))
			throw new IllegalArgumentException("Operand " + operand.getName() + " is not a number");
		final JsonNumber operandJN = (JsonNumber) operandJE;
		return Long.valueOf(operandJN.toLong());
	}
}
