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

net.intelie.pipes.UnsafeRow Maven / Gradle / Ivy

There is a newer version: 0.25.5
Show newest version
package net.intelie.pipes;

import java.util.Arrays;
import java.util.Objects;

public final class UnsafeRow implements UnsafeObject {
    private final Object[] buffer;

    public UnsafeRow(int size) {
        this(new Object[size]);
    }

    private UnsafeRow(Object[] buffer) {
        this.buffer = buffer;
    }

    public Object get(int id) {
        return this.buffer[id];
    }

    public void set(int id, Object obj) {
        this.buffer[id] = obj;
    }

    public int setMany(int id, Row first) {
        int size = first.size();
        for (int j = 0; j < size; j++)
            set(id + j, first.get(j));
        return id + size;
    }

    public Object[] buffer() {
        return buffer;
    }

    @Override
    public UnsafeRow copy() {
        return new UnsafeRow(Arrays.copyOf(buffer, buffer.length));
    }

    public ArrayRow toRow() {
        return new ArrayRow(Arrays.copyOf(buffer, buffer.length));
    }

    public ArrayRow toRowUnsafe() {
        return new ArrayRow(buffer);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o instanceof UnsafeRow) {
            UnsafeRow row = (UnsafeRow) o;
            return Arrays.equals(buffer, row.buffer);
        } else if (o instanceof Row) {
            Row other = (Row) o;
            if (buffer.length != other.size())
                return false;

            for (int i = 0; i < buffer.length; i++)
                if (!Objects.equals(buffer[i], other.get(i)))
                    return false;

            return true;
        } else {
            return false;
        }

    }

    @Override
    public int hashCode() {
        return Arrays.hashCode(buffer);
    }

    @Override
    public String toString() {
        return "" + Arrays.asList(buffer);
    }

    public int size() {
        return buffer.length;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy