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

io.deephaven.engine.table.impl.util.cast.BigNumberToBigDecimalCast Maven / Gradle / Ivy

There is a newer version: 0.37.1
Show newest version
/**
 * Copyright (c) 2016-2022 Deephaven Data Labs and Patent Pending
 */
package io.deephaven.engine.table.impl.util.cast;

import io.deephaven.chunk.Chunk;
import io.deephaven.chunk.ObjectChunk;
import io.deephaven.chunk.WritableObjectChunk;
import io.deephaven.chunk.attributes.Any;

import java.math.BigDecimal;
import java.math.BigInteger;

/**
 * Cast the values in the input chunk to an int.
 */
public class BigNumberToBigDecimalCast implements ToBigDecimalCast {
    private final WritableObjectChunk result;

    BigNumberToBigDecimalCast(int size) {
        result = WritableObjectChunk.makeWritableChunk(size);
    }

    @Override
    public  ObjectChunk cast(Chunk input) {
        return cast(input.asObjectChunk());
    }

    @SuppressWarnings("unchecked")
    private  ObjectChunk cast(ObjectChunk input) {
        castInto(input, result);
        return result;
    }

    public static  void castInto(ObjectChunk input,
            WritableObjectChunk result) {
        final int size = input.size();
        for (int ii = 0; ii < size; ++ii) {
            final BigInteger value = input.get(ii);
            if (value == null) {
                result.set(ii, null);
            } else {
                result.set(ii, new BigDecimal(value));
            }
        }
        result.setSize(input.size());
    }

    @Override
    public void close() {
        // Fill with nulls before closing.
        result.fillWithNullValue(0, result.size());
        result.close();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy