package com.ruoyi.project.business.dto.JEPNumberFactory;

import org.nfunk.jep.ParseException;
import org.nfunk.jep.type.Complex;
import org.nfunk.jep.type.NumberFactory;

import java.math.BigDecimal;

public class BigDecimalFactory implements NumberFactory {
    public static BigDecimal ZERO = new BigDecimal("0.0");
    public static BigDecimal ONE = new BigDecimal("1.0");
    public static BigDecimal TWO = new BigDecimal("2.0");
    public static BigDecimal MINUSONE = BigDecimal.valueOf(-1.0);

    public BigDecimalFactory(){

    }

    public Object createNumber(String value) {
        return new BigDecimal(value);
    }

    public Object createNumber(double value) {
        return new BigDecimal(value);
    }

    public Object createNumber(Number value) {
        return value;
    }

    public Object createNumber(boolean value) {
        return value ? ONE : ZERO;
    }

    public Object createNumber(float value) {
        return new BigDecimal(value);
    }

    public Object createNumber(int value) {
        return new BigDecimal(value);
    }

    public Object createNumber(short value) {
        return new BigDecimal(value);
    }

    public Object createNumber(Complex value) throws ParseException {
        throw new ParseException("Cannot create a number from a Complex value");
    }

    public Object getMinusOne() {
        return MINUSONE;
    }

    public Object getOne() {
        return ONE;
    }

    public Object getTwo() {
        return TWO;
    }

    public Object getZero() {
        return ZERO;
    }
}
