@Test public void swap() throws Exception { VariantStream<InvariantSpan> stream = new RopeVariantStream<>(documentHash, getA()); stream.swap(new VariantSpan(1, 3), new VariantSpan(12, 3)); List<InvariantSpan> spans = stream.getStreamElements(); assertEquals(new InvariantSpan(300, 3, documentHash), spans.get(0)); assertEquals(new InvariantSpan(103, 3, documentHash), spans.get(1)); assertEquals(new InvariantSpan(200, 3, documentHash), spans.get(2)); assertEquals(new InvariantSpan(250, 2, documentHash), spans.get(3)); assertEquals(new InvariantSpan(100, 3, documentHash), spans.get(4)); assertEquals(new InvariantSpan(303, 1, documentHash), spans.get(5)); assertEquals(new InvariantSpan(350, 1, documentHash), spans.get(6)); assertEquals(new InvariantSpan(360, 6, documentHash), spans.get(7)); assertEquals(8, spans.size()); }
@Override public void swap(VariantSpan v1, VariantSpan v2) throws MalformedSpanException { Node<T> from = deleteRange(v1); from.parent = null; long startV2 = v2.start - v1.width; Node<T> to = deleteRange(new VariantSpan(startV2, v2.width)); to.parent = null; insert(v1.start, to); insert(v2.start, from); }
RopeVariantStream implements VariantStream<T> { @Override public void swap(VariantSpan v1, VariantSpan v2) throws MalformedSpanException { Node<T> from = deleteRange(v1); from.parent = null; long startV2 = v2.start - v1.width; Node<T> to = deleteRange(new VariantSpan(startV2, v2.width)); to.parent = null; insert(v1.start, to); insert(v2.start, from); } }
RopeVariantStream implements VariantStream<T> { @Override public void swap(VariantSpan v1, VariantSpan v2) throws MalformedSpanException { Node<T> from = deleteRange(v1); from.parent = null; long startV2 = v2.start - v1.width; Node<T> to = deleteRange(new VariantSpan(startV2, v2.width)); to.parent = null; insert(v1.start, to); insert(v2.start, from); } RopeVariantStream(String documentHash);  RopeVariantStream(String documentHash, Node<T> root); }
RopeVariantStream implements VariantStream<T> { @Override public void swap(VariantSpan v1, VariantSpan v2) throws MalformedSpanException { Node<T> from = deleteRange(v1); from.parent = null; long startV2 = v2.start - v1.width; Node<T> to = deleteRange(new VariantSpan(startV2, v2.width)); to.parent = null; insert(v1.start, to); insert(v2.start, from); } RopeVariantStream(String documentHash);  RopeVariantStream(String documentHash, Node<T> root); @Override void copy(long characterPosition, VariantSpan variantSpan); @Override void delete(VariantSpan variantSpan); @Override String getDocumentHash(); @Override List<T> getStreamElements(); @Override List<T> getStreamElements(VariantSpan variantSpan); @Override List<VariantSpan> getVariantSpans(InvariantSpan targetSpan); @Override T index(long characterPosition); @Override void move(long to, VariantSpan v1); @Override void put(long characterPosition, T val); @Override void rebalance(); void save(OutputStream os); @Override void swap(VariantSpan v1, VariantSpan v2); @Override void toggleOverlay(VariantSpan variantSpan, Overlay linkType); }
RopeVariantStream implements VariantStream<T> { @Override public void swap(VariantSpan v1, VariantSpan v2) throws MalformedSpanException { Node<T> from = deleteRange(v1); from.parent = null; long startV2 = v2.start - v1.width; Node<T> to = deleteRange(new VariantSpan(startV2, v2.width)); to.parent = null; insert(v1.start, to); insert(v2.start, from); } RopeVariantStream(String documentHash);  RopeVariantStream(String documentHash, Node<T> root); @Override void copy(long characterPosition, VariantSpan variantSpan); @Override void delete(VariantSpan variantSpan); @Override String getDocumentHash(); @Override List<T> getStreamElements(); @Override List<T> getStreamElements(VariantSpan variantSpan); @Override List<VariantSpan> getVariantSpans(InvariantSpan targetSpan); @Override T index(long characterPosition); @Override void move(long to, VariantSpan v1); @Override void put(long characterPosition, T val); @Override void rebalance(); void save(OutputStream os); @Override void swap(VariantSpan v1, VariantSpan v2); @Override void toggleOverlay(VariantSpan variantSpan, Overlay linkType);  }