Add helper functions for mutating PositionListWritable's
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 db9f4aa..7a0d669 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
@@ -132,6 +132,20 @@
};
return it;
}
+
+ /*
+ * remove the first instance of @toRemove. Uses a linear scan. Throws an exception if not in this list.
+ */
+ public void remove(PositionWritable toRemove) {
+ Iterator<PositionWritable> posIterator = this.iterator();
+ while (posIterator.hasNext()) {
+ if(toRemove.equals(posIterator.next())) {
+ posIterator.remove();
+ return;
+ }
+ }
+ throw new ArrayIndexOutOfBoundsException("the PositionWritable `" + toRemove.toString() + "` was not found in this list.");
+ }
public void set(PositionListWritable list2) {
set(list2.valueCount, list2.storage, list2.offset);
@@ -163,6 +177,20 @@
valueCount += 1;
}
+ /*
+ * Append the otherList to the end of myList
+ */
+ public void appendList(PositionListWritable otherList) {
+ if (otherList.valueCount > 0) {
+ setSize((valueCount + otherList.valueCount) * PositionWritable.LENGTH);
+ // copy contents of otherList into the end of my storage
+ System.arraycopy(otherList.storage, otherList.offset,
+ storage, offset + valueCount * PositionWritable.LENGTH,
+ otherList.valueCount * PositionWritable.LENGTH);
+ valueCount += otherList.valueCount;
+ }
+ }
+
public static int getCountByDataLength(int length) {
if (length % PositionWritable.LENGTH != 0) {
for (StackTraceElement ste : Thread.currentThread().getStackTrace()) {