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

de.bytefish.pgbulkinsert.pgsql.handlers.RangeValueHandler Maven / Gradle / Ivy

There is a newer version: 7.0.1
Show newest version
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

package de.bytefish.pgbulkinsert.pgsql.handlers;

import de.bytefish.pgbulkinsert.pgsql.model.range.Range;

import java.io.DataOutputStream;

public class RangeValueHandler extends BaseValueHandler> {

    private final IValueHandler valueHandler;

    public RangeValueHandler(IValueHandler valueHandler) {
        this.valueHandler = valueHandler;
    }

    @SuppressWarnings("NullAway") // infinite bound checks only pass when bound value is not null
    @Override
    protected void internalHandle(DataOutputStream buffer, Range value) throws Exception {
        buffer.writeInt(getLength(value));
        buffer.writeByte(value.getFlags());

        if (value.isEmpty()) {
            return;
        }

        if(!value.isLowerBoundInfinite()) {
            valueHandler.handle(buffer, value.getLowerBound());
        }

        if(!value.isUpperBoundInfinite()) {
            valueHandler.handle(buffer, value.getUpperBound());
        }
    }

    @SuppressWarnings("NullAway") // infinite bound checks only pass when bound value is not null
    @Override
    public int getLength(Range value) {
        int totalLen = 1;

        if (!value.isEmpty()) {
            if (!value.isLowerBoundInfinite()) {
                totalLen += 4 + valueHandler.getLength(value.getLowerBound());
            }

            if (!value.isUpperBoundInfinite()) {
                totalLen += 4 + valueHandler.getLength(value.getUpperBound());
            }
        }

        return totalLen;
    }
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy