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

com.infomaximum.database.utils.key.IntervalIndexKey Maven / Gradle / Ivy

The newest version!
package com.infomaximum.database.utils.key;

import com.infomaximum.database.schema.BaseIntervalIndex;
import com.infomaximum.database.schema.dbstruct.DBIntervalIndex;
import com.infomaximum.database.utils.IntervalIndexUtils;
import com.infomaximum.database.utils.TypeConvert;

import java.nio.ByteBuffer;

public class IntervalIndexKey extends BaseIntervalIndexKey {

    public IntervalIndexKey(long id, final long[] hashedValues, BaseIntervalIndex index) {
        super(id, hashedValues, index.attendant);
    }

    public IntervalIndexKey(long id, final long[] hashedValues, DBIntervalIndex index) {
        super(id, hashedValues, index.getAttendant());
    }

    public void setIndexedValue(Object value) {
        indexedValue = IntervalIndexUtils.castToLong(value);
    }

    @Override
    public byte[] pack() {
        ByteBuffer buffer = TypeConvert.allocateBuffer(attendant.length + ID_BYTE_SIZE * (hashedValues.length + 2) + Byte.BYTES);
        fillBuffer(attendant, hashedValues, indexedValue, buffer);
        buffer.putLong(getId());
        return buffer.array();
    }

    public static long unpackIndexedValue(final byte[] src) {
        return TypeConvert.unpackLong(src, src.length - 2 * ID_BYTE_SIZE);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy