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

io.github.vmzakharov.ecdataframe.dsl.value.IntValue Maven / Gradle / Ivy

The newest version!
package io.github.vmzakharov.ecdataframe.dsl.value;

import io.github.vmzakharov.ecdataframe.dsl.ArithmeticOp;
import io.github.vmzakharov.ecdataframe.dsl.PredicateOp;
import io.github.vmzakharov.ecdataframe.dsl.UnaryOp;

import java.math.BigDecimal;

public record IntValue(int value)
implements WholeNumberValue
{
    @Override
    public String asStringLiteral()
    {
        return Integer.toString(this.value);
    }

    public int intValue()
    {
        return this.value;
    }

    @Override
    public double doubleValue()
    {
        return this.value;
    }

    @Override
    public long longValue()
    {
        return this.value;
    }

    @Override
    public BigDecimal decimalValue()
    {
        return BigDecimal.valueOf(this.value);
    }

    @Override
    public Value apply(Value another, ArithmeticOp operation)
    {
        if (another.isWholeNumber())
        {
            return operation.applyLong(this.longValue(), ((WholeNumberValue) another).longValue());
        }

        return operation.applyDouble(this.doubleValue(), ((NumberValue) another).doubleValue());
    }

    @Override
    public Value apply(UnaryOp operation)
    {
        return operation.applyInt(this.value);
    }

    @Override
    public BooleanValue applyPredicate(Value another, PredicateOp operation)
    {
        if (another.isWholeNumber())
        {
            return operation.applyLong(this.longValue(), ((WholeNumberValue) another).longValue());
        }

        return operation.applyDouble(this.doubleValue(), ((NumberValue) another).doubleValue());
    }

    @Override
    public ValueType getType()
    {
        return ValueType.INT;
    }

    @Override
    public int compareTo(Value other)
    {
        this.checkSameTypeForComparison(other);
        return other.isVoid() ? 1 : Integer.compare(this.intValue(), ((IntValue) other).intValue());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy