package com.jfireel.expression.node.impl;

import com.jfireel.expression.token.Operator;
import com.jfireel.expression.util.number.RemainderUtil;

import java.util.Map;

public class PercentNode extends OperatorResultNode {
	public PercentNode() {
		super(Operator.PERCENT);
	}

	@Override
	public Object calculate(Map<String, Object> variables) {
		Object leftValue = leftOperand.calculate(variables);
		if (leftValue == null) {
			return null;
		}
		Object rightValue = rightOperand.calculate(variables);
		if (rightValue == null) {
			return null;
		}
		return RemainderUtil.calculate((Number) leftValue, (Number) rightValue);
	}

}
