net.intelie.pipes.UnsafeRow Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pipes-api Show documentation
Show all versions of pipes-api Show documentation
Intelie Pipes' API classes and interfaces
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;
}
}