Merge remote-tracking branch 'origin/master'

This commit is contained in:
Rob Austin
2015-04-29 13:14:52 +01:00
2 changed files with 37 additions and 1 deletions
@@ -16,6 +16,10 @@ public class DoubleArray implements Byteable, Copyable<DoubleArray> {
private Bytes bytes;
private long offset;
// creates an empty DoubleArray
public DoubleArray() {
}
public DoubleArray(int capacity) {
bytes = DirectStore.allocate(BASE + capacity * 8L).bytes();
bytes.writeInt(CAPACITY, capacity);
@@ -45,7 +49,7 @@ public class DoubleArray implements Byteable, Copyable<DoubleArray> {
}
public int length() {
return bytes.readInt(LENGTH + offset);
return bytes == null ? 6 * 8 : bytes.readInt(LENGTH + offset);
}
public int capacity() {
@@ -98,4 +102,15 @@ public class DoubleArray implements Byteable, Copyable<DoubleArray> {
for (int i = 0; i < length; i++)
doubleArray.setDataAt(i, getDataAt(i));
}
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("[ ");
String sep = "";
for (int i = 0, len = length(); i < len; i++) {
sb.append(sep).append(getDataAt(i));
sep = ", ";
}
return sb.append(" ]").toString();
}
}
@@ -1,5 +1,7 @@
package net.openhft.lang.values;
import net.openhft.chronicle.map.ChronicleMap;
import net.openhft.chronicle.map.ChronicleMapBuilder;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
@@ -45,4 +47,23 @@ public class DoubleArrayTest {
// free the memory.
da.bytes().release();
}
@Test
public void addToAMap() {
DoubleArray a = new DoubleArray(10);
a.setData(new double[]{1, 2, 3, 4, 5});
DoubleArray b = new DoubleArray(10);
b.setData(new double[]{5, 6, 7, 8, 9});
ChronicleMap<Integer, DoubleArray> proxyMap = ChronicleMapBuilder.of(Integer.class, DoubleArray.class)
.create();
proxyMap.put(1, a);
proxyMap.put(2, b);
System.out.println(proxyMap.get(1));
System.out.println(proxyMap.get(2));
proxyMap.close();
}
}