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

io.github.vmzakharov.ecdataframe.dsl.value.LongValue 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 LongValue(long value)
implements WholeNumberValue
{
    @Override
    public String asStringLiteral()
    {
        return Long.toString(this.value);
    }

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

    @Override
    public double doubleValue()
    {
        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.applyLong(this.value);
    }

    @Override
    public BooleanValue applyPredicate(Value another, PredicateOp operation)
    {
        if (another.isDouble())
        {
            return operation.applyDouble(this.doubleValue(), ((DoubleValue) another).doubleValue());
        }
        return operation.applyLong(this.longValue(), ((LongValue) another).longValue());
    }

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

    @Override
    public int compareTo(Value other)
    {
        this.checkSameTypeForComparison(other);
        return other.isVoid() ? 1 : Long.compare(this.longValue(), ((LongValue) other).longValue());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy