@Test(expected = IllegalStateException.class) public void partitionNullNode() throws Exception { Partitioner.createNodePartition(2, null); }
public static <T extends StreamElement> NodePartition<T> createNodePartition(long leftPartitionWidth, Node<T> x) throws MalformedSpanException { if (x == null) { throw new IllegalStateException("Attempting to partition a null node"); } if (leftPartitionWidth < 0) { throw new IndexOutOfBoundsException( "Width of left partition must be non-negative: width = " + leftPartitionWidth); } if (leftPartitionWidth >= x.characterCount()) { return new NodePartition<T>(x, null); } else if (leftPartitionWidth == 0) { return new NodePartition<T>(null, x); } else if (x.isLeaf() && x.isRoot()) { Node<T> split = x.split(leftPartitionWidth); split.left.parent = null; split.right.parent = null; return new NodePartition<T>(split.left, split.right); } else { NodeIndex<T> nodeIndex = RopeUtils.index(leftPartitionWidth, x, 0); if (nodeIndex.displacement > leftPartitionWidth) { throw new IllegalStateException("Width of left partition can't be less than displacement: width = " + leftPartitionWidth + ", Displacement = " + nodeIndex.displacement); } Node<T> indexNode = nodeIndex.node; if (isSplitInMiddle(nodeIndex, leftPartitionWidth)) { Node<T> splitIndexNode = indexNode.split(leftPartitionWidth - nodeIndex.displacement); attachParent(splitIndexNode, indexNode.parent, indexNode.isRightNode()); splitIndexNode.weight = splitIndexNode.left.weight; indexNode = splitIndexNode.left; } List<Node<T>> orphans = pruneIndexNode(indexNode, leftPartitionWidth, nodeIndex.displacement); if (orphans.isEmpty()) { throw new IllegalStateException( "No partition available after cut: partitionWidth = " + leftPartitionWidth); } return new NodePartition<T>(x, RopeUtils.concat(orphans)); } }
Partitioner { public static <T extends StreamElement> NodePartition<T> createNodePartition(long leftPartitionWidth, Node<T> x) throws MalformedSpanException { if (x == null) { throw new IllegalStateException("Attempting to partition a null node"); } if (leftPartitionWidth < 0) { throw new IndexOutOfBoundsException( "Width of left partition must be non-negative: width = " + leftPartitionWidth); } if (leftPartitionWidth >= x.characterCount()) { return new NodePartition<T>(x, null); } else if (leftPartitionWidth == 0) { return new NodePartition<T>(null, x); } else if (x.isLeaf() && x.isRoot()) { Node<T> split = x.split(leftPartitionWidth); split.left.parent = null; split.right.parent = null; return new NodePartition<T>(split.left, split.right); } else { NodeIndex<T> nodeIndex = RopeUtils.index(leftPartitionWidth, x, 0); if (nodeIndex.displacement > leftPartitionWidth) { throw new IllegalStateException("Width of left partition can't be less than displacement: width = " + leftPartitionWidth + ", Displacement = " + nodeIndex.displacement); } Node<T> indexNode = nodeIndex.node; if (isSplitInMiddle(nodeIndex, leftPartitionWidth)) { Node<T> splitIndexNode = indexNode.split(leftPartitionWidth - nodeIndex.displacement); attachParent(splitIndexNode, indexNode.parent, indexNode.isRightNode()); splitIndexNode.weight = splitIndexNode.left.weight; indexNode = splitIndexNode.left; } List<Node<T>> orphans = pruneIndexNode(indexNode, leftPartitionWidth, nodeIndex.displacement); if (orphans.isEmpty()) { throw new IllegalStateException( "No partition available after cut: partitionWidth = " + leftPartitionWidth); } return new NodePartition<T>(x, RopeUtils.concat(orphans)); } } }
Partitioner { public static <T extends StreamElement> NodePartition<T> createNodePartition(long leftPartitionWidth, Node<T> x) throws MalformedSpanException { if (x == null) { throw new IllegalStateException("Attempting to partition a null node"); } if (leftPartitionWidth < 0) { throw new IndexOutOfBoundsException( "Width of left partition must be non-negative: width = " + leftPartitionWidth); } if (leftPartitionWidth >= x.characterCount()) { return new NodePartition<T>(x, null); } else if (leftPartitionWidth == 0) { return new NodePartition<T>(null, x); } else if (x.isLeaf() && x.isRoot()) { Node<T> split = x.split(leftPartitionWidth); split.left.parent = null; split.right.parent = null; return new NodePartition<T>(split.left, split.right); } else { NodeIndex<T> nodeIndex = RopeUtils.index(leftPartitionWidth, x, 0); if (nodeIndex.displacement > leftPartitionWidth) { throw new IllegalStateException("Width of left partition can't be less than displacement: width = " + leftPartitionWidth + ", Displacement = " + nodeIndex.displacement); } Node<T> indexNode = nodeIndex.node; if (isSplitInMiddle(nodeIndex, leftPartitionWidth)) { Node<T> splitIndexNode = indexNode.split(leftPartitionWidth - nodeIndex.displacement); attachParent(splitIndexNode, indexNode.parent, indexNode.isRightNode()); splitIndexNode.weight = splitIndexNode.left.weight; indexNode = splitIndexNode.left; } List<Node<T>> orphans = pruneIndexNode(indexNode, leftPartitionWidth, nodeIndex.displacement); if (orphans.isEmpty()) { throw new IllegalStateException( "No partition available after cut: partitionWidth = " + leftPartitionWidth); } return new NodePartition<T>(x, RopeUtils.concat(orphans)); } }  }
Partitioner { public static <T extends StreamElement> NodePartition<T> createNodePartition(long leftPartitionWidth, Node<T> x) throws MalformedSpanException { if (x == null) { throw new IllegalStateException("Attempting to partition a null node"); } if (leftPartitionWidth < 0) { throw new IndexOutOfBoundsException( "Width of left partition must be non-negative: width = " + leftPartitionWidth); } if (leftPartitionWidth >= x.characterCount()) { return new NodePartition<T>(x, null); } else if (leftPartitionWidth == 0) { return new NodePartition<T>(null, x); } else if (x.isLeaf() && x.isRoot()) { Node<T> split = x.split(leftPartitionWidth); split.left.parent = null; split.right.parent = null; return new NodePartition<T>(split.left, split.right); } else { NodeIndex<T> nodeIndex = RopeUtils.index(leftPartitionWidth, x, 0); if (nodeIndex.displacement > leftPartitionWidth) { throw new IllegalStateException("Width of left partition can't be less than displacement: width = " + leftPartitionWidth + ", Displacement = " + nodeIndex.displacement); } Node<T> indexNode = nodeIndex.node; if (isSplitInMiddle(nodeIndex, leftPartitionWidth)) { Node<T> splitIndexNode = indexNode.split(leftPartitionWidth - nodeIndex.displacement); attachParent(splitIndexNode, indexNode.parent, indexNode.isRightNode()); splitIndexNode.weight = splitIndexNode.left.weight; indexNode = splitIndexNode.left; } List<Node<T>> orphans = pruneIndexNode(indexNode, leftPartitionWidth, nodeIndex.displacement); if (orphans.isEmpty()) { throw new IllegalStateException( "No partition available after cut: partitionWidth = " + leftPartitionWidth); } return new NodePartition<T>(x, RopeUtils.concat(orphans)); } }  static NodePartition<T> createNodePartition(long leftPartitionWidth, Node<T> x); static List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth,
			long displacement); }
Partitioner { public static <T extends StreamElement> NodePartition<T> createNodePartition(long leftPartitionWidth, Node<T> x) throws MalformedSpanException { if (x == null) { throw new IllegalStateException("Attempting to partition a null node"); } if (leftPartitionWidth < 0) { throw new IndexOutOfBoundsException( "Width of left partition must be non-negative: width = " + leftPartitionWidth); } if (leftPartitionWidth >= x.characterCount()) { return new NodePartition<T>(x, null); } else if (leftPartitionWidth == 0) { return new NodePartition<T>(null, x); } else if (x.isLeaf() && x.isRoot()) { Node<T> split = x.split(leftPartitionWidth); split.left.parent = null; split.right.parent = null; return new NodePartition<T>(split.left, split.right); } else { NodeIndex<T> nodeIndex = RopeUtils.index(leftPartitionWidth, x, 0); if (nodeIndex.displacement > leftPartitionWidth) { throw new IllegalStateException("Width of left partition can't be less than displacement: width = " + leftPartitionWidth + ", Displacement = " + nodeIndex.displacement); } Node<T> indexNode = nodeIndex.node; if (isSplitInMiddle(nodeIndex, leftPartitionWidth)) { Node<T> splitIndexNode = indexNode.split(leftPartitionWidth - nodeIndex.displacement); attachParent(splitIndexNode, indexNode.parent, indexNode.isRightNode()); splitIndexNode.weight = splitIndexNode.left.weight; indexNode = splitIndexNode.left; } List<Node<T>> orphans = pruneIndexNode(indexNode, leftPartitionWidth, nodeIndex.displacement); if (orphans.isEmpty()) { throw new IllegalStateException( "No partition available after cut: partitionWidth = " + leftPartitionWidth); } return new NodePartition<T>(x, RopeUtils.concat(orphans)); } }  static NodePartition<T> createNodePartition(long leftPartitionWidth, Node<T> x); static List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth,
			long displacement);  }