Add a DoubleArray example.

This commit is contained in:
Peter Lawrey
2015-04-23 17:46:43 +01:00
parent 137ee0647f
commit 952eab1259
@@ -3,11 +3,12 @@ package net.openhft.lang.values;
import net.openhft.lang.io.Bytes;
import net.openhft.lang.io.DirectStore;
import net.openhft.lang.model.Byteable;
import net.openhft.lang.model.Copyable;
/**
* Created by peter.lawrey on 23/04/2015.
*/
public class DoubleArray implements Byteable {
public class DoubleArray implements Byteable, Copyable<DoubleArray> {
private static int LENGTH = 0; // assume a 32-bit size.
private static int CAPACITY = LENGTH + 4; // assume a 32-bit size.
private static int BASE = CAPACITY + 4;
@@ -20,6 +21,7 @@ public class DoubleArray implements Byteable {
offset = 0;
}
@Override
public void bytes(Bytes bytes, long offset) {
this.bytes = bytes;
@@ -86,4 +88,12 @@ public class DoubleArray implements Byteable {
doubles[index] = bytes.readDouble(BASE + offset + index * 8L);
return length;
}
@Override
public void copyFrom(DoubleArray doubleArray) {
int length = length();
doubleArray.setLength(length);
for (int i = 0; i < length; i++)
doubleArray.setDataAt(i, getDataAt(i));
}
}