53 lines
893 B
Java
53 lines
893 B
Java
package it.cavallium.strangedb.server;
|
|
|
|
import java.util.Arrays;
|
|
|
|
public class ArrayNode implements Node {
|
|
|
|
private final long reference;
|
|
private long[] items;
|
|
|
|
public ArrayNode(long reference, long[] items) {
|
|
this.reference = reference;
|
|
this.items = items;
|
|
}
|
|
|
|
public long[] getItems() {
|
|
return items;
|
|
}
|
|
|
|
public long getItem(int index) {
|
|
return items[index];
|
|
}
|
|
|
|
public int countItems() {
|
|
return items.length;
|
|
}
|
|
|
|
public void setItem(int index, long value) {
|
|
if (index >= items.length) {
|
|
items = Arrays.copyOf(items, index + 1);
|
|
}
|
|
items[index] = value;
|
|
}
|
|
|
|
public boolean hasItem(int index) {
|
|
return index >= 0 && index < items.length;
|
|
}
|
|
|
|
@Override
|
|
public NodeType getType() {
|
|
return NodeType.ARRAY;
|
|
}
|
|
|
|
@Override
|
|
public long getReference() {
|
|
return reference;
|
|
}
|
|
|
|
@Override
|
|
public Node copy() {
|
|
return new ArrayNode(reference, items.clone());
|
|
}
|
|
}
|