PositionListWritable passes tests
diff --git a/genomix/genomix-data/src/main/java/edu/uci/ics/genomix/type/PositionListWritable.java b/genomix/genomix-data/src/main/java/edu/uci/ics/genomix/type/PositionListWritable.java
index a7d67d1..fa7d9d5 100644
--- a/genomix/genomix-data/src/main/java/edu/uci/ics/genomix/type/PositionListWritable.java
+++ b/genomix/genomix-data/src/main/java/edu/uci/ics/genomix/type/PositionListWritable.java
@@ -31,17 +31,19 @@
public PositionListWritable(byte[] data, int offset) {
// setNewReference(data, offset);
+ this();
set(data, offset);
}
public PositionListWritable(List<PositionWritable> posns) {
this();
- setSize(posns.size()); // reserve space for all elements
+ setSize(posns.size() * PositionWritable.LENGTH + HEADER_SIZE); // reserve space for all elements
for (PositionWritable p : posns) {
append(p);
}
}
+// // TODO: we currently don't track who actually owns each block so variable-length references are impossible. We could track 1) if it's a reference and 2) the size of the original reference block, but that would require a check for every setSize and might be coplicated logic
// public void setNewReference(byte[] data, int offset) {
// this.valueCount = Marshal.getInt(data, offset);
// this.storage = data;
@@ -112,13 +114,13 @@
set(otherList.storage, otherList.offset);
}
- public void set(byte[] newData, int offset) {
- valueCount = Marshal.getInt(newData, offset);
+ public void set(byte[] newData, int newOffset) {
+ valueCount = Marshal.getInt(newData, newOffset);
setSize(valueCount * PositionWritable.LENGTH + HEADER_SIZE);
if (valueCount > 0) {
- System.arraycopy(newData, offset + HEADER_SIZE, storage, this.offset + HEADER_SIZE, valueCount * PositionWritable.LENGTH);
+ System.arraycopy(newData, newOffset + HEADER_SIZE, storage, this.offset + HEADER_SIZE, valueCount * PositionWritable.LENGTH);
}
- Marshal.putInt(valueCount, storage, offset);
+ Marshal.putInt(valueCount, storage, this.offset);
}
public void reset() {
@@ -154,7 +156,7 @@
if (i >= valueCount) {
throw new ArrayIndexOutOfBoundsException("No such positions");
}
- posIter.setNewReference(storage, offset + i * PositionWritable.LENGTH);
+ posIter.setNewReference(storage, offset + i * PositionWritable.LENGTH + HEADER_SIZE);
return posIter;
}
@@ -162,7 +164,7 @@
if (i >= valueCount) {
throw new ArrayIndexOutOfBoundsException("No such positions");
}
- Marshal.putLong(uuid, storage, offset + i * PositionWritable.LENGTH);
+ Marshal.putLong(uuid, storage, offset + i * PositionWritable.LENGTH + HEADER_SIZE);
}
public int getCountOfPosition() {
@@ -178,7 +180,7 @@
}
public int getLength() {
- return valueCount * PositionWritable.LENGTH;
+ return valueCount * PositionWritable.LENGTH + HEADER_SIZE;
}
@Override
@@ -200,11 +202,12 @@
@Override
public void remove() {
if (currentIndex < valueCount)
- System.arraycopy(storage, offset + currentIndex * PositionWritable.LENGTH, storage, offset
- + (currentIndex - 1) * PositionWritable.LENGTH, (valueCount - currentIndex)
+ System.arraycopy(storage, offset + currentIndex * PositionWritable.LENGTH + HEADER_SIZE, storage, offset
+ + (currentIndex - 1) * PositionWritable.LENGTH + HEADER_SIZE, (valueCount - currentIndex)
* PositionWritable.LENGTH);
valueCount--;
currentIndex--;
+ Marshal.putInt(valueCount, storage, offset);
}
};
return it;
@@ -234,14 +237,15 @@
@Override
public void write(DataOutput out) throws IOException {
out.writeInt(valueCount);
- out.write(storage, offset, valueCount * PositionWritable.LENGTH);
+ out.write(storage, offset + HEADER_SIZE, valueCount * PositionWritable.LENGTH);
}
@Override
public void readFields(DataInput in) throws IOException {
this.valueCount = in.readInt();
- setSize(valueCount * PositionWritable.LENGTH);
- in.readFully(storage, offset, valueCount * PositionWritable.LENGTH);
+ setSize(valueCount * PositionWritable.LENGTH + HEADER_SIZE);
+ in.readFully(storage, offset + HEADER_SIZE, valueCount * PositionWritable.LENGTH);
+ Marshal.putInt(valueCount, storage, offset);
}
@Override
diff --git a/genomix/genomix-data/src/main/java/edu/uci/ics/genomix/type/PositionWritable.java b/genomix/genomix-data/src/main/java/edu/uci/ics/genomix/type/PositionWritable.java
index 1079677..03d66a6 100644
--- a/genomix/genomix-data/src/main/java/edu/uci/ics/genomix/type/PositionWritable.java
+++ b/genomix/genomix-data/src/main/java/edu/uci/ics/genomix/type/PositionWritable.java
@@ -119,10 +119,10 @@
}
/*
- * String of form "(readId-posID_mate)" where mate is _1 or _2
+ * String of form "(readId-posID_mate)" where mate is _0 or _1
*/
@Override
public String toString() {
- return "(" + this.getReadId() + "-" + this.getPosId() + "_" + (this.getMateId() + 1) + ")";
+ return "(" + this.getReadId() + "-" + this.getPosId() + "_" + (this.getMateId()) + ")";
}
}
diff --git a/genomix/genomix-data/src/test/java/edu/uci/ics/genomix/data/test/PositionListWritableTest.java b/genomix/genomix-data/src/test/java/edu/uci/ics/genomix/data/test/PositionListWritableTest.java
index fea658d..ac7322e 100644
--- a/genomix/genomix-data/src/test/java/edu/uci/ics/genomix/data/test/PositionListWritableTest.java
+++ b/genomix/genomix-data/src/test/java/edu/uci/ics/genomix/data/test/PositionListWritableTest.java
@@ -41,7 +41,7 @@
byte [] another = new byte [plist.getLength()*2];
int start = 20;
System.arraycopy(plist.getByteArray(), 0, another, start, plist.getLength());
- PositionListWritable plist2 = new PositionListWritable(plist.getCountOfPosition(),another,start);
+ PositionListWritable plist2 = new PositionListWritable(another,start);
for( i = 0; i < plist2.getCountOfPosition(); i++){
Assert.assertEquals(plist.getPosition(i), plist2.getPosition(i));
}
@@ -84,19 +84,22 @@
iterator = copyList.iterator();
PositionWritable deletePos = new PositionWritable();
deletePos.set((byte)1, (long)j, j);
+ boolean removed = false;
while(iterator.hasNext()){
pos = iterator.next();
if(pos.equals(deletePos)){
iterator.remove();
+ removed = true;
break;
}
}
+ Assert.assertTrue(removed);
Assert.assertEquals(5 - 1 - j, copyList.getCountOfPosition());
while(iterator.hasNext()){
pos = iterator.next();
- Assert.assertTrue(pos.getUUID() != deletePos.getUUID());
- Assert.assertTrue(pos.getReadId() != deletePos.getReadId());
- Assert.assertTrue(pos.getPosId() != deletePos.getPosId());
+ Assert.assertTrue(! (pos.getUUID() == deletePos.getUUID() &&
+ pos.getReadId() == deletePos.getReadId() &&
+ pos.getPosId() == deletePos.getPosId()));
i++;
}
}