target
stringlengths 20
113k
| src_fm
stringlengths 11
86.3k
| src_fm_fc
stringlengths 21
86.4k
| src_fm_fc_co
stringlengths 30
86.4k
| src_fm_fc_ms
stringlengths 42
86.8k
| src_fm_fc_ms_ff
stringlengths 43
86.8k
|
---|---|---|---|---|---|
@Test(expected = IndexOutOfBoundsException.class) public void splitOverUpperBound() throws Exception { InvariantSpan span = new InvariantSpan(100, 10, documentHash); span.split(15); } | @Override public StreamElementPartition<InvariantSpan> split(long leftPartitionWidth) throws MalformedSpanException { if (leftPartitionWidth < 1) { throw new IndexOutOfBoundsException( "Partition width must be greater than 0, partitionWidth = " + leftPartitionWidth); } if (width <= leftPartitionWidth) { throw new IndexOutOfBoundsException("Width of left partition is greater than or equal to span: span width =" + width + ", partitionWidth = " + leftPartitionWidth); } return new StreamElementPartition<InvariantSpan>(new InvariantSpan(start, leftPartitionWidth, documentHash), new InvariantSpan(start + leftPartitionWidth, width - leftPartitionWidth, documentHash)); } | InvariantSpan implements Invariant { @Override public StreamElementPartition<InvariantSpan> split(long leftPartitionWidth) throws MalformedSpanException { if (leftPartitionWidth < 1) { throw new IndexOutOfBoundsException( "Partition width must be greater than 0, partitionWidth = " + leftPartitionWidth); } if (width <= leftPartitionWidth) { throw new IndexOutOfBoundsException("Width of left partition is greater than or equal to span: span width =" + width + ", partitionWidth = " + leftPartitionWidth); } return new StreamElementPartition<InvariantSpan>(new InvariantSpan(start, leftPartitionWidth, documentHash), new InvariantSpan(start + leftPartitionWidth, width - leftPartitionWidth, documentHash)); } } | InvariantSpan implements Invariant { @Override public StreamElementPartition<InvariantSpan> split(long leftPartitionWidth) throws MalformedSpanException { if (leftPartitionWidth < 1) { throw new IndexOutOfBoundsException( "Partition width must be greater than 0, partitionWidth = " + leftPartitionWidth); } if (width <= leftPartitionWidth) { throw new IndexOutOfBoundsException("Width of left partition is greater than or equal to span: span width =" + width + ", partitionWidth = " + leftPartitionWidth); } return new StreamElementPartition<InvariantSpan>(new InvariantSpan(start, leftPartitionWidth, documentHash), new InvariantSpan(start + leftPartitionWidth, width - leftPartitionWidth, documentHash)); } InvariantSpan(); InvariantSpan(long start, long width, String documentHash); } | InvariantSpan implements Invariant { @Override public StreamElementPartition<InvariantSpan> split(long leftPartitionWidth) throws MalformedSpanException { if (leftPartitionWidth < 1) { throw new IndexOutOfBoundsException( "Partition width must be greater than 0, partitionWidth = " + leftPartitionWidth); } if (width <= leftPartitionWidth) { throw new IndexOutOfBoundsException("Width of left partition is greater than or equal to span: span width =" + width + ", partitionWidth = " + leftPartitionWidth); } return new StreamElementPartition<InvariantSpan>(new InvariantSpan(start, leftPartitionWidth, documentHash), new InvariantSpan(start + leftPartitionWidth, width - leftPartitionWidth, documentHash)); } InvariantSpan(); InvariantSpan(long start, long width, String documentHash); @Override InvariantSpan copy(); @Override boolean equals(Object obj); String getDocumentHash(); long getStart(); @Override long getWidth(); @Override int hashCode(); boolean hashDocumentHash(); void setStart(long start); @Override void setWidth(long width); @Override StreamElementPartition<InvariantSpan> split(long leftPartitionWidth); @Override String toString(); } | InvariantSpan implements Invariant { @Override public StreamElementPartition<InvariantSpan> split(long leftPartitionWidth) throws MalformedSpanException { if (leftPartitionWidth < 1) { throw new IndexOutOfBoundsException( "Partition width must be greater than 0, partitionWidth = " + leftPartitionWidth); } if (width <= leftPartitionWidth) { throw new IndexOutOfBoundsException("Width of left partition is greater than or equal to span: span width =" + width + ", partitionWidth = " + leftPartitionWidth); } return new StreamElementPartition<InvariantSpan>(new InvariantSpan(start, leftPartitionWidth, documentHash), new InvariantSpan(start + leftPartitionWidth, width - leftPartitionWidth, documentHash)); } InvariantSpan(); InvariantSpan(long start, long width, String documentHash); @Override InvariantSpan copy(); @Override boolean equals(Object obj); String getDocumentHash(); long getStart(); @Override long getWidth(); @Override int hashCode(); boolean hashDocumentHash(); void setStart(long start); @Override void setWidth(long width); @Override StreamElementPartition<InvariantSpan> split(long leftPartitionWidth); @Override String toString(); } |
@Test public void hashBlock() throws Exception { DocumentFile.Builder builder = new DocumentFile.Builder("fakeHash"); builder.previousHashBlock("sadasdsad"); DocumentFile file = builder.build(); assertEquals("sadasdsad", file.getHashPreviousBlock()); } | public String getHashPreviousBlock() { return hashPreviousBlock; } | DocumentFile { public String getHashPreviousBlock() { return hashPreviousBlock; } } | DocumentFile { public String getHashPreviousBlock() { return hashPreviousBlock; } private DocumentFile(); } | DocumentFile { public String getHashPreviousBlock() { return hashPreviousBlock; } private DocumentFile(); static org.oulipo.streams.Compiler<DocumentFile> compiler(); static Decompiler<DocumentFile> decompiler(); Map<Integer, String> get(); String getDocumentHash(); String getEncyptedInvariantStream(); String getGenesisHash(); String getHashPreviousBlock(); String getInvariantStream(); int getMajorVersion(); int getMinorVersion(); List<Op> getOps(); Overlay getOverlay(int overlayIndex); Map<Integer, Overlay> getOverlayPool(); Set<Overlay> getOverlays(Set<Integer> indicies); String getString(int stringPoolIndex); long getTimestamp(); boolean hasEncryptedInvariantStream(); boolean hasGenesisHash(); boolean hasHashPreviousBlock(); boolean hasInvariantStream(); int operationCount(); int overlayPoolSize(); int stringPoolSize(); } | DocumentFile { public String getHashPreviousBlock() { return hashPreviousBlock; } private DocumentFile(); static org.oulipo.streams.Compiler<DocumentFile> compiler(); static Decompiler<DocumentFile> decompiler(); Map<Integer, String> get(); String getDocumentHash(); String getEncyptedInvariantStream(); String getGenesisHash(); String getHashPreviousBlock(); String getInvariantStream(); int getMajorVersion(); int getMinorVersion(); List<Op> getOps(); Overlay getOverlay(int overlayIndex); Map<Integer, Overlay> getOverlayPool(); Set<Overlay> getOverlays(Set<Integer> indicies); String getString(int stringPoolIndex); long getTimestamp(); boolean hasEncryptedInvariantStream(); boolean hasGenesisHash(); boolean hasHashPreviousBlock(); boolean hasInvariantStream(); int operationCount(); int overlayPoolSize(); int stringPoolSize(); static final byte[] MAGIC; } |
@Test(expected = IndexOutOfBoundsException.class) public void splitStart() throws Exception { InvariantSpan span = new InvariantSpan(1, 4, documentHash); span.split(0); } | @Override public StreamElementPartition<InvariantSpan> split(long leftPartitionWidth) throws MalformedSpanException { if (leftPartitionWidth < 1) { throw new IndexOutOfBoundsException( "Partition width must be greater than 0, partitionWidth = " + leftPartitionWidth); } if (width <= leftPartitionWidth) { throw new IndexOutOfBoundsException("Width of left partition is greater than or equal to span: span width =" + width + ", partitionWidth = " + leftPartitionWidth); } return new StreamElementPartition<InvariantSpan>(new InvariantSpan(start, leftPartitionWidth, documentHash), new InvariantSpan(start + leftPartitionWidth, width - leftPartitionWidth, documentHash)); } | InvariantSpan implements Invariant { @Override public StreamElementPartition<InvariantSpan> split(long leftPartitionWidth) throws MalformedSpanException { if (leftPartitionWidth < 1) { throw new IndexOutOfBoundsException( "Partition width must be greater than 0, partitionWidth = " + leftPartitionWidth); } if (width <= leftPartitionWidth) { throw new IndexOutOfBoundsException("Width of left partition is greater than or equal to span: span width =" + width + ", partitionWidth = " + leftPartitionWidth); } return new StreamElementPartition<InvariantSpan>(new InvariantSpan(start, leftPartitionWidth, documentHash), new InvariantSpan(start + leftPartitionWidth, width - leftPartitionWidth, documentHash)); } } | InvariantSpan implements Invariant { @Override public StreamElementPartition<InvariantSpan> split(long leftPartitionWidth) throws MalformedSpanException { if (leftPartitionWidth < 1) { throw new IndexOutOfBoundsException( "Partition width must be greater than 0, partitionWidth = " + leftPartitionWidth); } if (width <= leftPartitionWidth) { throw new IndexOutOfBoundsException("Width of left partition is greater than or equal to span: span width =" + width + ", partitionWidth = " + leftPartitionWidth); } return new StreamElementPartition<InvariantSpan>(new InvariantSpan(start, leftPartitionWidth, documentHash), new InvariantSpan(start + leftPartitionWidth, width - leftPartitionWidth, documentHash)); } InvariantSpan(); InvariantSpan(long start, long width, String documentHash); } | InvariantSpan implements Invariant { @Override public StreamElementPartition<InvariantSpan> split(long leftPartitionWidth) throws MalformedSpanException { if (leftPartitionWidth < 1) { throw new IndexOutOfBoundsException( "Partition width must be greater than 0, partitionWidth = " + leftPartitionWidth); } if (width <= leftPartitionWidth) { throw new IndexOutOfBoundsException("Width of left partition is greater than or equal to span: span width =" + width + ", partitionWidth = " + leftPartitionWidth); } return new StreamElementPartition<InvariantSpan>(new InvariantSpan(start, leftPartitionWidth, documentHash), new InvariantSpan(start + leftPartitionWidth, width - leftPartitionWidth, documentHash)); } InvariantSpan(); InvariantSpan(long start, long width, String documentHash); @Override InvariantSpan copy(); @Override boolean equals(Object obj); String getDocumentHash(); long getStart(); @Override long getWidth(); @Override int hashCode(); boolean hashDocumentHash(); void setStart(long start); @Override void setWidth(long width); @Override StreamElementPartition<InvariantSpan> split(long leftPartitionWidth); @Override String toString(); } | InvariantSpan implements Invariant { @Override public StreamElementPartition<InvariantSpan> split(long leftPartitionWidth) throws MalformedSpanException { if (leftPartitionWidth < 1) { throw new IndexOutOfBoundsException( "Partition width must be greater than 0, partitionWidth = " + leftPartitionWidth); } if (width <= leftPartitionWidth) { throw new IndexOutOfBoundsException("Width of left partition is greater than or equal to span: span width =" + width + ", partitionWidth = " + leftPartitionWidth); } return new StreamElementPartition<InvariantSpan>(new InvariantSpan(start, leftPartitionWidth, documentHash), new InvariantSpan(start + leftPartitionWidth, width - leftPartitionWidth, documentHash)); } InvariantSpan(); InvariantSpan(long start, long width, String documentHash); @Override InvariantSpan copy(); @Override boolean equals(Object obj); String getDocumentHash(); long getStart(); @Override long getWidth(); @Override int hashCode(); boolean hashDocumentHash(); void setStart(long start); @Override void setWidth(long width); @Override StreamElementPartition<InvariantSpan> split(long leftPartitionWidth); @Override String toString(); } |
@Test public void root() throws Exception { assertTrue(new Node<InvariantSpan>(10).isRoot()); } | public boolean isRoot() { return parent == null; } | Node { public boolean isRoot() { return parent == null; } } | Node { public boolean isRoot() { return parent == null; } Node(long weight); Node(T value); } | Node { public boolean isRoot() { return parent == null; } Node(long weight); Node(T value); long characterCount(); boolean isLeaf(); boolean isRightNode(); boolean isRoot(); Node<T> split(long leftPartitionWidth); @Override String toString(); } | Node { public boolean isRoot() { return parent == null; } Node(long weight); Node(T value); long characterCount(); boolean isLeaf(); boolean isRightNode(); boolean isRoot(); Node<T> split(long leftPartitionWidth); @Override String toString(); public boolean isRed; public Node<T> left; public Node<T> parent; public Node<T> right; public String tag; final T value; public long weight; } |
@Test public void simpleSplit() throws Exception { Node<InvariantSpan> node = new Node<InvariantSpan>(new InvariantSpan(1, 10, documentHash)); Node<InvariantSpan> result = node.split(5); assertNotNull(result.left); assertNotNull(result.right); assertEquals(new InvariantSpan(1, 5, documentHash), result.left.value); assertEquals(new InvariantSpan(6, 5, documentHash), result.right.value); } | public Node<T> split(long leftPartitionWidth) throws MalformedSpanException { if (leftPartitionWidth < 1) { throw new IllegalArgumentException("leftPartitionWidth must be greater than 0"); } if (!isLeaf()) { throw new MalformedSpanException("Can only split a leaf node"); } Node<T> parent = new Node<T>(leftPartitionWidth); StreamElementPartition<T> spans = (StreamElementPartition<T>) value.split(leftPartitionWidth); parent.left = new Node<T>(spans.getLeft()); parent.right = new Node<T>(spans.getRight()); parent.left.parent = parent; parent.right.parent = parent; if (parent.weight != leftPartitionWidth) { throw new IllegalStateException("node weight must equal variant position cutpoint"); } return parent; } | Node { public Node<T> split(long leftPartitionWidth) throws MalformedSpanException { if (leftPartitionWidth < 1) { throw new IllegalArgumentException("leftPartitionWidth must be greater than 0"); } if (!isLeaf()) { throw new MalformedSpanException("Can only split a leaf node"); } Node<T> parent = new Node<T>(leftPartitionWidth); StreamElementPartition<T> spans = (StreamElementPartition<T>) value.split(leftPartitionWidth); parent.left = new Node<T>(spans.getLeft()); parent.right = new Node<T>(spans.getRight()); parent.left.parent = parent; parent.right.parent = parent; if (parent.weight != leftPartitionWidth) { throw new IllegalStateException("node weight must equal variant position cutpoint"); } return parent; } } | Node { public Node<T> split(long leftPartitionWidth) throws MalformedSpanException { if (leftPartitionWidth < 1) { throw new IllegalArgumentException("leftPartitionWidth must be greater than 0"); } if (!isLeaf()) { throw new MalformedSpanException("Can only split a leaf node"); } Node<T> parent = new Node<T>(leftPartitionWidth); StreamElementPartition<T> spans = (StreamElementPartition<T>) value.split(leftPartitionWidth); parent.left = new Node<T>(spans.getLeft()); parent.right = new Node<T>(spans.getRight()); parent.left.parent = parent; parent.right.parent = parent; if (parent.weight != leftPartitionWidth) { throw new IllegalStateException("node weight must equal variant position cutpoint"); } return parent; } Node(long weight); Node(T value); } | Node { public Node<T> split(long leftPartitionWidth) throws MalformedSpanException { if (leftPartitionWidth < 1) { throw new IllegalArgumentException("leftPartitionWidth must be greater than 0"); } if (!isLeaf()) { throw new MalformedSpanException("Can only split a leaf node"); } Node<T> parent = new Node<T>(leftPartitionWidth); StreamElementPartition<T> spans = (StreamElementPartition<T>) value.split(leftPartitionWidth); parent.left = new Node<T>(spans.getLeft()); parent.right = new Node<T>(spans.getRight()); parent.left.parent = parent; parent.right.parent = parent; if (parent.weight != leftPartitionWidth) { throw new IllegalStateException("node weight must equal variant position cutpoint"); } return parent; } Node(long weight); Node(T value); long characterCount(); boolean isLeaf(); boolean isRightNode(); boolean isRoot(); Node<T> split(long leftPartitionWidth); @Override String toString(); } | Node { public Node<T> split(long leftPartitionWidth) throws MalformedSpanException { if (leftPartitionWidth < 1) { throw new IllegalArgumentException("leftPartitionWidth must be greater than 0"); } if (!isLeaf()) { throw new MalformedSpanException("Can only split a leaf node"); } Node<T> parent = new Node<T>(leftPartitionWidth); StreamElementPartition<T> spans = (StreamElementPartition<T>) value.split(leftPartitionWidth); parent.left = new Node<T>(spans.getLeft()); parent.right = new Node<T>(spans.getRight()); parent.left.parent = parent; parent.right.parent = parent; if (parent.weight != leftPartitionWidth) { throw new IllegalStateException("node weight must equal variant position cutpoint"); } return parent; } Node(long weight); Node(T value); long characterCount(); boolean isLeaf(); boolean isRightNode(); boolean isRoot(); Node<T> split(long leftPartitionWidth); @Override String toString(); public boolean isRed; public Node<T> left; public Node<T> parent; public Node<T> right; public String tag; final T value; public long weight; } |
@Test public void split13() throws Exception { Node<InvariantSpan> result = getK().split(2); assertEquals(new InvariantSpan(300, 2, documentHash), result.left.value); assertEquals(new InvariantSpan(302, 2, documentHash), result.right.value); } | public Node<T> split(long leftPartitionWidth) throws MalformedSpanException { if (leftPartitionWidth < 1) { throw new IllegalArgumentException("leftPartitionWidth must be greater than 0"); } if (!isLeaf()) { throw new MalformedSpanException("Can only split a leaf node"); } Node<T> parent = new Node<T>(leftPartitionWidth); StreamElementPartition<T> spans = (StreamElementPartition<T>) value.split(leftPartitionWidth); parent.left = new Node<T>(spans.getLeft()); parent.right = new Node<T>(spans.getRight()); parent.left.parent = parent; parent.right.parent = parent; if (parent.weight != leftPartitionWidth) { throw new IllegalStateException("node weight must equal variant position cutpoint"); } return parent; } | Node { public Node<T> split(long leftPartitionWidth) throws MalformedSpanException { if (leftPartitionWidth < 1) { throw new IllegalArgumentException("leftPartitionWidth must be greater than 0"); } if (!isLeaf()) { throw new MalformedSpanException("Can only split a leaf node"); } Node<T> parent = new Node<T>(leftPartitionWidth); StreamElementPartition<T> spans = (StreamElementPartition<T>) value.split(leftPartitionWidth); parent.left = new Node<T>(spans.getLeft()); parent.right = new Node<T>(spans.getRight()); parent.left.parent = parent; parent.right.parent = parent; if (parent.weight != leftPartitionWidth) { throw new IllegalStateException("node weight must equal variant position cutpoint"); } return parent; } } | Node { public Node<T> split(long leftPartitionWidth) throws MalformedSpanException { if (leftPartitionWidth < 1) { throw new IllegalArgumentException("leftPartitionWidth must be greater than 0"); } if (!isLeaf()) { throw new MalformedSpanException("Can only split a leaf node"); } Node<T> parent = new Node<T>(leftPartitionWidth); StreamElementPartition<T> spans = (StreamElementPartition<T>) value.split(leftPartitionWidth); parent.left = new Node<T>(spans.getLeft()); parent.right = new Node<T>(spans.getRight()); parent.left.parent = parent; parent.right.parent = parent; if (parent.weight != leftPartitionWidth) { throw new IllegalStateException("node weight must equal variant position cutpoint"); } return parent; } Node(long weight); Node(T value); } | Node { public Node<T> split(long leftPartitionWidth) throws MalformedSpanException { if (leftPartitionWidth < 1) { throw new IllegalArgumentException("leftPartitionWidth must be greater than 0"); } if (!isLeaf()) { throw new MalformedSpanException("Can only split a leaf node"); } Node<T> parent = new Node<T>(leftPartitionWidth); StreamElementPartition<T> spans = (StreamElementPartition<T>) value.split(leftPartitionWidth); parent.left = new Node<T>(spans.getLeft()); parent.right = new Node<T>(spans.getRight()); parent.left.parent = parent; parent.right.parent = parent; if (parent.weight != leftPartitionWidth) { throw new IllegalStateException("node weight must equal variant position cutpoint"); } return parent; } Node(long weight); Node(T value); long characterCount(); boolean isLeaf(); boolean isRightNode(); boolean isRoot(); Node<T> split(long leftPartitionWidth); @Override String toString(); } | Node { public Node<T> split(long leftPartitionWidth) throws MalformedSpanException { if (leftPartitionWidth < 1) { throw new IllegalArgumentException("leftPartitionWidth must be greater than 0"); } if (!isLeaf()) { throw new MalformedSpanException("Can only split a leaf node"); } Node<T> parent = new Node<T>(leftPartitionWidth); StreamElementPartition<T> spans = (StreamElementPartition<T>) value.split(leftPartitionWidth); parent.left = new Node<T>(spans.getLeft()); parent.right = new Node<T>(spans.getRight()); parent.left.parent = parent; parent.right.parent = parent; if (parent.weight != leftPartitionWidth) { throw new IllegalStateException("node weight must equal variant position cutpoint"); } return parent; } Node(long weight); Node(T value); long characterCount(); boolean isLeaf(); boolean isRightNode(); boolean isRoot(); Node<T> split(long leftPartitionWidth); @Override String toString(); public boolean isRed; public Node<T> left; public Node<T> parent; public Node<T> right; public String tag; final T value; public long weight; } |
@Test(expected = MalformedSpanException.class) public void splitBranch() throws Exception { new Node<InvariantSpan>(10).split(5); } | public Node<T> split(long leftPartitionWidth) throws MalformedSpanException { if (leftPartitionWidth < 1) { throw new IllegalArgumentException("leftPartitionWidth must be greater than 0"); } if (!isLeaf()) { throw new MalformedSpanException("Can only split a leaf node"); } Node<T> parent = new Node<T>(leftPartitionWidth); StreamElementPartition<T> spans = (StreamElementPartition<T>) value.split(leftPartitionWidth); parent.left = new Node<T>(spans.getLeft()); parent.right = new Node<T>(spans.getRight()); parent.left.parent = parent; parent.right.parent = parent; if (parent.weight != leftPartitionWidth) { throw new IllegalStateException("node weight must equal variant position cutpoint"); } return parent; } | Node { public Node<T> split(long leftPartitionWidth) throws MalformedSpanException { if (leftPartitionWidth < 1) { throw new IllegalArgumentException("leftPartitionWidth must be greater than 0"); } if (!isLeaf()) { throw new MalformedSpanException("Can only split a leaf node"); } Node<T> parent = new Node<T>(leftPartitionWidth); StreamElementPartition<T> spans = (StreamElementPartition<T>) value.split(leftPartitionWidth); parent.left = new Node<T>(spans.getLeft()); parent.right = new Node<T>(spans.getRight()); parent.left.parent = parent; parent.right.parent = parent; if (parent.weight != leftPartitionWidth) { throw new IllegalStateException("node weight must equal variant position cutpoint"); } return parent; } } | Node { public Node<T> split(long leftPartitionWidth) throws MalformedSpanException { if (leftPartitionWidth < 1) { throw new IllegalArgumentException("leftPartitionWidth must be greater than 0"); } if (!isLeaf()) { throw new MalformedSpanException("Can only split a leaf node"); } Node<T> parent = new Node<T>(leftPartitionWidth); StreamElementPartition<T> spans = (StreamElementPartition<T>) value.split(leftPartitionWidth); parent.left = new Node<T>(spans.getLeft()); parent.right = new Node<T>(spans.getRight()); parent.left.parent = parent; parent.right.parent = parent; if (parent.weight != leftPartitionWidth) { throw new IllegalStateException("node weight must equal variant position cutpoint"); } return parent; } Node(long weight); Node(T value); } | Node { public Node<T> split(long leftPartitionWidth) throws MalformedSpanException { if (leftPartitionWidth < 1) { throw new IllegalArgumentException("leftPartitionWidth must be greater than 0"); } if (!isLeaf()) { throw new MalformedSpanException("Can only split a leaf node"); } Node<T> parent = new Node<T>(leftPartitionWidth); StreamElementPartition<T> spans = (StreamElementPartition<T>) value.split(leftPartitionWidth); parent.left = new Node<T>(spans.getLeft()); parent.right = new Node<T>(spans.getRight()); parent.left.parent = parent; parent.right.parent = parent; if (parent.weight != leftPartitionWidth) { throw new IllegalStateException("node weight must equal variant position cutpoint"); } return parent; } Node(long weight); Node(T value); long characterCount(); boolean isLeaf(); boolean isRightNode(); boolean isRoot(); Node<T> split(long leftPartitionWidth); @Override String toString(); } | Node { public Node<T> split(long leftPartitionWidth) throws MalformedSpanException { if (leftPartitionWidth < 1) { throw new IllegalArgumentException("leftPartitionWidth must be greater than 0"); } if (!isLeaf()) { throw new MalformedSpanException("Can only split a leaf node"); } Node<T> parent = new Node<T>(leftPartitionWidth); StreamElementPartition<T> spans = (StreamElementPartition<T>) value.split(leftPartitionWidth); parent.left = new Node<T>(spans.getLeft()); parent.right = new Node<T>(spans.getRight()); parent.left.parent = parent; parent.right.parent = parent; if (parent.weight != leftPartitionWidth) { throw new IllegalStateException("node weight must equal variant position cutpoint"); } return parent; } Node(long weight); Node(T value); long characterCount(); boolean isLeaf(); boolean isRightNode(); boolean isRoot(); Node<T> split(long leftPartitionWidth); @Override String toString(); public boolean isRed; public Node<T> left; public Node<T> parent; public Node<T> right; public String tag; final T value; public long weight; } |
@Test public void splitEdge() throws Exception { Node<InvariantSpan> result = getE().split(4); assertEquals(new InvariantSpan(100, 4, documentHash), result.left.value); assertEquals(new InvariantSpan(104, 2, documentHash), result.right.value); } | public Node<T> split(long leftPartitionWidth) throws MalformedSpanException { if (leftPartitionWidth < 1) { throw new IllegalArgumentException("leftPartitionWidth must be greater than 0"); } if (!isLeaf()) { throw new MalformedSpanException("Can only split a leaf node"); } Node<T> parent = new Node<T>(leftPartitionWidth); StreamElementPartition<T> spans = (StreamElementPartition<T>) value.split(leftPartitionWidth); parent.left = new Node<T>(spans.getLeft()); parent.right = new Node<T>(spans.getRight()); parent.left.parent = parent; parent.right.parent = parent; if (parent.weight != leftPartitionWidth) { throw new IllegalStateException("node weight must equal variant position cutpoint"); } return parent; } | Node { public Node<T> split(long leftPartitionWidth) throws MalformedSpanException { if (leftPartitionWidth < 1) { throw new IllegalArgumentException("leftPartitionWidth must be greater than 0"); } if (!isLeaf()) { throw new MalformedSpanException("Can only split a leaf node"); } Node<T> parent = new Node<T>(leftPartitionWidth); StreamElementPartition<T> spans = (StreamElementPartition<T>) value.split(leftPartitionWidth); parent.left = new Node<T>(spans.getLeft()); parent.right = new Node<T>(spans.getRight()); parent.left.parent = parent; parent.right.parent = parent; if (parent.weight != leftPartitionWidth) { throw new IllegalStateException("node weight must equal variant position cutpoint"); } return parent; } } | Node { public Node<T> split(long leftPartitionWidth) throws MalformedSpanException { if (leftPartitionWidth < 1) { throw new IllegalArgumentException("leftPartitionWidth must be greater than 0"); } if (!isLeaf()) { throw new MalformedSpanException("Can only split a leaf node"); } Node<T> parent = new Node<T>(leftPartitionWidth); StreamElementPartition<T> spans = (StreamElementPartition<T>) value.split(leftPartitionWidth); parent.left = new Node<T>(spans.getLeft()); parent.right = new Node<T>(spans.getRight()); parent.left.parent = parent; parent.right.parent = parent; if (parent.weight != leftPartitionWidth) { throw new IllegalStateException("node weight must equal variant position cutpoint"); } return parent; } Node(long weight); Node(T value); } | Node { public Node<T> split(long leftPartitionWidth) throws MalformedSpanException { if (leftPartitionWidth < 1) { throw new IllegalArgumentException("leftPartitionWidth must be greater than 0"); } if (!isLeaf()) { throw new MalformedSpanException("Can only split a leaf node"); } Node<T> parent = new Node<T>(leftPartitionWidth); StreamElementPartition<T> spans = (StreamElementPartition<T>) value.split(leftPartitionWidth); parent.left = new Node<T>(spans.getLeft()); parent.right = new Node<T>(spans.getRight()); parent.left.parent = parent; parent.right.parent = parent; if (parent.weight != leftPartitionWidth) { throw new IllegalStateException("node weight must equal variant position cutpoint"); } return parent; } Node(long weight); Node(T value); long characterCount(); boolean isLeaf(); boolean isRightNode(); boolean isRoot(); Node<T> split(long leftPartitionWidth); @Override String toString(); } | Node { public Node<T> split(long leftPartitionWidth) throws MalformedSpanException { if (leftPartitionWidth < 1) { throw new IllegalArgumentException("leftPartitionWidth must be greater than 0"); } if (!isLeaf()) { throw new MalformedSpanException("Can only split a leaf node"); } Node<T> parent = new Node<T>(leftPartitionWidth); StreamElementPartition<T> spans = (StreamElementPartition<T>) value.split(leftPartitionWidth); parent.left = new Node<T>(spans.getLeft()); parent.right = new Node<T>(spans.getRight()); parent.left.parent = parent; parent.right.parent = parent; if (parent.weight != leftPartitionWidth) { throw new IllegalStateException("node weight must equal variant position cutpoint"); } return parent; } Node(long weight); Node(T value); long characterCount(); boolean isLeaf(); boolean isRightNode(); boolean isRoot(); Node<T> split(long leftPartitionWidth); @Override String toString(); public boolean isRed; public Node<T> left; public Node<T> parent; public Node<T> right; public String tag; final T value; public long weight; } |
@Test public void splitF() throws Exception { Node<InvariantSpan> result = getF().split(2); assertEquals(new InvariantSpan(200, 2, documentHash), result.left.value); assertEquals(new InvariantSpan(202, 1, documentHash), result.right.value); } | public Node<T> split(long leftPartitionWidth) throws MalformedSpanException { if (leftPartitionWidth < 1) { throw new IllegalArgumentException("leftPartitionWidth must be greater than 0"); } if (!isLeaf()) { throw new MalformedSpanException("Can only split a leaf node"); } Node<T> parent = new Node<T>(leftPartitionWidth); StreamElementPartition<T> spans = (StreamElementPartition<T>) value.split(leftPartitionWidth); parent.left = new Node<T>(spans.getLeft()); parent.right = new Node<T>(spans.getRight()); parent.left.parent = parent; parent.right.parent = parent; if (parent.weight != leftPartitionWidth) { throw new IllegalStateException("node weight must equal variant position cutpoint"); } return parent; } | Node { public Node<T> split(long leftPartitionWidth) throws MalformedSpanException { if (leftPartitionWidth < 1) { throw new IllegalArgumentException("leftPartitionWidth must be greater than 0"); } if (!isLeaf()) { throw new MalformedSpanException("Can only split a leaf node"); } Node<T> parent = new Node<T>(leftPartitionWidth); StreamElementPartition<T> spans = (StreamElementPartition<T>) value.split(leftPartitionWidth); parent.left = new Node<T>(spans.getLeft()); parent.right = new Node<T>(spans.getRight()); parent.left.parent = parent; parent.right.parent = parent; if (parent.weight != leftPartitionWidth) { throw new IllegalStateException("node weight must equal variant position cutpoint"); } return parent; } } | Node { public Node<T> split(long leftPartitionWidth) throws MalformedSpanException { if (leftPartitionWidth < 1) { throw new IllegalArgumentException("leftPartitionWidth must be greater than 0"); } if (!isLeaf()) { throw new MalformedSpanException("Can only split a leaf node"); } Node<T> parent = new Node<T>(leftPartitionWidth); StreamElementPartition<T> spans = (StreamElementPartition<T>) value.split(leftPartitionWidth); parent.left = new Node<T>(spans.getLeft()); parent.right = new Node<T>(spans.getRight()); parent.left.parent = parent; parent.right.parent = parent; if (parent.weight != leftPartitionWidth) { throw new IllegalStateException("node weight must equal variant position cutpoint"); } return parent; } Node(long weight); Node(T value); } | Node { public Node<T> split(long leftPartitionWidth) throws MalformedSpanException { if (leftPartitionWidth < 1) { throw new IllegalArgumentException("leftPartitionWidth must be greater than 0"); } if (!isLeaf()) { throw new MalformedSpanException("Can only split a leaf node"); } Node<T> parent = new Node<T>(leftPartitionWidth); StreamElementPartition<T> spans = (StreamElementPartition<T>) value.split(leftPartitionWidth); parent.left = new Node<T>(spans.getLeft()); parent.right = new Node<T>(spans.getRight()); parent.left.parent = parent; parent.right.parent = parent; if (parent.weight != leftPartitionWidth) { throw new IllegalStateException("node weight must equal variant position cutpoint"); } return parent; } Node(long weight); Node(T value); long characterCount(); boolean isLeaf(); boolean isRightNode(); boolean isRoot(); Node<T> split(long leftPartitionWidth); @Override String toString(); } | Node { public Node<T> split(long leftPartitionWidth) throws MalformedSpanException { if (leftPartitionWidth < 1) { throw new IllegalArgumentException("leftPartitionWidth must be greater than 0"); } if (!isLeaf()) { throw new MalformedSpanException("Can only split a leaf node"); } Node<T> parent = new Node<T>(leftPartitionWidth); StreamElementPartition<T> spans = (StreamElementPartition<T>) value.split(leftPartitionWidth); parent.left = new Node<T>(spans.getLeft()); parent.right = new Node<T>(spans.getRight()); parent.left.parent = parent; parent.right.parent = parent; if (parent.weight != leftPartitionWidth) { throw new IllegalStateException("node weight must equal variant position cutpoint"); } return parent; } Node(long weight); Node(T value); long characterCount(); boolean isLeaf(); boolean isRightNode(); boolean isRoot(); Node<T> split(long leftPartitionWidth); @Override String toString(); public boolean isRed; public Node<T> left; public Node<T> parent; public Node<T> right; public String tag; final T value; public long weight; } |
@Test public void splitMinEdge() throws Exception { Node<InvariantSpan> result = getE().split(1); assertEquals(new InvariantSpan(100, 1, documentHash), result.left.value); assertEquals(new InvariantSpan(101, 5, documentHash), result.right.value); } | public Node<T> split(long leftPartitionWidth) throws MalformedSpanException { if (leftPartitionWidth < 1) { throw new IllegalArgumentException("leftPartitionWidth must be greater than 0"); } if (!isLeaf()) { throw new MalformedSpanException("Can only split a leaf node"); } Node<T> parent = new Node<T>(leftPartitionWidth); StreamElementPartition<T> spans = (StreamElementPartition<T>) value.split(leftPartitionWidth); parent.left = new Node<T>(spans.getLeft()); parent.right = new Node<T>(spans.getRight()); parent.left.parent = parent; parent.right.parent = parent; if (parent.weight != leftPartitionWidth) { throw new IllegalStateException("node weight must equal variant position cutpoint"); } return parent; } | Node { public Node<T> split(long leftPartitionWidth) throws MalformedSpanException { if (leftPartitionWidth < 1) { throw new IllegalArgumentException("leftPartitionWidth must be greater than 0"); } if (!isLeaf()) { throw new MalformedSpanException("Can only split a leaf node"); } Node<T> parent = new Node<T>(leftPartitionWidth); StreamElementPartition<T> spans = (StreamElementPartition<T>) value.split(leftPartitionWidth); parent.left = new Node<T>(spans.getLeft()); parent.right = new Node<T>(spans.getRight()); parent.left.parent = parent; parent.right.parent = parent; if (parent.weight != leftPartitionWidth) { throw new IllegalStateException("node weight must equal variant position cutpoint"); } return parent; } } | Node { public Node<T> split(long leftPartitionWidth) throws MalformedSpanException { if (leftPartitionWidth < 1) { throw new IllegalArgumentException("leftPartitionWidth must be greater than 0"); } if (!isLeaf()) { throw new MalformedSpanException("Can only split a leaf node"); } Node<T> parent = new Node<T>(leftPartitionWidth); StreamElementPartition<T> spans = (StreamElementPartition<T>) value.split(leftPartitionWidth); parent.left = new Node<T>(spans.getLeft()); parent.right = new Node<T>(spans.getRight()); parent.left.parent = parent; parent.right.parent = parent; if (parent.weight != leftPartitionWidth) { throw new IllegalStateException("node weight must equal variant position cutpoint"); } return parent; } Node(long weight); Node(T value); } | Node { public Node<T> split(long leftPartitionWidth) throws MalformedSpanException { if (leftPartitionWidth < 1) { throw new IllegalArgumentException("leftPartitionWidth must be greater than 0"); } if (!isLeaf()) { throw new MalformedSpanException("Can only split a leaf node"); } Node<T> parent = new Node<T>(leftPartitionWidth); StreamElementPartition<T> spans = (StreamElementPartition<T>) value.split(leftPartitionWidth); parent.left = new Node<T>(spans.getLeft()); parent.right = new Node<T>(spans.getRight()); parent.left.parent = parent; parent.right.parent = parent; if (parent.weight != leftPartitionWidth) { throw new IllegalStateException("node weight must equal variant position cutpoint"); } return parent; } Node(long weight); Node(T value); long characterCount(); boolean isLeaf(); boolean isRightNode(); boolean isRoot(); Node<T> split(long leftPartitionWidth); @Override String toString(); } | Node { public Node<T> split(long leftPartitionWidth) throws MalformedSpanException { if (leftPartitionWidth < 1) { throw new IllegalArgumentException("leftPartitionWidth must be greater than 0"); } if (!isLeaf()) { throw new MalformedSpanException("Can only split a leaf node"); } Node<T> parent = new Node<T>(leftPartitionWidth); StreamElementPartition<T> spans = (StreamElementPartition<T>) value.split(leftPartitionWidth); parent.left = new Node<T>(spans.getLeft()); parent.right = new Node<T>(spans.getRight()); parent.left.parent = parent; parent.right.parent = parent; if (parent.weight != leftPartitionWidth) { throw new IllegalStateException("node weight must equal variant position cutpoint"); } return parent; } Node(long weight); Node(T value); long characterCount(); boolean isLeaf(); boolean isRightNode(); boolean isRoot(); Node<T> split(long leftPartitionWidth); @Override String toString(); public boolean isRed; public Node<T> left; public Node<T> parent; public Node<T> right; public String tag; final T value; public long weight; } |
@Test(expected = IllegalArgumentException.class) public void splitNegative() throws Exception { Node<InvariantSpan> node = new Node<InvariantSpan>(new InvariantSpan(1, 10, documentHash)); node.split(-1); } | public Node<T> split(long leftPartitionWidth) throws MalformedSpanException { if (leftPartitionWidth < 1) { throw new IllegalArgumentException("leftPartitionWidth must be greater than 0"); } if (!isLeaf()) { throw new MalformedSpanException("Can only split a leaf node"); } Node<T> parent = new Node<T>(leftPartitionWidth); StreamElementPartition<T> spans = (StreamElementPartition<T>) value.split(leftPartitionWidth); parent.left = new Node<T>(spans.getLeft()); parent.right = new Node<T>(spans.getRight()); parent.left.parent = parent; parent.right.parent = parent; if (parent.weight != leftPartitionWidth) { throw new IllegalStateException("node weight must equal variant position cutpoint"); } return parent; } | Node { public Node<T> split(long leftPartitionWidth) throws MalformedSpanException { if (leftPartitionWidth < 1) { throw new IllegalArgumentException("leftPartitionWidth must be greater than 0"); } if (!isLeaf()) { throw new MalformedSpanException("Can only split a leaf node"); } Node<T> parent = new Node<T>(leftPartitionWidth); StreamElementPartition<T> spans = (StreamElementPartition<T>) value.split(leftPartitionWidth); parent.left = new Node<T>(spans.getLeft()); parent.right = new Node<T>(spans.getRight()); parent.left.parent = parent; parent.right.parent = parent; if (parent.weight != leftPartitionWidth) { throw new IllegalStateException("node weight must equal variant position cutpoint"); } return parent; } } | Node { public Node<T> split(long leftPartitionWidth) throws MalformedSpanException { if (leftPartitionWidth < 1) { throw new IllegalArgumentException("leftPartitionWidth must be greater than 0"); } if (!isLeaf()) { throw new MalformedSpanException("Can only split a leaf node"); } Node<T> parent = new Node<T>(leftPartitionWidth); StreamElementPartition<T> spans = (StreamElementPartition<T>) value.split(leftPartitionWidth); parent.left = new Node<T>(spans.getLeft()); parent.right = new Node<T>(spans.getRight()); parent.left.parent = parent; parent.right.parent = parent; if (parent.weight != leftPartitionWidth) { throw new IllegalStateException("node weight must equal variant position cutpoint"); } return parent; } Node(long weight); Node(T value); } | Node { public Node<T> split(long leftPartitionWidth) throws MalformedSpanException { if (leftPartitionWidth < 1) { throw new IllegalArgumentException("leftPartitionWidth must be greater than 0"); } if (!isLeaf()) { throw new MalformedSpanException("Can only split a leaf node"); } Node<T> parent = new Node<T>(leftPartitionWidth); StreamElementPartition<T> spans = (StreamElementPartition<T>) value.split(leftPartitionWidth); parent.left = new Node<T>(spans.getLeft()); parent.right = new Node<T>(spans.getRight()); parent.left.parent = parent; parent.right.parent = parent; if (parent.weight != leftPartitionWidth) { throw new IllegalStateException("node weight must equal variant position cutpoint"); } return parent; } Node(long weight); Node(T value); long characterCount(); boolean isLeaf(); boolean isRightNode(); boolean isRoot(); Node<T> split(long leftPartitionWidth); @Override String toString(); } | Node { public Node<T> split(long leftPartitionWidth) throws MalformedSpanException { if (leftPartitionWidth < 1) { throw new IllegalArgumentException("leftPartitionWidth must be greater than 0"); } if (!isLeaf()) { throw new MalformedSpanException("Can only split a leaf node"); } Node<T> parent = new Node<T>(leftPartitionWidth); StreamElementPartition<T> spans = (StreamElementPartition<T>) value.split(leftPartitionWidth); parent.left = new Node<T>(spans.getLeft()); parent.right = new Node<T>(spans.getRight()); parent.left.parent = parent; parent.right.parent = parent; if (parent.weight != leftPartitionWidth) { throw new IllegalStateException("node weight must equal variant position cutpoint"); } return parent; } Node(long weight); Node(T value); long characterCount(); boolean isLeaf(); boolean isRightNode(); boolean isRoot(); Node<T> split(long leftPartitionWidth); @Override String toString(); public boolean isRed; public Node<T> left; public Node<T> parent; public Node<T> right; public String tag; final T value; public long weight; } |
@Test public void streamLoadable() throws Exception { File file = new File("target/streams-junit/FileInvariantStream-" + System.currentTimeMillis() + ".txt"); InvariantStream stream = new FileInvariantStream(file, null, "fakeHash", null); stream.append("Hello"); stream.append("Xanadu"); } | @Override public InvariantSpan append(String text) throws IOException, MalformedSpanException { if (Strings.isNullOrEmpty(text)) { throw new MalformedSpanException("No text - span length is 0"); } FileLock lock = channel.lock(); try { InvariantSpan span = new InvariantSpan(channel.position() + 1, text.length(), documentHash); buffer.clear(); buffer.put(text.getBytes()); buffer.flip(); while (buffer.hasRemaining()) { channel.write(buffer); } channel.force(true); return span; } finally { lock.release(); } } | FileInvariantStream implements InvariantStream { @Override public InvariantSpan append(String text) throws IOException, MalformedSpanException { if (Strings.isNullOrEmpty(text)) { throw new MalformedSpanException("No text - span length is 0"); } FileLock lock = channel.lock(); try { InvariantSpan span = new InvariantSpan(channel.position() + 1, text.length(), documentHash); buffer.clear(); buffer.put(text.getBytes()); buffer.flip(); while (buffer.hasRemaining()) { channel.write(buffer); } channel.force(true); return span; } finally { lock.release(); } } } | FileInvariantStream implements InvariantStream { @Override public InvariantSpan append(String text) throws IOException, MalformedSpanException { if (Strings.isNullOrEmpty(text)) { throw new MalformedSpanException("No text - span length is 0"); } FileLock lock = channel.lock(); try { InvariantSpan span = new InvariantSpan(channel.position() + 1, text.length(), documentHash); buffer.clear(); buffer.put(text.getBytes()); buffer.flip(); while (buffer.hasRemaining()) { channel.write(buffer); } channel.force(true); return span; } finally { lock.release(); } } FileInvariantStream(File file, File encryptedFile, String documentHash, Key key); } | FileInvariantStream implements InvariantStream { @Override public InvariantSpan append(String text) throws IOException, MalformedSpanException { if (Strings.isNullOrEmpty(text)) { throw new MalformedSpanException("No text - span length is 0"); } FileLock lock = channel.lock(); try { InvariantSpan span = new InvariantSpan(channel.position() + 1, text.length(), documentHash); buffer.clear(); buffer.put(text.getBytes()); buffer.flip(); while (buffer.hasRemaining()) { channel.write(buffer); } channel.force(true); return span; } finally { lock.release(); } } FileInvariantStream(File file, File encryptedFile, String documentHash, Key key); @Override InvariantSpan append(String text); @Override String getText(InvariantSpan ispan); } | FileInvariantStream implements InvariantStream { @Override public InvariantSpan append(String text) throws IOException, MalformedSpanException { if (Strings.isNullOrEmpty(text)) { throw new MalformedSpanException("No text - span length is 0"); } FileLock lock = channel.lock(); try { InvariantSpan span = new InvariantSpan(channel.position() + 1, text.length(), documentHash); buffer.clear(); buffer.put(text.getBytes()); buffer.flip(); while (buffer.hasRemaining()) { channel.write(buffer); } channel.force(true); return span; } finally { lock.release(); } } FileInvariantStream(File file, File encryptedFile, String documentHash, Key key); @Override InvariantSpan append(String text); @Override String getText(InvariantSpan ispan); } |
@Test public void addEncryptedTextCompile() throws Exception { KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA"); keyGen.initialize(2056); KeyPair pair = keyGen.generateKeyPair(); DocumentFile.Builder builder = new DocumentFile.Builder("fakeHash"); builder.appendEncryptedText("Xanadu"); builder.appendEncryptedText("Green"); DocumentFile file = builder.build(); String compiledDocument = DocumentFile.compiler().compileEncrypted(file, new ECKey(), pair.getPublic()); DocumentFile result = DocumentFile.decompiler().decompileEncrypted("fakehash", compiledDocument.getBytes(), pair.getPrivate()); assertEquals("XanaduGreen", result.getEncyptedInvariantStream()); } | @Override public String compileEncrypted(DocumentFile doc, ECKey ecKey, Key key) throws Exception { if (ecKey == null) { throw new IllegalArgumentException("ECKey is null"); } ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream os = new DataOutputStream(baos); String publicKeyHash = URLDecoder.decode(ecKey.toAddress(MainNetParams.get()).toString(), "UTF-8"); os.write(DocumentFile.MAGIC); os.writeShort(0); os.writeUTF(publicKeyHash); os.writeUTF(doc.hasGenesisHash() ? doc.getGenesisHash() : ""); os.writeUTF(doc.hasHashPreviousBlock() ? doc.getHashPreviousBlock() : ""); os.writeInt(doc.getMajorVersion()); os.writeInt(doc.getMinorVersion()); os.writeLong(System.currentTimeMillis()); os.writeInt(doc.stringPoolSize()); for (Map.Entry<Integer, String> entry : doc.getStringPool().entrySet()) { os.writeInt(entry.getKey()); os.writeUTF(entry.getValue()); } os.writeInt(doc.overlayPoolSize()); for (Map.Entry<Integer, Overlay> entry : doc.getOverlayPool().entrySet()) { os.writeInt(entry.getKey()); os.write(entry.getValue().encode()); } os.writeUTF(doc.hasInvariantStream() ? doc.getInvariantStream() : ""); os.writeUTF(doc.hasEncryptedInvariantStream() ? encrypt(doc.getEncyptedInvariantStream(), key) : ""); os.writeInt(doc.operationCount()); for (Op op : doc.getOps()) { os.write(op.encode()); } String message = base64Url().encode(baos.toByteArray()); String signature64 = ecKey.signMessage(message); return message + "." + publicKeyHash + "." + signature64; } | DocumentFileCompiler implements Compiler<DocumentFile> { @Override public String compileEncrypted(DocumentFile doc, ECKey ecKey, Key key) throws Exception { if (ecKey == null) { throw new IllegalArgumentException("ECKey is null"); } ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream os = new DataOutputStream(baos); String publicKeyHash = URLDecoder.decode(ecKey.toAddress(MainNetParams.get()).toString(), "UTF-8"); os.write(DocumentFile.MAGIC); os.writeShort(0); os.writeUTF(publicKeyHash); os.writeUTF(doc.hasGenesisHash() ? doc.getGenesisHash() : ""); os.writeUTF(doc.hasHashPreviousBlock() ? doc.getHashPreviousBlock() : ""); os.writeInt(doc.getMajorVersion()); os.writeInt(doc.getMinorVersion()); os.writeLong(System.currentTimeMillis()); os.writeInt(doc.stringPoolSize()); for (Map.Entry<Integer, String> entry : doc.getStringPool().entrySet()) { os.writeInt(entry.getKey()); os.writeUTF(entry.getValue()); } os.writeInt(doc.overlayPoolSize()); for (Map.Entry<Integer, Overlay> entry : doc.getOverlayPool().entrySet()) { os.writeInt(entry.getKey()); os.write(entry.getValue().encode()); } os.writeUTF(doc.hasInvariantStream() ? doc.getInvariantStream() : ""); os.writeUTF(doc.hasEncryptedInvariantStream() ? encrypt(doc.getEncyptedInvariantStream(), key) : ""); os.writeInt(doc.operationCount()); for (Op op : doc.getOps()) { os.write(op.encode()); } String message = base64Url().encode(baos.toByteArray()); String signature64 = ecKey.signMessage(message); return message + "." + publicKeyHash + "." + signature64; } } | DocumentFileCompiler implements Compiler<DocumentFile> { @Override public String compileEncrypted(DocumentFile doc, ECKey ecKey, Key key) throws Exception { if (ecKey == null) { throw new IllegalArgumentException("ECKey is null"); } ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream os = new DataOutputStream(baos); String publicKeyHash = URLDecoder.decode(ecKey.toAddress(MainNetParams.get()).toString(), "UTF-8"); os.write(DocumentFile.MAGIC); os.writeShort(0); os.writeUTF(publicKeyHash); os.writeUTF(doc.hasGenesisHash() ? doc.getGenesisHash() : ""); os.writeUTF(doc.hasHashPreviousBlock() ? doc.getHashPreviousBlock() : ""); os.writeInt(doc.getMajorVersion()); os.writeInt(doc.getMinorVersion()); os.writeLong(System.currentTimeMillis()); os.writeInt(doc.stringPoolSize()); for (Map.Entry<Integer, String> entry : doc.getStringPool().entrySet()) { os.writeInt(entry.getKey()); os.writeUTF(entry.getValue()); } os.writeInt(doc.overlayPoolSize()); for (Map.Entry<Integer, Overlay> entry : doc.getOverlayPool().entrySet()) { os.writeInt(entry.getKey()); os.write(entry.getValue().encode()); } os.writeUTF(doc.hasInvariantStream() ? doc.getInvariantStream() : ""); os.writeUTF(doc.hasEncryptedInvariantStream() ? encrypt(doc.getEncyptedInvariantStream(), key) : ""); os.writeInt(doc.operationCount()); for (Op op : doc.getOps()) { os.write(op.encode()); } String message = base64Url().encode(baos.toByteArray()); String signature64 = ecKey.signMessage(message); return message + "." + publicKeyHash + "." + signature64; } } | DocumentFileCompiler implements Compiler<DocumentFile> { @Override public String compileEncrypted(DocumentFile doc, ECKey ecKey, Key key) throws Exception { if (ecKey == null) { throw new IllegalArgumentException("ECKey is null"); } ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream os = new DataOutputStream(baos); String publicKeyHash = URLDecoder.decode(ecKey.toAddress(MainNetParams.get()).toString(), "UTF-8"); os.write(DocumentFile.MAGIC); os.writeShort(0); os.writeUTF(publicKeyHash); os.writeUTF(doc.hasGenesisHash() ? doc.getGenesisHash() : ""); os.writeUTF(doc.hasHashPreviousBlock() ? doc.getHashPreviousBlock() : ""); os.writeInt(doc.getMajorVersion()); os.writeInt(doc.getMinorVersion()); os.writeLong(System.currentTimeMillis()); os.writeInt(doc.stringPoolSize()); for (Map.Entry<Integer, String> entry : doc.getStringPool().entrySet()) { os.writeInt(entry.getKey()); os.writeUTF(entry.getValue()); } os.writeInt(doc.overlayPoolSize()); for (Map.Entry<Integer, Overlay> entry : doc.getOverlayPool().entrySet()) { os.writeInt(entry.getKey()); os.write(entry.getValue().encode()); } os.writeUTF(doc.hasInvariantStream() ? doc.getInvariantStream() : ""); os.writeUTF(doc.hasEncryptedInvariantStream() ? encrypt(doc.getEncyptedInvariantStream(), key) : ""); os.writeInt(doc.operationCount()); for (Op op : doc.getOps()) { os.write(op.encode()); } String message = base64Url().encode(baos.toByteArray()); String signature64 = ecKey.signMessage(message); return message + "." + publicKeyHash + "." + signature64; } static DocumentFileCompiler createInstance(); @Override String compileEncrypted(DocumentFile doc, ECKey ecKey, Key key); } | DocumentFileCompiler implements Compiler<DocumentFile> { @Override public String compileEncrypted(DocumentFile doc, ECKey ecKey, Key key) throws Exception { if (ecKey == null) { throw new IllegalArgumentException("ECKey is null"); } ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream os = new DataOutputStream(baos); String publicKeyHash = URLDecoder.decode(ecKey.toAddress(MainNetParams.get()).toString(), "UTF-8"); os.write(DocumentFile.MAGIC); os.writeShort(0); os.writeUTF(publicKeyHash); os.writeUTF(doc.hasGenesisHash() ? doc.getGenesisHash() : ""); os.writeUTF(doc.hasHashPreviousBlock() ? doc.getHashPreviousBlock() : ""); os.writeInt(doc.getMajorVersion()); os.writeInt(doc.getMinorVersion()); os.writeLong(System.currentTimeMillis()); os.writeInt(doc.stringPoolSize()); for (Map.Entry<Integer, String> entry : doc.getStringPool().entrySet()) { os.writeInt(entry.getKey()); os.writeUTF(entry.getValue()); } os.writeInt(doc.overlayPoolSize()); for (Map.Entry<Integer, Overlay> entry : doc.getOverlayPool().entrySet()) { os.writeInt(entry.getKey()); os.write(entry.getValue().encode()); } os.writeUTF(doc.hasInvariantStream() ? doc.getInvariantStream() : ""); os.writeUTF(doc.hasEncryptedInvariantStream() ? encrypt(doc.getEncyptedInvariantStream(), key) : ""); os.writeInt(doc.operationCount()); for (Op op : doc.getOps()) { os.write(op.encode()); } String message = base64Url().encode(baos.toByteArray()); String signature64 = ecKey.signMessage(message); return message + "." + publicKeyHash + "." + signature64; } static DocumentFileCompiler createInstance(); @Override String compileEncrypted(DocumentFile doc, ECKey ecKey, Key key); } |
@Test public void createNodeParitionAlongRightCut() throws Exception { Node<InvariantSpan> left = new Node<>(new InvariantSpan(1, 10, documentHash)); Node<InvariantSpan> right = new Node<>(new InvariantSpan(1, 20, documentHash)); Node<InvariantSpan> root = new Node.Builder<InvariantSpan>(10).left(left).right(right).build(); NodePartition<InvariantSpan> part = Partitioner.createNodePartition(10, root); assertEquals(new InvariantSpan(1, 10, documentHash), part.left.left.value); assertEquals(new InvariantSpan(1, 20, documentHash), part.right.value); } | 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); } |
@Test public void createNodePartitionLeafRoot() throws Exception { Node<InvariantSpan> root = new Node<InvariantSpan>(new InvariantSpan(1, 10, documentHash)); NodePartition<InvariantSpan> part = Partitioner.createNodePartition(5, root); assertEquals(new InvariantSpan(1, 5, documentHash), part.left.value); assertEquals(new InvariantSpan(6, 5, documentHash), part.right.value); } | 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); } |
@Test public void createNodePartitionLinearList() throws Exception { Node<InvariantSpan> a = new Node<>(new InvariantSpan(1, 1, documentHash)); Node<InvariantSpan> b = new Node<>(new InvariantSpan(2, 1, documentHash)); Node<InvariantSpan> c = new Node<>(new InvariantSpan(3, 1, documentHash)); Node<InvariantSpan> d = new Node<>(new InvariantSpan(4, 1, documentHash)); Node<InvariantSpan> e = new Node<>(new InvariantSpan(5, 1, documentHash)); Node<InvariantSpan> f = new Node<>(new InvariantSpan(6, 1, documentHash)); Node<InvariantSpan> g = new Node<>(new InvariantSpan(7, 1, documentHash)); Node<InvariantSpan> h = new Node<>(new InvariantSpan(8, 1, documentHash)); Node<InvariantSpan> ab = new Node.Builder<InvariantSpan>(1).left(a).right(b).build(); Node<InvariantSpan> ac = new Node.Builder<InvariantSpan>(2).left(ab).right(c).build(); Node<InvariantSpan> ad = new Node.Builder<InvariantSpan>(3).left(ac).right(d).build(); Node<InvariantSpan> ae = new Node.Builder<InvariantSpan>(4).left(ad).right(e).build(); Node<InvariantSpan> af = new Node.Builder<InvariantSpan>(5).left(ae).right(f).build(); Node<InvariantSpan> ag = new Node.Builder<InvariantSpan>(6).left(af).right(g).build(); Node<InvariantSpan> ah = new Node.Builder<InvariantSpan>(7).left(ag).right(h).build(); NodePartition<InvariantSpan> part = Partitioner.createNodePartition(2, ah); } | 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); } |
@Test public void createNodePartitionLinearList2() throws Exception { Node<InvariantSpan> a = new Node<>(new InvariantSpan(1, 1, documentHash)); Node<InvariantSpan> b = new Node<>(new InvariantSpan(2, 1, documentHash)); Node<InvariantSpan> c = new Node<>(new InvariantSpan(3, 1, documentHash)); Node<InvariantSpan> d = new Node<>(new InvariantSpan(4, 1, documentHash)); Node<InvariantSpan> ab = new Node.Builder<InvariantSpan>(1).left(a).right(b).build(); Node<InvariantSpan> ac = new Node.Builder<InvariantSpan>(2).left(ab).right(c).build(); Node<InvariantSpan> ac_dummy = new Node.Builder<InvariantSpan>(3).left(ac).build(); Node<InvariantSpan> ad = new Node.Builder<InvariantSpan>(3).left(ac_dummy).right(d).build(); Node<InvariantSpan> root = new Node.Builder<InvariantSpan>(4).left(ad).build(); NodeIndex<InvariantSpan> e = RopeUtils.index(3, root, 0); List<Node<InvariantSpan>> orphans = Partitioner.pruneIndexNode(e.node, 3, e.displacement); } | public static <S extends StreamElement> List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth, long displacement) { if (indexNode.isRightNode()) { if (indexNode.parent.parent != null) { if (indexNode.parent.left != null) { displacement -= indexNode.parent.left.weight; indexNode.parent.parent.isRed = false; } return pruneTree(indexNode.parent.parent, 0, leftPartitionWidth, displacement, indexNode.parent.parent.isRightNode()); } return new ArrayList<>(); } else { return pruneTree(indexNode.parent, 0, leftPartitionWidth, displacement, true); } } | Partitioner { public static <S extends StreamElement> List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth, long displacement) { if (indexNode.isRightNode()) { if (indexNode.parent.parent != null) { if (indexNode.parent.left != null) { displacement -= indexNode.parent.left.weight; indexNode.parent.parent.isRed = false; } return pruneTree(indexNode.parent.parent, 0, leftPartitionWidth, displacement, indexNode.parent.parent.isRightNode()); } return new ArrayList<>(); } else { return pruneTree(indexNode.parent, 0, leftPartitionWidth, displacement, true); } } } | Partitioner { public static <S extends StreamElement> List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth, long displacement) { if (indexNode.isRightNode()) { if (indexNode.parent.parent != null) { if (indexNode.parent.left != null) { displacement -= indexNode.parent.left.weight; indexNode.parent.parent.isRed = false; } return pruneTree(indexNode.parent.parent, 0, leftPartitionWidth, displacement, indexNode.parent.parent.isRightNode()); } return new ArrayList<>(); } else { return pruneTree(indexNode.parent, 0, leftPartitionWidth, displacement, true); } } } | Partitioner { public static <S extends StreamElement> List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth, long displacement) { if (indexNode.isRightNode()) { if (indexNode.parent.parent != null) { if (indexNode.parent.left != null) { displacement -= indexNode.parent.left.weight; indexNode.parent.parent.isRed = false; } return pruneTree(indexNode.parent.parent, 0, leftPartitionWidth, displacement, indexNode.parent.parent.isRightNode()); } return new ArrayList<>(); } else { return pruneTree(indexNode.parent, 0, leftPartitionWidth, displacement, true); } } static NodePartition<T> createNodePartition(long leftPartitionWidth, Node<T> x); static List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth,
long displacement); } | Partitioner { public static <S extends StreamElement> List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth, long displacement) { if (indexNode.isRightNode()) { if (indexNode.parent.parent != null) { if (indexNode.parent.left != null) { displacement -= indexNode.parent.left.weight; indexNode.parent.parent.isRed = false; } return pruneTree(indexNode.parent.parent, 0, leftPartitionWidth, displacement, indexNode.parent.parent.isRightNode()); } return new ArrayList<>(); } else { return pruneTree(indexNode.parent, 0, leftPartitionWidth, displacement, true); } } static NodePartition<T> createNodePartition(long leftPartitionWidth, Node<T> x); static List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth,
long displacement); } |
@Test public void createNodePartitionMiddle() throws Exception { Node<InvariantSpan> a = new Node<>(new InvariantSpan(1, 1, documentHash)); Node<InvariantSpan> b = new Node<>(new InvariantSpan(2, 1, documentHash)); Node<InvariantSpan> c = new Node<>(new InvariantSpan(3, 1, documentHash)); Node<InvariantSpan> d = new Node<>(new InvariantSpan(4, 1, documentHash)); Node<InvariantSpan> ab = new Node.Builder<InvariantSpan>(1).left(a).right(b).build(); Node<InvariantSpan> abc = new Node.Builder<InvariantSpan>(2).left(ab).right(c).build(); Node<InvariantSpan> abcd = new Node.Builder<InvariantSpan>(3).left(abc).right(d).build(); NodePartition<InvariantSpan> part = Partitioner.createNodePartition(1, abcd); Node<InvariantSpan> leftNode = RopeUtils.index(1, part.left, 0).node; assertEquals(new InvariantSpan(1, 1, documentHash), leftNode.value); assertEquals(new InvariantSpan(2, 1, documentHash), RopeUtils.index(1, part.right, 0).node.value); assertEquals(new InvariantSpan(3, 1, documentHash), RopeUtils.index(2, part.right, 0).node.value); assertEquals(new InvariantSpan(4, 1, documentHash), RopeUtils.index(3, part.right, 0).node.value); } | 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); } |
@Test public void createNodePartitionRootBadPosition() throws Exception { NodePartition<InvariantSpan> part = Partitioner.createNodePartition(0, new Node<InvariantSpan>(new InvariantSpan(1, 10, documentHash))); assertEquals(new InvariantSpan(1, 10, documentHash), part.right.value); assertNull(part.left); } | 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); } |
@Test public void createNodePartitionRootBeyondRangePutLeft() throws Exception { NodePartition<InvariantSpan> part = Partitioner.createNodePartition(12, new Node<InvariantSpan>(new InvariantSpan(1, 10, documentHash))); assertEquals(new InvariantSpan(1, 10, documentHash), part.left.value); assertNull(part.right); } | 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); } |
@Test public void createNodePartitionWithRightLeaningIndexNode() throws Exception { Node<InvariantSpan> a = new Node<>(new InvariantSpan(2, 1, documentHash)); Node<InvariantSpan> b = new Node<>(new InvariantSpan(3, 1, documentHash)); Node<InvariantSpan> c = new Node<>(new InvariantSpan(4, 1, documentHash)); Node<InvariantSpan> ab = new Node.Builder<InvariantSpan>(1).left(a).right(b).build(); Node<InvariantSpan> abc = new Node.Builder<InvariantSpan>(2).left(ab).right(c).build(); NodePartition<InvariantSpan> part = Partitioner.createNodePartition(2, abc); assertEquals(new InvariantSpan(2, 1, documentHash), RopeUtils.index(1, part.left, 0).node.value); assertEquals(new InvariantSpan(3, 1, documentHash), RopeUtils.index(2, part.left, 0).node.value); assertEquals(new InvariantSpan(4, 1, documentHash), RopeUtils.index(3, part.right, 0).node.value); } | 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); } |
@Test public void createPartition() throws Exception { Node<InvariantSpan> A = new Node<InvariantSpan>(2); Node<InvariantSpan> B = new Node<>(1); Node<InvariantSpan> C = new Node<>(new InvariantSpan(4, 1, documentHash)); Node<InvariantSpan> D = new Node<>(new InvariantSpan(2, 1, documentHash)); Node<InvariantSpan> E = new Node<>(new InvariantSpan(3, 1, documentHash)); A.tag = "A"; B.tag = "B"; C.tag = "C"; D.tag = "D"; E.tag = "E"; A.left = B; A.right = C; B.left = D; B.right = E; B.parent = A; C.parent = A; D.parent = B; E.parent = B; NodePartition<InvariantSpan> result = Partitioner.createNodePartition(2, A); } | 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); } |
@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); } |
@Test public void encodeDecode() throws Exception { ToggleOverlayOp op = new ToggleOverlayOp(new VariantSpan(100, 1), 10); byte[] data = op.encode(); DataInputStream dis = new DataInputStream(new ByteArrayInputStream(data)); assertEquals(Op.TOGGLE_OVERLAY, dis.readByte()); ToggleOverlayOp decoded = new ToggleOverlayOp(dis); assertEquals(op, decoded); } | @Override public byte[] encode() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(os)) { dos.writeByte(Op.TOGGLE_OVERLAY); dos.writeLong(variantSpan.start); dos.writeLong(variantSpan.width); dos.writeInt(linkTypeIndex); } os.flush(); return os.toByteArray(); } | ToggleOverlayOp extends Op { @Override public byte[] encode() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(os)) { dos.writeByte(Op.TOGGLE_OVERLAY); dos.writeLong(variantSpan.start); dos.writeLong(variantSpan.width); dos.writeInt(linkTypeIndex); } os.flush(); return os.toByteArray(); } } | ToggleOverlayOp extends Op { @Override public byte[] encode() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(os)) { dos.writeByte(Op.TOGGLE_OVERLAY); dos.writeLong(variantSpan.start); dos.writeLong(variantSpan.width); dos.writeInt(linkTypeIndex); } os.flush(); return os.toByteArray(); } ToggleOverlayOp(DataInputStream dis); ToggleOverlayOp(VariantSpan variantSpan, int linkTypeIndex); } | ToggleOverlayOp extends Op { @Override public byte[] encode() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(os)) { dos.writeByte(Op.TOGGLE_OVERLAY); dos.writeLong(variantSpan.start); dos.writeLong(variantSpan.width); dos.writeInt(linkTypeIndex); } os.flush(); return os.toByteArray(); } ToggleOverlayOp(DataInputStream dis); ToggleOverlayOp(VariantSpan variantSpan, int linkTypeIndex); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); } | ToggleOverlayOp extends Op { @Override public byte[] encode() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(os)) { dos.writeByte(Op.TOGGLE_OVERLAY); dos.writeLong(variantSpan.start); dos.writeLong(variantSpan.width); dos.writeInt(linkTypeIndex); } os.flush(); return os.toByteArray(); } ToggleOverlayOp(DataInputStream dis); ToggleOverlayOp(VariantSpan variantSpan, int linkTypeIndex); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); final int linkTypeIndex; final VariantSpan variantSpan; } |
@Test(expected = IllegalStateException.class) public void partitionNullRoot() 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); } |
@Test public void prune() throws Exception { Node<InvariantSpan> a = new Node<>(new InvariantSpan(300, 4, documentHash)); Node<InvariantSpan> b = new Node<>(new InvariantSpan(350, 1, documentHash)); Node<InvariantSpan> c = new Node<>(new InvariantSpan(360, 1, documentHash)); Node<InvariantSpan> d = new Node<>(new InvariantSpan(361, 5, documentHash)); d.tag = "d"; Node<InvariantSpan> cd = new Node.Builder<InvariantSpan>(1).left(c).right(d).tag("cd").build(); Node<InvariantSpan> bcd = new Node.Builder<InvariantSpan>(1).left(b).right(cd).tag("bcd").build(); Node<InvariantSpan> abcd = new Node.Builder<InvariantSpan>(4).left(a).right(bcd).tag("abcd").build(); NodeIndex<InvariantSpan> cIndex = RopeUtils.index(6, abcd, 0); List<Node<InvariantSpan>> orphans = Partitioner.pruneIndexNode(cIndex.node, 6, cIndex.displacement); assertEquals(1, orphans.size()); assertEquals("d", orphans.get(0).tag); } | public static <S extends StreamElement> List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth, long displacement) { if (indexNode.isRightNode()) { if (indexNode.parent.parent != null) { if (indexNode.parent.left != null) { displacement -= indexNode.parent.left.weight; indexNode.parent.parent.isRed = false; } return pruneTree(indexNode.parent.parent, 0, leftPartitionWidth, displacement, indexNode.parent.parent.isRightNode()); } return new ArrayList<>(); } else { return pruneTree(indexNode.parent, 0, leftPartitionWidth, displacement, true); } } | Partitioner { public static <S extends StreamElement> List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth, long displacement) { if (indexNode.isRightNode()) { if (indexNode.parent.parent != null) { if (indexNode.parent.left != null) { displacement -= indexNode.parent.left.weight; indexNode.parent.parent.isRed = false; } return pruneTree(indexNode.parent.parent, 0, leftPartitionWidth, displacement, indexNode.parent.parent.isRightNode()); } return new ArrayList<>(); } else { return pruneTree(indexNode.parent, 0, leftPartitionWidth, displacement, true); } } } | Partitioner { public static <S extends StreamElement> List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth, long displacement) { if (indexNode.isRightNode()) { if (indexNode.parent.parent != null) { if (indexNode.parent.left != null) { displacement -= indexNode.parent.left.weight; indexNode.parent.parent.isRed = false; } return pruneTree(indexNode.parent.parent, 0, leftPartitionWidth, displacement, indexNode.parent.parent.isRightNode()); } return new ArrayList<>(); } else { return pruneTree(indexNode.parent, 0, leftPartitionWidth, displacement, true); } } } | Partitioner { public static <S extends StreamElement> List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth, long displacement) { if (indexNode.isRightNode()) { if (indexNode.parent.parent != null) { if (indexNode.parent.left != null) { displacement -= indexNode.parent.left.weight; indexNode.parent.parent.isRed = false; } return pruneTree(indexNode.parent.parent, 0, leftPartitionWidth, displacement, indexNode.parent.parent.isRightNode()); } return new ArrayList<>(); } else { return pruneTree(indexNode.parent, 0, leftPartitionWidth, displacement, true); } } static NodePartition<T> createNodePartition(long leftPartitionWidth, Node<T> x); static List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth,
long displacement); } | Partitioner { public static <S extends StreamElement> List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth, long displacement) { if (indexNode.isRightNode()) { if (indexNode.parent.parent != null) { if (indexNode.parent.left != null) { displacement -= indexNode.parent.left.weight; indexNode.parent.parent.isRed = false; } return pruneTree(indexNode.parent.parent, 0, leftPartitionWidth, displacement, indexNode.parent.parent.isRightNode()); } return new ArrayList<>(); } else { return pruneTree(indexNode.parent, 0, leftPartitionWidth, displacement, true); } } static NodePartition<T> createNodePartition(long leftPartitionWidth, Node<T> x); static List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth,
long displacement); } |
@Test public void prune11() throws Exception { Node<InvariantSpan> root = getA(); NodeIndex<InvariantSpan> j = RopeUtils.index(11, root, 0); List<Node<InvariantSpan>> orphans = Partitioner.pruneIndexNode(j.node, 11, j.displacement); assertEquals(2, orphans.size()); assertEquals("K", orphans.get(0).tag); assertEquals("H", orphans.get(1).tag); Node<InvariantSpan> resultRoot = RopeUtils.findRoot(j.node); assertEquals(9, resultRoot.left.weight); assertEquals(11, resultRoot.weight); } | public static <S extends StreamElement> List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth, long displacement) { if (indexNode.isRightNode()) { if (indexNode.parent.parent != null) { if (indexNode.parent.left != null) { displacement -= indexNode.parent.left.weight; indexNode.parent.parent.isRed = false; } return pruneTree(indexNode.parent.parent, 0, leftPartitionWidth, displacement, indexNode.parent.parent.isRightNode()); } return new ArrayList<>(); } else { return pruneTree(indexNode.parent, 0, leftPartitionWidth, displacement, true); } } | Partitioner { public static <S extends StreamElement> List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth, long displacement) { if (indexNode.isRightNode()) { if (indexNode.parent.parent != null) { if (indexNode.parent.left != null) { displacement -= indexNode.parent.left.weight; indexNode.parent.parent.isRed = false; } return pruneTree(indexNode.parent.parent, 0, leftPartitionWidth, displacement, indexNode.parent.parent.isRightNode()); } return new ArrayList<>(); } else { return pruneTree(indexNode.parent, 0, leftPartitionWidth, displacement, true); } } } | Partitioner { public static <S extends StreamElement> List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth, long displacement) { if (indexNode.isRightNode()) { if (indexNode.parent.parent != null) { if (indexNode.parent.left != null) { displacement -= indexNode.parent.left.weight; indexNode.parent.parent.isRed = false; } return pruneTree(indexNode.parent.parent, 0, leftPartitionWidth, displacement, indexNode.parent.parent.isRightNode()); } return new ArrayList<>(); } else { return pruneTree(indexNode.parent, 0, leftPartitionWidth, displacement, true); } } } | Partitioner { public static <S extends StreamElement> List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth, long displacement) { if (indexNode.isRightNode()) { if (indexNode.parent.parent != null) { if (indexNode.parent.left != null) { displacement -= indexNode.parent.left.weight; indexNode.parent.parent.isRed = false; } return pruneTree(indexNode.parent.parent, 0, leftPartitionWidth, displacement, indexNode.parent.parent.isRightNode()); } return new ArrayList<>(); } else { return pruneTree(indexNode.parent, 0, leftPartitionWidth, displacement, true); } } static NodePartition<T> createNodePartition(long leftPartitionWidth, Node<T> x); static List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth,
long displacement); } | Partitioner { public static <S extends StreamElement> List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth, long displacement) { if (indexNode.isRightNode()) { if (indexNode.parent.parent != null) { if (indexNode.parent.left != null) { displacement -= indexNode.parent.left.weight; indexNode.parent.parent.isRed = false; } return pruneTree(indexNode.parent.parent, 0, leftPartitionWidth, displacement, indexNode.parent.parent.isRightNode()); } return new ArrayList<>(); } else { return pruneTree(indexNode.parent, 0, leftPartitionWidth, displacement, true); } } static NodePartition<T> createNodePartition(long leftPartitionWidth, Node<T> x); static List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth,
long displacement); } |
@Test public void prune6() throws Exception { Node<InvariantSpan> root = getA(); NodeIndex<InvariantSpan> e = RopeUtils.index(6, root, 0); List<Node<InvariantSpan>> orphans = Partitioner.pruneIndexNode(e.node, 6, e.displacement); assertEquals(2, orphans.size()); assertEquals("F", orphans.get(0).tag); assertEquals("D", orphans.get(1).tag); assertEquals(6, root.left.weight); assertEquals(6, root.weight); } | public static <S extends StreamElement> List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth, long displacement) { if (indexNode.isRightNode()) { if (indexNode.parent.parent != null) { if (indexNode.parent.left != null) { displacement -= indexNode.parent.left.weight; indexNode.parent.parent.isRed = false; } return pruneTree(indexNode.parent.parent, 0, leftPartitionWidth, displacement, indexNode.parent.parent.isRightNode()); } return new ArrayList<>(); } else { return pruneTree(indexNode.parent, 0, leftPartitionWidth, displacement, true); } } | Partitioner { public static <S extends StreamElement> List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth, long displacement) { if (indexNode.isRightNode()) { if (indexNode.parent.parent != null) { if (indexNode.parent.left != null) { displacement -= indexNode.parent.left.weight; indexNode.parent.parent.isRed = false; } return pruneTree(indexNode.parent.parent, 0, leftPartitionWidth, displacement, indexNode.parent.parent.isRightNode()); } return new ArrayList<>(); } else { return pruneTree(indexNode.parent, 0, leftPartitionWidth, displacement, true); } } } | Partitioner { public static <S extends StreamElement> List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth, long displacement) { if (indexNode.isRightNode()) { if (indexNode.parent.parent != null) { if (indexNode.parent.left != null) { displacement -= indexNode.parent.left.weight; indexNode.parent.parent.isRed = false; } return pruneTree(indexNode.parent.parent, 0, leftPartitionWidth, displacement, indexNode.parent.parent.isRightNode()); } return new ArrayList<>(); } else { return pruneTree(indexNode.parent, 0, leftPartitionWidth, displacement, true); } } } | Partitioner { public static <S extends StreamElement> List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth, long displacement) { if (indexNode.isRightNode()) { if (indexNode.parent.parent != null) { if (indexNode.parent.left != null) { displacement -= indexNode.parent.left.weight; indexNode.parent.parent.isRed = false; } return pruneTree(indexNode.parent.parent, 0, leftPartitionWidth, displacement, indexNode.parent.parent.isRightNode()); } return new ArrayList<>(); } else { return pruneTree(indexNode.parent, 0, leftPartitionWidth, displacement, true); } } static NodePartition<T> createNodePartition(long leftPartitionWidth, Node<T> x); static List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth,
long displacement); } | Partitioner { public static <S extends StreamElement> List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth, long displacement) { if (indexNode.isRightNode()) { if (indexNode.parent.parent != null) { if (indexNode.parent.left != null) { displacement -= indexNode.parent.left.weight; indexNode.parent.parent.isRed = false; } return pruneTree(indexNode.parent.parent, 0, leftPartitionWidth, displacement, indexNode.parent.parent.isRightNode()); } return new ArrayList<>(); } else { return pruneTree(indexNode.parent, 0, leftPartitionWidth, displacement, true); } } static NodePartition<T> createNodePartition(long leftPartitionWidth, Node<T> x); static List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth,
long displacement); } |
@Test public void prune9() throws Exception { Node<InvariantSpan> root = getA(); NodeIndex<InvariantSpan> f = RopeUtils.index(9, root, 0); List<Node<InvariantSpan>> orphans = Partitioner.pruneIndexNode(f.node, 9, f.displacement); assertEquals(1, orphans.size()); assertEquals("D", orphans.get(0).tag); assertEquals(9, root.weight); } | public static <S extends StreamElement> List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth, long displacement) { if (indexNode.isRightNode()) { if (indexNode.parent.parent != null) { if (indexNode.parent.left != null) { displacement -= indexNode.parent.left.weight; indexNode.parent.parent.isRed = false; } return pruneTree(indexNode.parent.parent, 0, leftPartitionWidth, displacement, indexNode.parent.parent.isRightNode()); } return new ArrayList<>(); } else { return pruneTree(indexNode.parent, 0, leftPartitionWidth, displacement, true); } } | Partitioner { public static <S extends StreamElement> List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth, long displacement) { if (indexNode.isRightNode()) { if (indexNode.parent.parent != null) { if (indexNode.parent.left != null) { displacement -= indexNode.parent.left.weight; indexNode.parent.parent.isRed = false; } return pruneTree(indexNode.parent.parent, 0, leftPartitionWidth, displacement, indexNode.parent.parent.isRightNode()); } return new ArrayList<>(); } else { return pruneTree(indexNode.parent, 0, leftPartitionWidth, displacement, true); } } } | Partitioner { public static <S extends StreamElement> List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth, long displacement) { if (indexNode.isRightNode()) { if (indexNode.parent.parent != null) { if (indexNode.parent.left != null) { displacement -= indexNode.parent.left.weight; indexNode.parent.parent.isRed = false; } return pruneTree(indexNode.parent.parent, 0, leftPartitionWidth, displacement, indexNode.parent.parent.isRightNode()); } return new ArrayList<>(); } else { return pruneTree(indexNode.parent, 0, leftPartitionWidth, displacement, true); } } } | Partitioner { public static <S extends StreamElement> List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth, long displacement) { if (indexNode.isRightNode()) { if (indexNode.parent.parent != null) { if (indexNode.parent.left != null) { displacement -= indexNode.parent.left.weight; indexNode.parent.parent.isRed = false; } return pruneTree(indexNode.parent.parent, 0, leftPartitionWidth, displacement, indexNode.parent.parent.isRightNode()); } return new ArrayList<>(); } else { return pruneTree(indexNode.parent, 0, leftPartitionWidth, displacement, true); } } static NodePartition<T> createNodePartition(long leftPartitionWidth, Node<T> x); static List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth,
long displacement); } | Partitioner { public static <S extends StreamElement> List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth, long displacement) { if (indexNode.isRightNode()) { if (indexNode.parent.parent != null) { if (indexNode.parent.left != null) { displacement -= indexNode.parent.left.weight; indexNode.parent.parent.isRed = false; } return pruneTree(indexNode.parent.parent, 0, leftPartitionWidth, displacement, indexNode.parent.parent.isRightNode()); } return new ArrayList<>(); } else { return pruneTree(indexNode.parent, 0, leftPartitionWidth, displacement, true); } } static NodePartition<T> createNodePartition(long leftPartitionWidth, Node<T> x); static List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth,
long displacement); } |
@Test public void pruneNullLeft() throws Exception { Node<InvariantSpan> right = new Node<>(new InvariantSpan(2, 1, documentHash)); new Node.Builder<InvariantSpan>(0).right(right).build(); List<Node<InvariantSpan>> orphans = Partitioner.pruneIndexNode(right, 1, 0); assertEquals(0, orphans.size()); } | public static <S extends StreamElement> List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth, long displacement) { if (indexNode.isRightNode()) { if (indexNode.parent.parent != null) { if (indexNode.parent.left != null) { displacement -= indexNode.parent.left.weight; indexNode.parent.parent.isRed = false; } return pruneTree(indexNode.parent.parent, 0, leftPartitionWidth, displacement, indexNode.parent.parent.isRightNode()); } return new ArrayList<>(); } else { return pruneTree(indexNode.parent, 0, leftPartitionWidth, displacement, true); } } | Partitioner { public static <S extends StreamElement> List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth, long displacement) { if (indexNode.isRightNode()) { if (indexNode.parent.parent != null) { if (indexNode.parent.left != null) { displacement -= indexNode.parent.left.weight; indexNode.parent.parent.isRed = false; } return pruneTree(indexNode.parent.parent, 0, leftPartitionWidth, displacement, indexNode.parent.parent.isRightNode()); } return new ArrayList<>(); } else { return pruneTree(indexNode.parent, 0, leftPartitionWidth, displacement, true); } } } | Partitioner { public static <S extends StreamElement> List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth, long displacement) { if (indexNode.isRightNode()) { if (indexNode.parent.parent != null) { if (indexNode.parent.left != null) { displacement -= indexNode.parent.left.weight; indexNode.parent.parent.isRed = false; } return pruneTree(indexNode.parent.parent, 0, leftPartitionWidth, displacement, indexNode.parent.parent.isRightNode()); } return new ArrayList<>(); } else { return pruneTree(indexNode.parent, 0, leftPartitionWidth, displacement, true); } } } | Partitioner { public static <S extends StreamElement> List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth, long displacement) { if (indexNode.isRightNode()) { if (indexNode.parent.parent != null) { if (indexNode.parent.left != null) { displacement -= indexNode.parent.left.weight; indexNode.parent.parent.isRed = false; } return pruneTree(indexNode.parent.parent, 0, leftPartitionWidth, displacement, indexNode.parent.parent.isRightNode()); } return new ArrayList<>(); } else { return pruneTree(indexNode.parent, 0, leftPartitionWidth, displacement, true); } } static NodePartition<T> createNodePartition(long leftPartitionWidth, Node<T> x); static List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth,
long displacement); } | Partitioner { public static <S extends StreamElement> List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth, long displacement) { if (indexNode.isRightNode()) { if (indexNode.parent.parent != null) { if (indexNode.parent.left != null) { displacement -= indexNode.parent.left.weight; indexNode.parent.parent.isRed = false; } return pruneTree(indexNode.parent.parent, 0, leftPartitionWidth, displacement, indexNode.parent.parent.isRightNode()); } return new ArrayList<>(); } else { return pruneTree(indexNode.parent, 0, leftPartitionWidth, displacement, true); } } static NodePartition<T> createNodePartition(long leftPartitionWidth, Node<T> x); static List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth,
long displacement); } |
@Test public void pruneNullRight() throws Exception { Node<InvariantSpan> left = new Node<>(new InvariantSpan(1, 1, documentHash)); new Node.Builder<InvariantSpan>(1).left(left).build(); List<Node<InvariantSpan>> orphans = Partitioner.pruneIndexNode(left, 1, 0); assertEquals(0, orphans.size()); } | public static <S extends StreamElement> List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth, long displacement) { if (indexNode.isRightNode()) { if (indexNode.parent.parent != null) { if (indexNode.parent.left != null) { displacement -= indexNode.parent.left.weight; indexNode.parent.parent.isRed = false; } return pruneTree(indexNode.parent.parent, 0, leftPartitionWidth, displacement, indexNode.parent.parent.isRightNode()); } return new ArrayList<>(); } else { return pruneTree(indexNode.parent, 0, leftPartitionWidth, displacement, true); } } | Partitioner { public static <S extends StreamElement> List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth, long displacement) { if (indexNode.isRightNode()) { if (indexNode.parent.parent != null) { if (indexNode.parent.left != null) { displacement -= indexNode.parent.left.weight; indexNode.parent.parent.isRed = false; } return pruneTree(indexNode.parent.parent, 0, leftPartitionWidth, displacement, indexNode.parent.parent.isRightNode()); } return new ArrayList<>(); } else { return pruneTree(indexNode.parent, 0, leftPartitionWidth, displacement, true); } } } | Partitioner { public static <S extends StreamElement> List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth, long displacement) { if (indexNode.isRightNode()) { if (indexNode.parent.parent != null) { if (indexNode.parent.left != null) { displacement -= indexNode.parent.left.weight; indexNode.parent.parent.isRed = false; } return pruneTree(indexNode.parent.parent, 0, leftPartitionWidth, displacement, indexNode.parent.parent.isRightNode()); } return new ArrayList<>(); } else { return pruneTree(indexNode.parent, 0, leftPartitionWidth, displacement, true); } } } | Partitioner { public static <S extends StreamElement> List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth, long displacement) { if (indexNode.isRightNode()) { if (indexNode.parent.parent != null) { if (indexNode.parent.left != null) { displacement -= indexNode.parent.left.weight; indexNode.parent.parent.isRed = false; } return pruneTree(indexNode.parent.parent, 0, leftPartitionWidth, displacement, indexNode.parent.parent.isRightNode()); } return new ArrayList<>(); } else { return pruneTree(indexNode.parent, 0, leftPartitionWidth, displacement, true); } } static NodePartition<T> createNodePartition(long leftPartitionWidth, Node<T> x); static List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth,
long displacement); } | Partitioner { public static <S extends StreamElement> List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth, long displacement) { if (indexNode.isRightNode()) { if (indexNode.parent.parent != null) { if (indexNode.parent.left != null) { displacement -= indexNode.parent.left.weight; indexNode.parent.parent.isRed = false; } return pruneTree(indexNode.parent.parent, 0, leftPartitionWidth, displacement, indexNode.parent.parent.isRightNode()); } return new ArrayList<>(); } else { return pruneTree(indexNode.parent, 0, leftPartitionWidth, displacement, true); } } static NodePartition<T> createNodePartition(long leftPartitionWidth, Node<T> x); static List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth,
long displacement); } |
@Test public void pruneRight() throws Exception { Node<InvariantSpan> left = new Node<>(new InvariantSpan(1, 1, documentHash)); Node<InvariantSpan> right = new Node<>(1); right.left = new Node<InvariantSpan>(new InvariantSpan(50, 1, documentHash)); right.right = new Node<InvariantSpan>(new InvariantSpan(100, 1, documentHash)); right.tag = "RGHT"; new Node.Builder<InvariantSpan>(1).left(left).right(right).build(); List<Node<InvariantSpan>> orphans = Partitioner.pruneIndexNode(left, 1, 0); assertEquals(1, orphans.size()); assertEquals("RGHT", orphans.get(0).tag); } | public static <S extends StreamElement> List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth, long displacement) { if (indexNode.isRightNode()) { if (indexNode.parent.parent != null) { if (indexNode.parent.left != null) { displacement -= indexNode.parent.left.weight; indexNode.parent.parent.isRed = false; } return pruneTree(indexNode.parent.parent, 0, leftPartitionWidth, displacement, indexNode.parent.parent.isRightNode()); } return new ArrayList<>(); } else { return pruneTree(indexNode.parent, 0, leftPartitionWidth, displacement, true); } } | Partitioner { public static <S extends StreamElement> List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth, long displacement) { if (indexNode.isRightNode()) { if (indexNode.parent.parent != null) { if (indexNode.parent.left != null) { displacement -= indexNode.parent.left.weight; indexNode.parent.parent.isRed = false; } return pruneTree(indexNode.parent.parent, 0, leftPartitionWidth, displacement, indexNode.parent.parent.isRightNode()); } return new ArrayList<>(); } else { return pruneTree(indexNode.parent, 0, leftPartitionWidth, displacement, true); } } } | Partitioner { public static <S extends StreamElement> List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth, long displacement) { if (indexNode.isRightNode()) { if (indexNode.parent.parent != null) { if (indexNode.parent.left != null) { displacement -= indexNode.parent.left.weight; indexNode.parent.parent.isRed = false; } return pruneTree(indexNode.parent.parent, 0, leftPartitionWidth, displacement, indexNode.parent.parent.isRightNode()); } return new ArrayList<>(); } else { return pruneTree(indexNode.parent, 0, leftPartitionWidth, displacement, true); } } } | Partitioner { public static <S extends StreamElement> List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth, long displacement) { if (indexNode.isRightNode()) { if (indexNode.parent.parent != null) { if (indexNode.parent.left != null) { displacement -= indexNode.parent.left.weight; indexNode.parent.parent.isRed = false; } return pruneTree(indexNode.parent.parent, 0, leftPartitionWidth, displacement, indexNode.parent.parent.isRightNode()); } return new ArrayList<>(); } else { return pruneTree(indexNode.parent, 0, leftPartitionWidth, displacement, true); } } static NodePartition<T> createNodePartition(long leftPartitionWidth, Node<T> x); static List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth,
long displacement); } | Partitioner { public static <S extends StreamElement> List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth, long displacement) { if (indexNode.isRightNode()) { if (indexNode.parent.parent != null) { if (indexNode.parent.left != null) { displacement -= indexNode.parent.left.weight; indexNode.parent.parent.isRed = false; } return pruneTree(indexNode.parent.parent, 0, leftPartitionWidth, displacement, indexNode.parent.parent.isRightNode()); } return new ArrayList<>(); } else { return pruneTree(indexNode.parent, 0, leftPartitionWidth, displacement, true); } } static NodePartition<T> createNodePartition(long leftPartitionWidth, Node<T> x); static List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth,
long displacement); } |
@Test public void pruneRight2() throws Exception { Node<InvariantSpan> left = new Node<>(new InvariantSpan(1, 4, documentHash)); Node<InvariantSpan> right = new Node<>(new InvariantSpan(1, 20, documentHash)); new Node.Builder<InvariantSpan>(4).left(left).right(right).build(); List<Node<InvariantSpan>> orphans = Partitioner.pruneIndexNode(left, 4, 0); assertEquals(1, orphans.size()); assertEquals(new InvariantSpan(1, 20, documentHash), orphans.get(0).value); } | public static <S extends StreamElement> List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth, long displacement) { if (indexNode.isRightNode()) { if (indexNode.parent.parent != null) { if (indexNode.parent.left != null) { displacement -= indexNode.parent.left.weight; indexNode.parent.parent.isRed = false; } return pruneTree(indexNode.parent.parent, 0, leftPartitionWidth, displacement, indexNode.parent.parent.isRightNode()); } return new ArrayList<>(); } else { return pruneTree(indexNode.parent, 0, leftPartitionWidth, displacement, true); } } | Partitioner { public static <S extends StreamElement> List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth, long displacement) { if (indexNode.isRightNode()) { if (indexNode.parent.parent != null) { if (indexNode.parent.left != null) { displacement -= indexNode.parent.left.weight; indexNode.parent.parent.isRed = false; } return pruneTree(indexNode.parent.parent, 0, leftPartitionWidth, displacement, indexNode.parent.parent.isRightNode()); } return new ArrayList<>(); } else { return pruneTree(indexNode.parent, 0, leftPartitionWidth, displacement, true); } } } | Partitioner { public static <S extends StreamElement> List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth, long displacement) { if (indexNode.isRightNode()) { if (indexNode.parent.parent != null) { if (indexNode.parent.left != null) { displacement -= indexNode.parent.left.weight; indexNode.parent.parent.isRed = false; } return pruneTree(indexNode.parent.parent, 0, leftPartitionWidth, displacement, indexNode.parent.parent.isRightNode()); } return new ArrayList<>(); } else { return pruneTree(indexNode.parent, 0, leftPartitionWidth, displacement, true); } } } | Partitioner { public static <S extends StreamElement> List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth, long displacement) { if (indexNode.isRightNode()) { if (indexNode.parent.parent != null) { if (indexNode.parent.left != null) { displacement -= indexNode.parent.left.weight; indexNode.parent.parent.isRed = false; } return pruneTree(indexNode.parent.parent, 0, leftPartitionWidth, displacement, indexNode.parent.parent.isRightNode()); } return new ArrayList<>(); } else { return pruneTree(indexNode.parent, 0, leftPartitionWidth, displacement, true); } } static NodePartition<T> createNodePartition(long leftPartitionWidth, Node<T> x); static List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth,
long displacement); } | Partitioner { public static <S extends StreamElement> List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth, long displacement) { if (indexNode.isRightNode()) { if (indexNode.parent.parent != null) { if (indexNode.parent.left != null) { displacement -= indexNode.parent.left.weight; indexNode.parent.parent.isRed = false; } return pruneTree(indexNode.parent.parent, 0, leftPartitionWidth, displacement, indexNode.parent.parent.isRightNode()); } return new ArrayList<>(); } else { return pruneTree(indexNode.parent, 0, leftPartitionWidth, displacement, true); } } static NodePartition<T> createNodePartition(long leftPartitionWidth, Node<T> x); static List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth,
long displacement); } |
@Test public void pruneRightWithNoChildLeft() throws Exception { Node<InvariantSpan> left = new Node<>(new InvariantSpan(1, 1, documentHash)); Node<InvariantSpan> right = new Node<>(1); right.right = new Node<InvariantSpan>(new InvariantSpan(100, 1, documentHash)); right.tag = "RGHT"; new Node.Builder<InvariantSpan>(1).left(left).right(right).build(); List<Node<InvariantSpan>> orphans = Partitioner.pruneIndexNode(left, 1, 0); assertEquals(1, orphans.size()); assertEquals("RGHT", orphans.get(0).tag); assertNull(orphans.get(0).left); assertNotNull(orphans.get(0).right); } | public static <S extends StreamElement> List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth, long displacement) { if (indexNode.isRightNode()) { if (indexNode.parent.parent != null) { if (indexNode.parent.left != null) { displacement -= indexNode.parent.left.weight; indexNode.parent.parent.isRed = false; } return pruneTree(indexNode.parent.parent, 0, leftPartitionWidth, displacement, indexNode.parent.parent.isRightNode()); } return new ArrayList<>(); } else { return pruneTree(indexNode.parent, 0, leftPartitionWidth, displacement, true); } } | Partitioner { public static <S extends StreamElement> List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth, long displacement) { if (indexNode.isRightNode()) { if (indexNode.parent.parent != null) { if (indexNode.parent.left != null) { displacement -= indexNode.parent.left.weight; indexNode.parent.parent.isRed = false; } return pruneTree(indexNode.parent.parent, 0, leftPartitionWidth, displacement, indexNode.parent.parent.isRightNode()); } return new ArrayList<>(); } else { return pruneTree(indexNode.parent, 0, leftPartitionWidth, displacement, true); } } } | Partitioner { public static <S extends StreamElement> List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth, long displacement) { if (indexNode.isRightNode()) { if (indexNode.parent.parent != null) { if (indexNode.parent.left != null) { displacement -= indexNode.parent.left.weight; indexNode.parent.parent.isRed = false; } return pruneTree(indexNode.parent.parent, 0, leftPartitionWidth, displacement, indexNode.parent.parent.isRightNode()); } return new ArrayList<>(); } else { return pruneTree(indexNode.parent, 0, leftPartitionWidth, displacement, true); } } } | Partitioner { public static <S extends StreamElement> List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth, long displacement) { if (indexNode.isRightNode()) { if (indexNode.parent.parent != null) { if (indexNode.parent.left != null) { displacement -= indexNode.parent.left.weight; indexNode.parent.parent.isRed = false; } return pruneTree(indexNode.parent.parent, 0, leftPartitionWidth, displacement, indexNode.parent.parent.isRightNode()); } return new ArrayList<>(); } else { return pruneTree(indexNode.parent, 0, leftPartitionWidth, displacement, true); } } static NodePartition<T> createNodePartition(long leftPartitionWidth, Node<T> x); static List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth,
long displacement); } | Partitioner { public static <S extends StreamElement> List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth, long displacement) { if (indexNode.isRightNode()) { if (indexNode.parent.parent != null) { if (indexNode.parent.left != null) { displacement -= indexNode.parent.left.weight; indexNode.parent.parent.isRed = false; } return pruneTree(indexNode.parent.parent, 0, leftPartitionWidth, displacement, indexNode.parent.parent.isRightNode()); } return new ArrayList<>(); } else { return pruneTree(indexNode.parent, 0, leftPartitionWidth, displacement, true); } } static NodePartition<T> createNodePartition(long leftPartitionWidth, Node<T> x); static List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth,
long displacement); } |
@Test public void encode() throws Exception { ApplyOverlayOp op = new ApplyOverlayOp(new VariantSpan(1, 100), Sets.newHashSet(1, 10)); byte[] data = op.encode(); DataInputStream dis = new DataInputStream(new ByteArrayInputStream(data)); assertEquals(Op.APPLY_OVERLAY, dis.read()); assertEquals(1, dis.readLong()); assertEquals(100, dis.readLong()); assertEquals(2, dis.readInt()); assertEquals(1, dis.readInt()); assertEquals(10, dis.readInt()); } | @Override public byte[] encode() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(os)) { dos.writeByte(Op.APPLY_OVERLAY); dos.writeLong(variantSpan.start); dos.writeLong(variantSpan.width); dos.writeInt(linkTypes.size()); for (Integer i : linkTypes) { if (i < 0) { throw new IOException("Tumbler pool index must be 0 or greater: " + i); } dos.writeInt(i); } } os.flush(); return os.toByteArray(); } | ApplyOverlayOp extends Op { @Override public byte[] encode() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(os)) { dos.writeByte(Op.APPLY_OVERLAY); dos.writeLong(variantSpan.start); dos.writeLong(variantSpan.width); dos.writeInt(linkTypes.size()); for (Integer i : linkTypes) { if (i < 0) { throw new IOException("Tumbler pool index must be 0 or greater: " + i); } dos.writeInt(i); } } os.flush(); return os.toByteArray(); } } | ApplyOverlayOp extends Op { @Override public byte[] encode() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(os)) { dos.writeByte(Op.APPLY_OVERLAY); dos.writeLong(variantSpan.start); dos.writeLong(variantSpan.width); dos.writeInt(linkTypes.size()); for (Integer i : linkTypes) { if (i < 0) { throw new IOException("Tumbler pool index must be 0 or greater: " + i); } dos.writeInt(i); } } os.flush(); return os.toByteArray(); } ApplyOverlayOp(DataInputStream dis); ApplyOverlayOp(VariantSpan variantSpan, Set<Integer> linkTypes); } | ApplyOverlayOp extends Op { @Override public byte[] encode() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(os)) { dos.writeByte(Op.APPLY_OVERLAY); dos.writeLong(variantSpan.start); dos.writeLong(variantSpan.width); dos.writeInt(linkTypes.size()); for (Integer i : linkTypes) { if (i < 0) { throw new IOException("Tumbler pool index must be 0 or greater: " + i); } dos.writeInt(i); } } os.flush(); return os.toByteArray(); } ApplyOverlayOp(DataInputStream dis); ApplyOverlayOp(VariantSpan variantSpan, Set<Integer> linkTypes); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); } | ApplyOverlayOp extends Op { @Override public byte[] encode() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(os)) { dos.writeByte(Op.APPLY_OVERLAY); dos.writeLong(variantSpan.start); dos.writeLong(variantSpan.width); dos.writeInt(linkTypes.size()); for (Integer i : linkTypes) { if (i < 0) { throw new IOException("Tumbler pool index must be 0 or greater: " + i); } dos.writeInt(i); } } os.flush(); return os.toByteArray(); } ApplyOverlayOp(DataInputStream dis); ApplyOverlayOp(VariantSpan variantSpan, Set<Integer> linkTypes); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); final Set<Integer> linkTypes; final VariantSpan variantSpan; } |
@Test public void pruneSimpleRight() throws Exception { Node<InvariantSpan> left = new Node<>(new InvariantSpan(1, 1, documentHash)); Node<InvariantSpan> right = new Node<>(new InvariantSpan(2, 1, documentHash)); new Node.Builder<InvariantSpan>(1).left(left).right(right).build(); List<Node<InvariantSpan>> orphans = Partitioner.pruneIndexNode(right, 2, 1); assertEquals(0, orphans.size()); } | public static <S extends StreamElement> List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth, long displacement) { if (indexNode.isRightNode()) { if (indexNode.parent.parent != null) { if (indexNode.parent.left != null) { displacement -= indexNode.parent.left.weight; indexNode.parent.parent.isRed = false; } return pruneTree(indexNode.parent.parent, 0, leftPartitionWidth, displacement, indexNode.parent.parent.isRightNode()); } return new ArrayList<>(); } else { return pruneTree(indexNode.parent, 0, leftPartitionWidth, displacement, true); } } | Partitioner { public static <S extends StreamElement> List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth, long displacement) { if (indexNode.isRightNode()) { if (indexNode.parent.parent != null) { if (indexNode.parent.left != null) { displacement -= indexNode.parent.left.weight; indexNode.parent.parent.isRed = false; } return pruneTree(indexNode.parent.parent, 0, leftPartitionWidth, displacement, indexNode.parent.parent.isRightNode()); } return new ArrayList<>(); } else { return pruneTree(indexNode.parent, 0, leftPartitionWidth, displacement, true); } } } | Partitioner { public static <S extends StreamElement> List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth, long displacement) { if (indexNode.isRightNode()) { if (indexNode.parent.parent != null) { if (indexNode.parent.left != null) { displacement -= indexNode.parent.left.weight; indexNode.parent.parent.isRed = false; } return pruneTree(indexNode.parent.parent, 0, leftPartitionWidth, displacement, indexNode.parent.parent.isRightNode()); } return new ArrayList<>(); } else { return pruneTree(indexNode.parent, 0, leftPartitionWidth, displacement, true); } } } | Partitioner { public static <S extends StreamElement> List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth, long displacement) { if (indexNode.isRightNode()) { if (indexNode.parent.parent != null) { if (indexNode.parent.left != null) { displacement -= indexNode.parent.left.weight; indexNode.parent.parent.isRed = false; } return pruneTree(indexNode.parent.parent, 0, leftPartitionWidth, displacement, indexNode.parent.parent.isRightNode()); } return new ArrayList<>(); } else { return pruneTree(indexNode.parent, 0, leftPartitionWidth, displacement, true); } } static NodePartition<T> createNodePartition(long leftPartitionWidth, Node<T> x); static List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth,
long displacement); } | Partitioner { public static <S extends StreamElement> List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth, long displacement) { if (indexNode.isRightNode()) { if (indexNode.parent.parent != null) { if (indexNode.parent.left != null) { displacement -= indexNode.parent.left.weight; indexNode.parent.parent.isRed = false; } return pruneTree(indexNode.parent.parent, 0, leftPartitionWidth, displacement, indexNode.parent.parent.isRightNode()); } return new ArrayList<>(); } else { return pruneTree(indexNode.parent, 0, leftPartitionWidth, displacement, true); } } static NodePartition<T> createNodePartition(long leftPartitionWidth, Node<T> x); static List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth,
long displacement); } |
@Test public void copy() throws Exception { VariantStream<InvariantSpan> stream = new RopeVariantStream<>(documentHash, getA()); stream.copy(2, new VariantSpan(12, 3)); List<InvariantSpan> spans = stream.getStreamElements(); assertEquals(new InvariantSpan(100, 1, documentHash), spans.get(0)); assertEquals(new InvariantSpan(301, 3, documentHash), spans.get(1)); assertEquals(new InvariantSpan(200, 3, documentHash), spans.get(3)); assertEquals(new InvariantSpan(250, 2, documentHash), spans.get(4)); assertEquals(new InvariantSpan(300, 4, documentHash), spans.get(5)); assertEquals(new InvariantSpan(350, 1, documentHash), spans.get(6)); assertEquals(new InvariantSpan(360, 6, documentHash), spans.get(7)); } | @Override public void copy(long characterPosition, VariantSpan variantSpan) throws MalformedSpanException, IOException { putElements(characterPosition, getStreamElements(variantSpan)); } | RopeVariantStream implements VariantStream<T> { @Override public void copy(long characterPosition, VariantSpan variantSpan) throws MalformedSpanException, IOException { putElements(characterPosition, getStreamElements(variantSpan)); } } | RopeVariantStream implements VariantStream<T> { @Override public void copy(long characterPosition, VariantSpan variantSpan) throws MalformedSpanException, IOException { putElements(characterPosition, getStreamElements(variantSpan)); } RopeVariantStream(String documentHash); RopeVariantStream(String documentHash, Node<T> root); } | RopeVariantStream implements VariantStream<T> { @Override public void copy(long characterPosition, VariantSpan variantSpan) throws MalformedSpanException, IOException { putElements(characterPosition, getStreamElements(variantSpan)); } 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 copy(long characterPosition, VariantSpan variantSpan) throws MalformedSpanException, IOException { putElements(characterPosition, getStreamElements(variantSpan)); } 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); } |
@Test public void delete() throws Exception { VariantStream<InvariantSpan> stream = new RopeVariantStream<>(documentHash, getA()); stream.delete(new VariantSpan(12, 4)); List<InvariantSpan> spans = stream.getStreamElements(); assertEquals(new InvariantSpan(100, 6, documentHash), spans.get(0)); assertEquals(new InvariantSpan(200, 3, documentHash), spans.get(1)); assertEquals(new InvariantSpan(250, 2, documentHash), spans.get(2)); assertEquals(new InvariantSpan(350, 1, documentHash), spans.get(3)); assertEquals(new InvariantSpan(360, 6, documentHash), spans.get(4)); assertEquals(5, spans.size()); } | @Override public void delete(VariantSpan variantSpan) throws MalformedSpanException { if (variantSpan == null) { throw new MalformedSpanException("Variant span is null for delete operation"); } deleteRange(variantSpan); } | RopeVariantStream implements VariantStream<T> { @Override public void delete(VariantSpan variantSpan) throws MalformedSpanException { if (variantSpan == null) { throw new MalformedSpanException("Variant span is null for delete operation"); } deleteRange(variantSpan); } } | RopeVariantStream implements VariantStream<T> { @Override public void delete(VariantSpan variantSpan) throws MalformedSpanException { if (variantSpan == null) { throw new MalformedSpanException("Variant span is null for delete operation"); } deleteRange(variantSpan); } RopeVariantStream(String documentHash); RopeVariantStream(String documentHash, Node<T> root); } | RopeVariantStream implements VariantStream<T> { @Override public void delete(VariantSpan variantSpan) throws MalformedSpanException { if (variantSpan == null) { throw new MalformedSpanException("Variant span is null for delete operation"); } deleteRange(variantSpan); } 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 delete(VariantSpan variantSpan) throws MalformedSpanException { if (variantSpan == null) { throw new MalformedSpanException("Variant span is null for delete operation"); } deleteRange(variantSpan); } 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); } |
@Test public void getInvariantSpan() throws Exception { VariantStream<InvariantSpan> stream = new RopeVariantStream<>(documentHash); List<InvariantSpan> spans = Arrays.asList(new InvariantSpan(1, 11, documentHash)); stream.putElements(1, spans); List<InvariantSpan> results = stream.getStreamElements(new VariantSpan(5, 6)); assertEquals(new InvariantSpan(6, 6, documentHash), results.get(0)); } | @Override public List<T> getStreamElements() throws MalformedSpanException { List<T> elements = new ArrayList<>(); Iterator<Node<T>> it = getAllLeafNodes(); while (it.hasNext()) { Node<T> node = it.next(); if (node.value != null) { elements.add(node.value); } } return elements; } | RopeVariantStream implements VariantStream<T> { @Override public List<T> getStreamElements() throws MalformedSpanException { List<T> elements = new ArrayList<>(); Iterator<Node<T>> it = getAllLeafNodes(); while (it.hasNext()) { Node<T> node = it.next(); if (node.value != null) { elements.add(node.value); } } return elements; } } | RopeVariantStream implements VariantStream<T> { @Override public List<T> getStreamElements() throws MalformedSpanException { List<T> elements = new ArrayList<>(); Iterator<Node<T>> it = getAllLeafNodes(); while (it.hasNext()) { Node<T> node = it.next(); if (node.value != null) { elements.add(node.value); } } return elements; } RopeVariantStream(String documentHash); RopeVariantStream(String documentHash, Node<T> root); } | RopeVariantStream implements VariantStream<T> { @Override public List<T> getStreamElements() throws MalformedSpanException { List<T> elements = new ArrayList<>(); Iterator<Node<T>> it = getAllLeafNodes(); while (it.hasNext()) { Node<T> node = it.next(); if (node.value != null) { elements.add(node.value); } } return elements; } 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 List<T> getStreamElements() throws MalformedSpanException { List<T> elements = new ArrayList<>(); Iterator<Node<T>> it = getAllLeafNodes(); while (it.hasNext()) { Node<T> node = it.next(); if (node.value != null) { elements.add(node.value); } } return elements; } 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); } |
@Test public void getInvariantSpansBeyondWidthOk() throws Exception { VariantStream<InvariantSpan> stream = new RopeVariantStream<>(documentHash, getA()); List<InvariantSpan> spans = stream.getStreamElements(new VariantSpan(10, 700)); assertEquals(new InvariantSpan(250, 2, documentHash), spans.get(0)); assertEquals(new InvariantSpan(300, 4, documentHash), spans.get(1)); assertEquals(new InvariantSpan(350, 1, documentHash), spans.get(2)); assertEquals(new InvariantSpan(360, 6, documentHash), spans.get(3)); } | @Override public List<T> getStreamElements() throws MalformedSpanException { List<T> elements = new ArrayList<>(); Iterator<Node<T>> it = getAllLeafNodes(); while (it.hasNext()) { Node<T> node = it.next(); if (node.value != null) { elements.add(node.value); } } return elements; } | RopeVariantStream implements VariantStream<T> { @Override public List<T> getStreamElements() throws MalformedSpanException { List<T> elements = new ArrayList<>(); Iterator<Node<T>> it = getAllLeafNodes(); while (it.hasNext()) { Node<T> node = it.next(); if (node.value != null) { elements.add(node.value); } } return elements; } } | RopeVariantStream implements VariantStream<T> { @Override public List<T> getStreamElements() throws MalformedSpanException { List<T> elements = new ArrayList<>(); Iterator<Node<T>> it = getAllLeafNodes(); while (it.hasNext()) { Node<T> node = it.next(); if (node.value != null) { elements.add(node.value); } } return elements; } RopeVariantStream(String documentHash); RopeVariantStream(String documentHash, Node<T> root); } | RopeVariantStream implements VariantStream<T> { @Override public List<T> getStreamElements() throws MalformedSpanException { List<T> elements = new ArrayList<>(); Iterator<Node<T>> it = getAllLeafNodes(); while (it.hasNext()) { Node<T> node = it.next(); if (node.value != null) { elements.add(node.value); } } return elements; } 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 List<T> getStreamElements() throws MalformedSpanException { List<T> elements = new ArrayList<>(); Iterator<Node<T>> it = getAllLeafNodes(); while (it.hasNext()) { Node<T> node = it.next(); if (node.value != null) { elements.add(node.value); } } return elements; } 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); } |
@Test public void getInvariantSpansMiddle() throws Exception { VariantStream<InvariantSpan> stream = new RopeVariantStream<>(documentHash, getA()); List<InvariantSpan> spans = stream.getStreamElements(new VariantSpan(10, 7)); assertEquals(new InvariantSpan(250, 2, documentHash), spans.get(0)); assertEquals(new InvariantSpan(300, 4, documentHash), spans.get(1)); assertEquals(new InvariantSpan(350, 1, documentHash), spans.get(2)); } | @Override public List<T> getStreamElements() throws MalformedSpanException { List<T> elements = new ArrayList<>(); Iterator<Node<T>> it = getAllLeafNodes(); while (it.hasNext()) { Node<T> node = it.next(); if (node.value != null) { elements.add(node.value); } } return elements; } | RopeVariantStream implements VariantStream<T> { @Override public List<T> getStreamElements() throws MalformedSpanException { List<T> elements = new ArrayList<>(); Iterator<Node<T>> it = getAllLeafNodes(); while (it.hasNext()) { Node<T> node = it.next(); if (node.value != null) { elements.add(node.value); } } return elements; } } | RopeVariantStream implements VariantStream<T> { @Override public List<T> getStreamElements() throws MalformedSpanException { List<T> elements = new ArrayList<>(); Iterator<Node<T>> it = getAllLeafNodes(); while (it.hasNext()) { Node<T> node = it.next(); if (node.value != null) { elements.add(node.value); } } return elements; } RopeVariantStream(String documentHash); RopeVariantStream(String documentHash, Node<T> root); } | RopeVariantStream implements VariantStream<T> { @Override public List<T> getStreamElements() throws MalformedSpanException { List<T> elements = new ArrayList<>(); Iterator<Node<T>> it = getAllLeafNodes(); while (it.hasNext()) { Node<T> node = it.next(); if (node.value != null) { elements.add(node.value); } } return elements; } 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 List<T> getStreamElements() throws MalformedSpanException { List<T> elements = new ArrayList<>(); Iterator<Node<T>> it = getAllLeafNodes(); while (it.hasNext()) { Node<T> node = it.next(); if (node.value != null) { elements.add(node.value); } } return elements; } 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); } |
@Test public void getInvariantSpansMiddle2() throws Exception { VariantStream<InvariantSpan> stream = new RopeVariantStream<>(documentHash, getA()); List<InvariantSpan> spans = stream.getStreamElements(new VariantSpan(10, 6, documentHash)); assertEquals(new InvariantSpan(250, 2, documentHash), spans.get(0)); assertEquals(new InvariantSpan(300, 4, documentHash), spans.get(1)); } | @Override public List<T> getStreamElements() throws MalformedSpanException { List<T> elements = new ArrayList<>(); Iterator<Node<T>> it = getAllLeafNodes(); while (it.hasNext()) { Node<T> node = it.next(); if (node.value != null) { elements.add(node.value); } } return elements; } | RopeVariantStream implements VariantStream<T> { @Override public List<T> getStreamElements() throws MalformedSpanException { List<T> elements = new ArrayList<>(); Iterator<Node<T>> it = getAllLeafNodes(); while (it.hasNext()) { Node<T> node = it.next(); if (node.value != null) { elements.add(node.value); } } return elements; } } | RopeVariantStream implements VariantStream<T> { @Override public List<T> getStreamElements() throws MalformedSpanException { List<T> elements = new ArrayList<>(); Iterator<Node<T>> it = getAllLeafNodes(); while (it.hasNext()) { Node<T> node = it.next(); if (node.value != null) { elements.add(node.value); } } return elements; } RopeVariantStream(String documentHash); RopeVariantStream(String documentHash, Node<T> root); } | RopeVariantStream implements VariantStream<T> { @Override public List<T> getStreamElements() throws MalformedSpanException { List<T> elements = new ArrayList<>(); Iterator<Node<T>> it = getAllLeafNodes(); while (it.hasNext()) { Node<T> node = it.next(); if (node.value != null) { elements.add(node.value); } } return elements; } 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 List<T> getStreamElements() throws MalformedSpanException { List<T> elements = new ArrayList<>(); Iterator<Node<T>> it = getAllLeafNodes(); while (it.hasNext()) { Node<T> node = it.next(); if (node.value != null) { elements.add(node.value); } } return elements; } 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); } |
@Test public void getInvariantSpansRangeEdgeLeft() throws Exception { VariantStream<InvariantSpan> stream = new RopeVariantStream<>(documentHash, getA()); List<InvariantSpan> spans = stream.getStreamElements(new VariantSpan(1, 14)); assertEquals(new InvariantSpan(100, 6, documentHash), spans.get(0)); assertEquals(new InvariantSpan(200, 3, documentHash), spans.get(1)); assertEquals(new InvariantSpan(250, 2, documentHash), spans.get(2)); assertEquals(new InvariantSpan(300, 3, documentHash), spans.get(3)); assertEquals(4, spans.size()); } | @Override public List<T> getStreamElements() throws MalformedSpanException { List<T> elements = new ArrayList<>(); Iterator<Node<T>> it = getAllLeafNodes(); while (it.hasNext()) { Node<T> node = it.next(); if (node.value != null) { elements.add(node.value); } } return elements; } | RopeVariantStream implements VariantStream<T> { @Override public List<T> getStreamElements() throws MalformedSpanException { List<T> elements = new ArrayList<>(); Iterator<Node<T>> it = getAllLeafNodes(); while (it.hasNext()) { Node<T> node = it.next(); if (node.value != null) { elements.add(node.value); } } return elements; } } | RopeVariantStream implements VariantStream<T> { @Override public List<T> getStreamElements() throws MalformedSpanException { List<T> elements = new ArrayList<>(); Iterator<Node<T>> it = getAllLeafNodes(); while (it.hasNext()) { Node<T> node = it.next(); if (node.value != null) { elements.add(node.value); } } return elements; } RopeVariantStream(String documentHash); RopeVariantStream(String documentHash, Node<T> root); } | RopeVariantStream implements VariantStream<T> { @Override public List<T> getStreamElements() throws MalformedSpanException { List<T> elements = new ArrayList<>(); Iterator<Node<T>> it = getAllLeafNodes(); while (it.hasNext()) { Node<T> node = it.next(); if (node.value != null) { elements.add(node.value); } } return elements; } 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 List<T> getStreamElements() throws MalformedSpanException { List<T> elements = new ArrayList<>(); Iterator<Node<T>> it = getAllLeafNodes(); while (it.hasNext()) { Node<T> node = it.next(); if (node.value != null) { elements.add(node.value); } } return elements; } 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); } |
@Test public void getInvariantSpansSmallWidthLeft() throws Exception { VariantStream<InvariantSpan> stream = new RopeVariantStream<>(documentHash, getA()); List<InvariantSpan> spans = stream.getStreamElements(new VariantSpan(1, 1)); assertEquals(new InvariantSpan(100, 1, documentHash), spans.get(0)); } | @Override public List<T> getStreamElements() throws MalformedSpanException { List<T> elements = new ArrayList<>(); Iterator<Node<T>> it = getAllLeafNodes(); while (it.hasNext()) { Node<T> node = it.next(); if (node.value != null) { elements.add(node.value); } } return elements; } | RopeVariantStream implements VariantStream<T> { @Override public List<T> getStreamElements() throws MalformedSpanException { List<T> elements = new ArrayList<>(); Iterator<Node<T>> it = getAllLeafNodes(); while (it.hasNext()) { Node<T> node = it.next(); if (node.value != null) { elements.add(node.value); } } return elements; } } | RopeVariantStream implements VariantStream<T> { @Override public List<T> getStreamElements() throws MalformedSpanException { List<T> elements = new ArrayList<>(); Iterator<Node<T>> it = getAllLeafNodes(); while (it.hasNext()) { Node<T> node = it.next(); if (node.value != null) { elements.add(node.value); } } return elements; } RopeVariantStream(String documentHash); RopeVariantStream(String documentHash, Node<T> root); } | RopeVariantStream implements VariantStream<T> { @Override public List<T> getStreamElements() throws MalformedSpanException { List<T> elements = new ArrayList<>(); Iterator<Node<T>> it = getAllLeafNodes(); while (it.hasNext()) { Node<T> node = it.next(); if (node.value != null) { elements.add(node.value); } } return elements; } 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 List<T> getStreamElements() throws MalformedSpanException { List<T> elements = new ArrayList<>(); Iterator<Node<T>> it = getAllLeafNodes(); while (it.hasNext()) { Node<T> node = it.next(); if (node.value != null) { elements.add(node.value); } } return elements; } 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); } |
@Test public void getInvariantSpansSmallWidthRight() throws Exception { VariantStream<InvariantSpan> stream = new RopeVariantStream<>(documentHash, getA()); List<InvariantSpan> spans = stream.getStreamElements(new VariantSpan(21, 1)); assertEquals(new InvariantSpan(365, 1, documentHash), spans.get(0)); } | @Override public List<T> getStreamElements() throws MalformedSpanException { List<T> elements = new ArrayList<>(); Iterator<Node<T>> it = getAllLeafNodes(); while (it.hasNext()) { Node<T> node = it.next(); if (node.value != null) { elements.add(node.value); } } return elements; } | RopeVariantStream implements VariantStream<T> { @Override public List<T> getStreamElements() throws MalformedSpanException { List<T> elements = new ArrayList<>(); Iterator<Node<T>> it = getAllLeafNodes(); while (it.hasNext()) { Node<T> node = it.next(); if (node.value != null) { elements.add(node.value); } } return elements; } } | RopeVariantStream implements VariantStream<T> { @Override public List<T> getStreamElements() throws MalformedSpanException { List<T> elements = new ArrayList<>(); Iterator<Node<T>> it = getAllLeafNodes(); while (it.hasNext()) { Node<T> node = it.next(); if (node.value != null) { elements.add(node.value); } } return elements; } RopeVariantStream(String documentHash); RopeVariantStream(String documentHash, Node<T> root); } | RopeVariantStream implements VariantStream<T> { @Override public List<T> getStreamElements() throws MalformedSpanException { List<T> elements = new ArrayList<>(); Iterator<Node<T>> it = getAllLeafNodes(); while (it.hasNext()) { Node<T> node = it.next(); if (node.value != null) { elements.add(node.value); } } return elements; } 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 List<T> getStreamElements() throws MalformedSpanException { List<T> elements = new ArrayList<>(); Iterator<Node<T>> it = getAllLeafNodes(); while (it.hasNext()) { Node<T> node = it.next(); if (node.value != null) { elements.add(node.value); } } return elements; } 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); } |
@Test public void encodeDecode() throws Exception { ApplyOverlayOp op = new ApplyOverlayOp(new VariantSpan(1, 100), Sets.newHashSet(1, 10)); byte[] data = op.encode(); DataInputStream dis = new DataInputStream(new ByteArrayInputStream(data)); assertEquals(Op.APPLY_OVERLAY, dis.readByte()); ApplyOverlayOp decoded = new ApplyOverlayOp(dis); assertEquals(op, decoded); } | @Override public byte[] encode() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(os)) { dos.writeByte(Op.APPLY_OVERLAY); dos.writeLong(variantSpan.start); dos.writeLong(variantSpan.width); dos.writeInt(linkTypes.size()); for (Integer i : linkTypes) { if (i < 0) { throw new IOException("Tumbler pool index must be 0 or greater: " + i); } dos.writeInt(i); } } os.flush(); return os.toByteArray(); } | ApplyOverlayOp extends Op { @Override public byte[] encode() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(os)) { dos.writeByte(Op.APPLY_OVERLAY); dos.writeLong(variantSpan.start); dos.writeLong(variantSpan.width); dos.writeInt(linkTypes.size()); for (Integer i : linkTypes) { if (i < 0) { throw new IOException("Tumbler pool index must be 0 or greater: " + i); } dos.writeInt(i); } } os.flush(); return os.toByteArray(); } } | ApplyOverlayOp extends Op { @Override public byte[] encode() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(os)) { dos.writeByte(Op.APPLY_OVERLAY); dos.writeLong(variantSpan.start); dos.writeLong(variantSpan.width); dos.writeInt(linkTypes.size()); for (Integer i : linkTypes) { if (i < 0) { throw new IOException("Tumbler pool index must be 0 or greater: " + i); } dos.writeInt(i); } } os.flush(); return os.toByteArray(); } ApplyOverlayOp(DataInputStream dis); ApplyOverlayOp(VariantSpan variantSpan, Set<Integer> linkTypes); } | ApplyOverlayOp extends Op { @Override public byte[] encode() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(os)) { dos.writeByte(Op.APPLY_OVERLAY); dos.writeLong(variantSpan.start); dos.writeLong(variantSpan.width); dos.writeInt(linkTypes.size()); for (Integer i : linkTypes) { if (i < 0) { throw new IOException("Tumbler pool index must be 0 or greater: " + i); } dos.writeInt(i); } } os.flush(); return os.toByteArray(); } ApplyOverlayOp(DataInputStream dis); ApplyOverlayOp(VariantSpan variantSpan, Set<Integer> linkTypes); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); } | ApplyOverlayOp extends Op { @Override public byte[] encode() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(os)) { dos.writeByte(Op.APPLY_OVERLAY); dos.writeLong(variantSpan.start); dos.writeLong(variantSpan.width); dos.writeInt(linkTypes.size()); for (Integer i : linkTypes) { if (i < 0) { throw new IOException("Tumbler pool index must be 0 or greater: " + i); } dos.writeInt(i); } } os.flush(); return os.toByteArray(); } ApplyOverlayOp(DataInputStream dis); ApplyOverlayOp(VariantSpan variantSpan, Set<Integer> linkTypes); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); final Set<Integer> linkTypes; final VariantSpan variantSpan; } |
@Test public void getVariantSpansTwoIntersect() throws Exception { VariantStream<InvariantSpan> stream = new RopeVariantStream<>(documentHash); List<InvariantSpan> spans = Arrays.asList(new InvariantSpan(7, 5, documentHash), new InvariantSpan(4, 3, documentHash), new InvariantSpan(1, 3, documentHash)); stream.putElements(1, spans); List<VariantSpan> result = stream.getVariantSpans(new InvariantSpan(2, 5, documentHash)); assertEquals(2, result.size()); assertEquals(new VariantSpan(6, 3, documentHash), result.get(0)); assertEquals(new VariantSpan(10, 2, documentHash), result.get(1)); } | @Override public List<VariantSpan> getVariantSpans(InvariantSpan targetSpan) throws MalformedSpanException { long index = 1; List<VariantSpan> vspans = new ArrayList<>(); List<T> spans = getStreamElements(); for (int i = 0; i < spans.size(); i++) { T element = spans.get(i); long targetStart = targetSpan.getStart(); long targetEnd = targetStart + targetSpan.getWidth(); if (!(element instanceof InvariantSpan)) { continue; } InvariantSpan span = (InvariantSpan) element; long start = span.getStart(); long end = start + span.getWidth(); if (RopeUtils.intersects(start, end, targetStart, targetEnd)) { long a = Math.max(0, targetStart - start); long b = Math.max(0, end - targetEnd); VariantSpan vs = new VariantSpan(index + a, span.getWidth() - b - a); vs.documentHash = documentHash; vspans.add(vs); } index += span.getWidth(); } return vspans; } | RopeVariantStream implements VariantStream<T> { @Override public List<VariantSpan> getVariantSpans(InvariantSpan targetSpan) throws MalformedSpanException { long index = 1; List<VariantSpan> vspans = new ArrayList<>(); List<T> spans = getStreamElements(); for (int i = 0; i < spans.size(); i++) { T element = spans.get(i); long targetStart = targetSpan.getStart(); long targetEnd = targetStart + targetSpan.getWidth(); if (!(element instanceof InvariantSpan)) { continue; } InvariantSpan span = (InvariantSpan) element; long start = span.getStart(); long end = start + span.getWidth(); if (RopeUtils.intersects(start, end, targetStart, targetEnd)) { long a = Math.max(0, targetStart - start); long b = Math.max(0, end - targetEnd); VariantSpan vs = new VariantSpan(index + a, span.getWidth() - b - a); vs.documentHash = documentHash; vspans.add(vs); } index += span.getWidth(); } return vspans; } } | RopeVariantStream implements VariantStream<T> { @Override public List<VariantSpan> getVariantSpans(InvariantSpan targetSpan) throws MalformedSpanException { long index = 1; List<VariantSpan> vspans = new ArrayList<>(); List<T> spans = getStreamElements(); for (int i = 0; i < spans.size(); i++) { T element = spans.get(i); long targetStart = targetSpan.getStart(); long targetEnd = targetStart + targetSpan.getWidth(); if (!(element instanceof InvariantSpan)) { continue; } InvariantSpan span = (InvariantSpan) element; long start = span.getStart(); long end = start + span.getWidth(); if (RopeUtils.intersects(start, end, targetStart, targetEnd)) { long a = Math.max(0, targetStart - start); long b = Math.max(0, end - targetEnd); VariantSpan vs = new VariantSpan(index + a, span.getWidth() - b - a); vs.documentHash = documentHash; vspans.add(vs); } index += span.getWidth(); } return vspans; } RopeVariantStream(String documentHash); RopeVariantStream(String documentHash, Node<T> root); } | RopeVariantStream implements VariantStream<T> { @Override public List<VariantSpan> getVariantSpans(InvariantSpan targetSpan) throws MalformedSpanException { long index = 1; List<VariantSpan> vspans = new ArrayList<>(); List<T> spans = getStreamElements(); for (int i = 0; i < spans.size(); i++) { T element = spans.get(i); long targetStart = targetSpan.getStart(); long targetEnd = targetStart + targetSpan.getWidth(); if (!(element instanceof InvariantSpan)) { continue; } InvariantSpan span = (InvariantSpan) element; long start = span.getStart(); long end = start + span.getWidth(); if (RopeUtils.intersects(start, end, targetStart, targetEnd)) { long a = Math.max(0, targetStart - start); long b = Math.max(0, end - targetEnd); VariantSpan vs = new VariantSpan(index + a, span.getWidth() - b - a); vs.documentHash = documentHash; vspans.add(vs); } index += span.getWidth(); } return vspans; } 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 List<VariantSpan> getVariantSpans(InvariantSpan targetSpan) throws MalformedSpanException { long index = 1; List<VariantSpan> vspans = new ArrayList<>(); List<T> spans = getStreamElements(); for (int i = 0; i < spans.size(); i++) { T element = spans.get(i); long targetStart = targetSpan.getStart(); long targetEnd = targetStart + targetSpan.getWidth(); if (!(element instanceof InvariantSpan)) { continue; } InvariantSpan span = (InvariantSpan) element; long start = span.getStart(); long end = start + span.getWidth(); if (RopeUtils.intersects(start, end, targetStart, targetEnd)) { long a = Math.max(0, targetStart - start); long b = Math.max(0, end - targetEnd); VariantSpan vs = new VariantSpan(index + a, span.getWidth() - b - a); vs.documentHash = documentHash; vspans.add(vs); } index += span.getWidth(); } return vspans; } 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); } |
@Test public void getVariantSpansTwoIntersect2() throws Exception { VariantStream<InvariantSpan> stream = new RopeVariantStream<>(documentHash); List<InvariantSpan> spans = Arrays.asList(new InvariantSpan(7, 5, documentHash), new InvariantSpan(4, 3, documentHash), new InvariantSpan(1, 3, documentHash)); stream.putElements(1, spans); List<VariantSpan> result = stream.getVariantSpans(new InvariantSpan(1, 4, documentHash)); assertEquals(2, result.size()); assertEquals(new VariantSpan(6, 1, documentHash), result.get(0)); assertEquals(new VariantSpan(9, 3, documentHash), result.get(1)); } | @Override public List<VariantSpan> getVariantSpans(InvariantSpan targetSpan) throws MalformedSpanException { long index = 1; List<VariantSpan> vspans = new ArrayList<>(); List<T> spans = getStreamElements(); for (int i = 0; i < spans.size(); i++) { T element = spans.get(i); long targetStart = targetSpan.getStart(); long targetEnd = targetStart + targetSpan.getWidth(); if (!(element instanceof InvariantSpan)) { continue; } InvariantSpan span = (InvariantSpan) element; long start = span.getStart(); long end = start + span.getWidth(); if (RopeUtils.intersects(start, end, targetStart, targetEnd)) { long a = Math.max(0, targetStart - start); long b = Math.max(0, end - targetEnd); VariantSpan vs = new VariantSpan(index + a, span.getWidth() - b - a); vs.documentHash = documentHash; vspans.add(vs); } index += span.getWidth(); } return vspans; } | RopeVariantStream implements VariantStream<T> { @Override public List<VariantSpan> getVariantSpans(InvariantSpan targetSpan) throws MalformedSpanException { long index = 1; List<VariantSpan> vspans = new ArrayList<>(); List<T> spans = getStreamElements(); for (int i = 0; i < spans.size(); i++) { T element = spans.get(i); long targetStart = targetSpan.getStart(); long targetEnd = targetStart + targetSpan.getWidth(); if (!(element instanceof InvariantSpan)) { continue; } InvariantSpan span = (InvariantSpan) element; long start = span.getStart(); long end = start + span.getWidth(); if (RopeUtils.intersects(start, end, targetStart, targetEnd)) { long a = Math.max(0, targetStart - start); long b = Math.max(0, end - targetEnd); VariantSpan vs = new VariantSpan(index + a, span.getWidth() - b - a); vs.documentHash = documentHash; vspans.add(vs); } index += span.getWidth(); } return vspans; } } | RopeVariantStream implements VariantStream<T> { @Override public List<VariantSpan> getVariantSpans(InvariantSpan targetSpan) throws MalformedSpanException { long index = 1; List<VariantSpan> vspans = new ArrayList<>(); List<T> spans = getStreamElements(); for (int i = 0; i < spans.size(); i++) { T element = spans.get(i); long targetStart = targetSpan.getStart(); long targetEnd = targetStart + targetSpan.getWidth(); if (!(element instanceof InvariantSpan)) { continue; } InvariantSpan span = (InvariantSpan) element; long start = span.getStart(); long end = start + span.getWidth(); if (RopeUtils.intersects(start, end, targetStart, targetEnd)) { long a = Math.max(0, targetStart - start); long b = Math.max(0, end - targetEnd); VariantSpan vs = new VariantSpan(index + a, span.getWidth() - b - a); vs.documentHash = documentHash; vspans.add(vs); } index += span.getWidth(); } return vspans; } RopeVariantStream(String documentHash); RopeVariantStream(String documentHash, Node<T> root); } | RopeVariantStream implements VariantStream<T> { @Override public List<VariantSpan> getVariantSpans(InvariantSpan targetSpan) throws MalformedSpanException { long index = 1; List<VariantSpan> vspans = new ArrayList<>(); List<T> spans = getStreamElements(); for (int i = 0; i < spans.size(); i++) { T element = spans.get(i); long targetStart = targetSpan.getStart(); long targetEnd = targetStart + targetSpan.getWidth(); if (!(element instanceof InvariantSpan)) { continue; } InvariantSpan span = (InvariantSpan) element; long start = span.getStart(); long end = start + span.getWidth(); if (RopeUtils.intersects(start, end, targetStart, targetEnd)) { long a = Math.max(0, targetStart - start); long b = Math.max(0, end - targetEnd); VariantSpan vs = new VariantSpan(index + a, span.getWidth() - b - a); vs.documentHash = documentHash; vspans.add(vs); } index += span.getWidth(); } return vspans; } 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 List<VariantSpan> getVariantSpans(InvariantSpan targetSpan) throws MalformedSpanException { long index = 1; List<VariantSpan> vspans = new ArrayList<>(); List<T> spans = getStreamElements(); for (int i = 0; i < spans.size(); i++) { T element = spans.get(i); long targetStart = targetSpan.getStart(); long targetEnd = targetStart + targetSpan.getWidth(); if (!(element instanceof InvariantSpan)) { continue; } InvariantSpan span = (InvariantSpan) element; long start = span.getStart(); long end = start + span.getWidth(); if (RopeUtils.intersects(start, end, targetStart, targetEnd)) { long a = Math.max(0, targetStart - start); long b = Math.max(0, end - targetEnd); VariantSpan vs = new VariantSpan(index + a, span.getWidth() - b - a); vs.documentHash = documentHash; vspans.add(vs); } index += span.getWidth(); } return vspans; } 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); } |
@Test public void index() throws Exception { VariantStream<InvariantSpan> stream = new RopeVariantStream<>(documentHash, getA()); InvariantSpan span = stream.index(12); assertEquals(new InvariantSpan(300, 4, documentHash), span); } | @Override public T index(long characterPosition) { if (root == null) { throw new IllegalStateException("Stream is empty"); } return RopeUtils.index(characterPosition, root, 0).node.value; } | RopeVariantStream implements VariantStream<T> { @Override public T index(long characterPosition) { if (root == null) { throw new IllegalStateException("Stream is empty"); } return RopeUtils.index(characterPosition, root, 0).node.value; } } | RopeVariantStream implements VariantStream<T> { @Override public T index(long characterPosition) { if (root == null) { throw new IllegalStateException("Stream is empty"); } return RopeUtils.index(characterPosition, root, 0).node.value; } RopeVariantStream(String documentHash); RopeVariantStream(String documentHash, Node<T> root); } | RopeVariantStream implements VariantStream<T> { @Override public T index(long characterPosition) { if (root == null) { throw new IllegalStateException("Stream is empty"); } return RopeUtils.index(characterPosition, root, 0).node.value; } 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 T index(long characterPosition) { if (root == null) { throw new IllegalStateException("Stream is empty"); } return RopeUtils.index(characterPosition, root, 0).node.value; } 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); } |
@Test public void index11() throws Exception { VariantStream<InvariantSpan> stream = new RopeVariantStream<>(documentHash, getA()); InvariantSpan span = stream.index(11); assertEquals(new InvariantSpan(250, 2, documentHash), span); span = stream.index(10); assertEquals(new InvariantSpan(250, 2, documentHash), span); } | @Override public T index(long characterPosition) { if (root == null) { throw new IllegalStateException("Stream is empty"); } return RopeUtils.index(characterPosition, root, 0).node.value; } | RopeVariantStream implements VariantStream<T> { @Override public T index(long characterPosition) { if (root == null) { throw new IllegalStateException("Stream is empty"); } return RopeUtils.index(characterPosition, root, 0).node.value; } } | RopeVariantStream implements VariantStream<T> { @Override public T index(long characterPosition) { if (root == null) { throw new IllegalStateException("Stream is empty"); } return RopeUtils.index(characterPosition, root, 0).node.value; } RopeVariantStream(String documentHash); RopeVariantStream(String documentHash, Node<T> root); } | RopeVariantStream implements VariantStream<T> { @Override public T index(long characterPosition) { if (root == null) { throw new IllegalStateException("Stream is empty"); } return RopeUtils.index(characterPosition, root, 0).node.value; } 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 T index(long characterPosition) { if (root == null) { throw new IllegalStateException("Stream is empty"); } return RopeUtils.index(characterPosition, root, 0).node.value; } 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); } |
@Test(expected = IndexOutOfBoundsException.class) public void indexNull() throws Exception { VariantStream<InvariantSpan> stream = new RopeVariantStream<>(documentHash, getA()); InvariantSpan span = stream.index(100); assertNull(span); } | @Override public T index(long characterPosition) { if (root == null) { throw new IllegalStateException("Stream is empty"); } return RopeUtils.index(characterPosition, root, 0).node.value; } | RopeVariantStream implements VariantStream<T> { @Override public T index(long characterPosition) { if (root == null) { throw new IllegalStateException("Stream is empty"); } return RopeUtils.index(characterPosition, root, 0).node.value; } } | RopeVariantStream implements VariantStream<T> { @Override public T index(long characterPosition) { if (root == null) { throw new IllegalStateException("Stream is empty"); } return RopeUtils.index(characterPosition, root, 0).node.value; } RopeVariantStream(String documentHash); RopeVariantStream(String documentHash, Node<T> root); } | RopeVariantStream implements VariantStream<T> { @Override public T index(long characterPosition) { if (root == null) { throw new IllegalStateException("Stream is empty"); } return RopeUtils.index(characterPosition, root, 0).node.value; } 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 T index(long characterPosition) { if (root == null) { throw new IllegalStateException("Stream is empty"); } return RopeUtils.index(characterPosition, root, 0).node.value; } 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); } |
@Test public void put() throws Exception { VariantStream<InvariantSpan> stream = new RopeVariantStream<>(documentHash, getA()); stream.put(12, new InvariantSpan(500, 34, documentHash)); List<InvariantSpan> spans = stream.getStreamElements(); assertEquals(new InvariantSpan(100, 6, documentHash), spans.get(0)); assertEquals(new InvariantSpan(200, 3, documentHash), spans.get(1)); assertEquals(new InvariantSpan(250, 2, documentHash), spans.get(2)); assertEquals(new InvariantSpan(500, 34, documentHash), spans.get(3)); assertEquals(new InvariantSpan(300, 4, documentHash), spans.get(4)); assertEquals(new InvariantSpan(350, 1, documentHash), spans.get(5)); assertEquals(new InvariantSpan(360, 6, documentHash), spans.get(6)); } | @Override public void put(long characterPosition, T val) throws MalformedSpanException { if (val == null) { throw new IllegalArgumentException("invariant span is null"); } if (characterPosition < 1) { throw new IndexOutOfBoundsException("put position must be greater than 0"); } if (val.getWidth() < 1) { throw new MalformedSpanException("invariant span must have a width greater than 0"); } insert(characterPosition, new Node<T>(val)); } | RopeVariantStream implements VariantStream<T> { @Override public void put(long characterPosition, T val) throws MalformedSpanException { if (val == null) { throw new IllegalArgumentException("invariant span is null"); } if (characterPosition < 1) { throw new IndexOutOfBoundsException("put position must be greater than 0"); } if (val.getWidth() < 1) { throw new MalformedSpanException("invariant span must have a width greater than 0"); } insert(characterPosition, new Node<T>(val)); } } | RopeVariantStream implements VariantStream<T> { @Override public void put(long characterPosition, T val) throws MalformedSpanException { if (val == null) { throw new IllegalArgumentException("invariant span is null"); } if (characterPosition < 1) { throw new IndexOutOfBoundsException("put position must be greater than 0"); } if (val.getWidth() < 1) { throw new MalformedSpanException("invariant span must have a width greater than 0"); } insert(characterPosition, new Node<T>(val)); } RopeVariantStream(String documentHash); RopeVariantStream(String documentHash, Node<T> root); } | RopeVariantStream implements VariantStream<T> { @Override public void put(long characterPosition, T val) throws MalformedSpanException { if (val == null) { throw new IllegalArgumentException("invariant span is null"); } if (characterPosition < 1) { throw new IndexOutOfBoundsException("put position must be greater than 0"); } if (val.getWidth() < 1) { throw new MalformedSpanException("invariant span must have a width greater than 0"); } insert(characterPosition, new Node<T>(val)); } 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 put(long characterPosition, T val) throws MalformedSpanException { if (val == null) { throw new IllegalArgumentException("invariant span is null"); } if (characterPosition < 1) { throw new IndexOutOfBoundsException("put position must be greater than 0"); } if (val.getWidth() < 1) { throw new MalformedSpanException("invariant span must have a width greater than 0"); } insert(characterPosition, new Node<T>(val)); } 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); } |
@Test public void putSpans() throws Exception { VariantStream<InvariantSpan> stream = new RopeVariantStream<>(documentHash); List<InvariantSpan> spans = Arrays.asList(new InvariantSpan(7, 5, documentHash), new InvariantSpan(4, 3, documentHash), new InvariantSpan(1, 3, documentHash)); stream.putElements(1, spans); List<InvariantSpan> results = stream.getStreamElements(); assertEquals(results.get(0), spans.get(0)); assertEquals(results.get(1), spans.get(1)); assertEquals(results.get(2), spans.get(2)); } | @Override public List<T> getStreamElements() throws MalformedSpanException { List<T> elements = new ArrayList<>(); Iterator<Node<T>> it = getAllLeafNodes(); while (it.hasNext()) { Node<T> node = it.next(); if (node.value != null) { elements.add(node.value); } } return elements; } | RopeVariantStream implements VariantStream<T> { @Override public List<T> getStreamElements() throws MalformedSpanException { List<T> elements = new ArrayList<>(); Iterator<Node<T>> it = getAllLeafNodes(); while (it.hasNext()) { Node<T> node = it.next(); if (node.value != null) { elements.add(node.value); } } return elements; } } | RopeVariantStream implements VariantStream<T> { @Override public List<T> getStreamElements() throws MalformedSpanException { List<T> elements = new ArrayList<>(); Iterator<Node<T>> it = getAllLeafNodes(); while (it.hasNext()) { Node<T> node = it.next(); if (node.value != null) { elements.add(node.value); } } return elements; } RopeVariantStream(String documentHash); RopeVariantStream(String documentHash, Node<T> root); } | RopeVariantStream implements VariantStream<T> { @Override public List<T> getStreamElements() throws MalformedSpanException { List<T> elements = new ArrayList<>(); Iterator<Node<T>> it = getAllLeafNodes(); while (it.hasNext()) { Node<T> node = it.next(); if (node.value != null) { elements.add(node.value); } } return elements; } 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 List<T> getStreamElements() throws MalformedSpanException { List<T> elements = new ArrayList<>(); Iterator<Node<T>> it = getAllLeafNodes(); while (it.hasNext()) { Node<T> node = it.next(); if (node.value != null) { elements.add(node.value); } } return elements; } 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); } |
@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); } |
@Test public void addWeightsOfRightLeaningChildNodesChained() throws Exception { Node<InvariantSpan> right = new Node<>(new InvariantSpan(1, 10, documentHash)); Node<InvariantSpan> right2 = new Node<>(new InvariantSpan(1, 20, documentHash)); right.right = right2; Node<InvariantSpan> x = new Node.Builder<InvariantSpan>(0).right(right).build(); assertEquals(30, RopeUtils.addWeightsOfRightLeaningChildNodes(x)); } | public static <T extends StreamElement> long addWeightsOfRightLeaningChildNodes(Node<T> x) { if (x == null || x.right == null) { return 0; } return x.right.weight + addWeightsOfRightLeaningChildNodes(x.right); } | RopeUtils { public static <T extends StreamElement> long addWeightsOfRightLeaningChildNodes(Node<T> x) { if (x == null || x.right == null) { return 0; } return x.right.weight + addWeightsOfRightLeaningChildNodes(x.right); } } | RopeUtils { public static <T extends StreamElement> long addWeightsOfRightLeaningChildNodes(Node<T> x) { if (x == null || x.right == null) { return 0; } return x.right.weight + addWeightsOfRightLeaningChildNodes(x.right); } } | RopeUtils { public static <T extends StreamElement> long addWeightsOfRightLeaningChildNodes(Node<T> x) { if (x == null || x.right == null) { return 0; } return x.right.weight + addWeightsOfRightLeaningChildNodes(x.right); } static long addWeightsOfRightLeaningChildNodes(Node<T> x); static long addWeightsOfRightLeaningParentNodes(Node<T> child); static void adjustWeightOfLeftLeaningParents(Node<T> startNode, long weight); static long characterCount(Node<T> x); static void collectLeafNodes(Node<T> x, Queue<Node<T>> queue); static Node<T> concat(List<Node<T>> orphans); static Node<T> concat(Node<T> left, Node<T> right); static void cutLeftNode(Node<T> x, List<Node<T>> orphans); static void cutRightNode(Node<T> x, List<Node<T>> orphans); static Node<T> findRoot(Node<T> child); static Node<T> findSearchNode(Node<T> x, long weight, Node<T> root); static NodeIndex<T> index(long characterPosition, Node<T> x, long disp); static boolean intersects(long start, long end, long start2, long end2); static Node<T> rebalance(Node<T> x); } | RopeUtils { public static <T extends StreamElement> long addWeightsOfRightLeaningChildNodes(Node<T> x) { if (x == null || x.right == null) { return 0; } return x.right.weight + addWeightsOfRightLeaningChildNodes(x.right); } static long addWeightsOfRightLeaningChildNodes(Node<T> x); static long addWeightsOfRightLeaningParentNodes(Node<T> child); static void adjustWeightOfLeftLeaningParents(Node<T> startNode, long weight); static long characterCount(Node<T> x); static void collectLeafNodes(Node<T> x, Queue<Node<T>> queue); static Node<T> concat(List<Node<T>> orphans); static Node<T> concat(Node<T> left, Node<T> right); static void cutLeftNode(Node<T> x, List<Node<T>> orphans); static void cutRightNode(Node<T> x, List<Node<T>> orphans); static Node<T> findRoot(Node<T> child); static Node<T> findSearchNode(Node<T> x, long weight, Node<T> root); static NodeIndex<T> index(long characterPosition, Node<T> x, long disp); static boolean intersects(long start, long end, long start2, long end2); static Node<T> rebalance(Node<T> x); } |
@Test public void addWeightsOfRightLeaningChildNodesLeftOnly() throws Exception { Node<InvariantSpan> left = new Node<>(new InvariantSpan(1, 1, documentHash)); Node<InvariantSpan> x = new Node.Builder<InvariantSpan>(1).left(left).build(); assertEquals(0, RopeUtils.addWeightsOfRightLeaningChildNodes(x)); } | public static <T extends StreamElement> long addWeightsOfRightLeaningChildNodes(Node<T> x) { if (x == null || x.right == null) { return 0; } return x.right.weight + addWeightsOfRightLeaningChildNodes(x.right); } | RopeUtils { public static <T extends StreamElement> long addWeightsOfRightLeaningChildNodes(Node<T> x) { if (x == null || x.right == null) { return 0; } return x.right.weight + addWeightsOfRightLeaningChildNodes(x.right); } } | RopeUtils { public static <T extends StreamElement> long addWeightsOfRightLeaningChildNodes(Node<T> x) { if (x == null || x.right == null) { return 0; } return x.right.weight + addWeightsOfRightLeaningChildNodes(x.right); } } | RopeUtils { public static <T extends StreamElement> long addWeightsOfRightLeaningChildNodes(Node<T> x) { if (x == null || x.right == null) { return 0; } return x.right.weight + addWeightsOfRightLeaningChildNodes(x.right); } static long addWeightsOfRightLeaningChildNodes(Node<T> x); static long addWeightsOfRightLeaningParentNodes(Node<T> child); static void adjustWeightOfLeftLeaningParents(Node<T> startNode, long weight); static long characterCount(Node<T> x); static void collectLeafNodes(Node<T> x, Queue<Node<T>> queue); static Node<T> concat(List<Node<T>> orphans); static Node<T> concat(Node<T> left, Node<T> right); static void cutLeftNode(Node<T> x, List<Node<T>> orphans); static void cutRightNode(Node<T> x, List<Node<T>> orphans); static Node<T> findRoot(Node<T> child); static Node<T> findSearchNode(Node<T> x, long weight, Node<T> root); static NodeIndex<T> index(long characterPosition, Node<T> x, long disp); static boolean intersects(long start, long end, long start2, long end2); static Node<T> rebalance(Node<T> x); } | RopeUtils { public static <T extends StreamElement> long addWeightsOfRightLeaningChildNodes(Node<T> x) { if (x == null || x.right == null) { return 0; } return x.right.weight + addWeightsOfRightLeaningChildNodes(x.right); } static long addWeightsOfRightLeaningChildNodes(Node<T> x); static long addWeightsOfRightLeaningParentNodes(Node<T> child); static void adjustWeightOfLeftLeaningParents(Node<T> startNode, long weight); static long characterCount(Node<T> x); static void collectLeafNodes(Node<T> x, Queue<Node<T>> queue); static Node<T> concat(List<Node<T>> orphans); static Node<T> concat(Node<T> left, Node<T> right); static void cutLeftNode(Node<T> x, List<Node<T>> orphans); static void cutRightNode(Node<T> x, List<Node<T>> orphans); static Node<T> findRoot(Node<T> child); static Node<T> findSearchNode(Node<T> x, long weight, Node<T> root); static NodeIndex<T> index(long characterPosition, Node<T> x, long disp); static boolean intersects(long start, long end, long start2, long end2); static Node<T> rebalance(Node<T> x); } |
@Test public void equalsLinkTypesFalse() throws Exception { ApplyOverlayOp op1 = new ApplyOverlayOp(new VariantSpan(1, 100), Sets.newHashSet(1)); ApplyOverlayOp op2 = new ApplyOverlayOp(new VariantSpan(1, 100), Sets.newHashSet(1, 10)); assertFalse(op1.equals(op2)); assertFalse(op2.equals(op1)); } | @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; ApplyOverlayOp other = (ApplyOverlayOp) obj; if (!linkTypes.equals(other.linkTypes)) return false; if (!variantSpan.equals(other.variantSpan)) return false; return true; } | ApplyOverlayOp extends Op { @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; ApplyOverlayOp other = (ApplyOverlayOp) obj; if (!linkTypes.equals(other.linkTypes)) return false; if (!variantSpan.equals(other.variantSpan)) return false; return true; } } | ApplyOverlayOp extends Op { @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; ApplyOverlayOp other = (ApplyOverlayOp) obj; if (!linkTypes.equals(other.linkTypes)) return false; if (!variantSpan.equals(other.variantSpan)) return false; return true; } ApplyOverlayOp(DataInputStream dis); ApplyOverlayOp(VariantSpan variantSpan, Set<Integer> linkTypes); } | ApplyOverlayOp extends Op { @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; ApplyOverlayOp other = (ApplyOverlayOp) obj; if (!linkTypes.equals(other.linkTypes)) return false; if (!variantSpan.equals(other.variantSpan)) return false; return true; } ApplyOverlayOp(DataInputStream dis); ApplyOverlayOp(VariantSpan variantSpan, Set<Integer> linkTypes); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); } | ApplyOverlayOp extends Op { @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; ApplyOverlayOp other = (ApplyOverlayOp) obj; if (!linkTypes.equals(other.linkTypes)) return false; if (!variantSpan.equals(other.variantSpan)) return false; return true; } ApplyOverlayOp(DataInputStream dis); ApplyOverlayOp(VariantSpan variantSpan, Set<Integer> linkTypes); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); final Set<Integer> linkTypes; final VariantSpan variantSpan; } |
@Test public void testGranularityFromSlotKey() { Granularity expected = Granularity.MIN_5; Granularity myGranularity = SlotKeySerDes.granularityFromSlotKey(SlotKey.of(expected, 1, 1).toString()); Assert.assertNotNull(myGranularity); Assert.assertEquals(myGranularity, expected); myGranularity = SlotKeySerDes.granularityFromSlotKey("FULL"); Assert.assertNull(myGranularity); } | protected static Granularity granularityFromSlotKey(String s) { String field = s.split(",", -1)[0]; for (Granularity g : Granularity.granularities()) if (g.name().startsWith(field)) return g; return null; } | SlotKeySerDes { protected static Granularity granularityFromSlotKey(String s) { String field = s.split(",", -1)[0]; for (Granularity g : Granularity.granularities()) if (g.name().startsWith(field)) return g; return null; } } | SlotKeySerDes { protected static Granularity granularityFromSlotKey(String s) { String field = s.split(",", -1)[0]; for (Granularity g : Granularity.granularities()) if (g.name().startsWith(field)) return g; return null; } } | SlotKeySerDes { protected static Granularity granularityFromSlotKey(String s) { String field = s.split(",", -1)[0]; for (Granularity g : Granularity.granularities()) if (g.name().startsWith(field)) return g; return null; } static SlotKey deserialize(String stateStr); String serialize(SlotKey slotKey); String serialize(Granularity gran, int slot, int shard); } | SlotKeySerDes { protected static Granularity granularityFromSlotKey(String s) { String field = s.split(",", -1)[0]; for (Granularity g : Granularity.granularities()) if (g.name().startsWith(field)) return g; return null; } static SlotKey deserialize(String stateStr); String serialize(SlotKey slotKey); String serialize(Granularity gran, int slot, int shard); } |
@Test public void testGetLocatorsForReRollLowerLevelToStorageGranularity() throws IOException { boolean isReroll = true; SlotKey destSlotKey = SlotKey.of(Granularity.MIN_5, 0, TEST_SHARD); Granularity delayedMetricsRerollGranularity = Granularity.MIN_60; Granularity delayedMetricsStorageGranularity = Granularity.MIN_20; LocatorFetchRunnable lfrunnable = new LocatorFetchRunnable(scheduleCtx, destSlotKey, rollupReadExecutor, rollupWriteExecutor); HashSet<Locator> delayedLocators = new HashSet<Locator>() {{ add(locators.get(0)); }}; when(delayedLocatorIO.getLocators(SlotKey.of(Granularity.MIN_20, 0, TEST_SHARD))).thenReturn(delayedLocators); Set<Locator> locatorsForRollup = lfrunnable.getLocators(executionContext, isReroll, delayedMetricsRerollGranularity, delayedMetricsStorageGranularity); assertEquals(delayedLocators.size(), locatorsForRollup.size()); } | protected Set<Locator> getLocators(RollupExecutionContext executionContext, boolean isReroll, Granularity delayedMetricsRerollGranularity, Granularity delayedMetricsStorageGranularity) { Set<Locator> locators = new HashSet<Locator>(); if (RECORD_DELAYED_METRICS && isReroll && !getGranularity().isCoarser(delayedMetricsRerollGranularity)) { if (getGranularity().isCoarser(delayedMetricsStorageGranularity)) { for (SlotKey slotKey: parentSlotKey.getChildrenKeys(delayedMetricsStorageGranularity)) { locators.addAll(getDelayedLocators(executionContext, slotKey)); } } else { locators = getDelayedLocators(executionContext, parentSlotKey.extrapolate(delayedMetricsStorageGranularity)); } } else { locators = getLocators(executionContext); } return locators; } | LocatorFetchRunnable implements Runnable { protected Set<Locator> getLocators(RollupExecutionContext executionContext, boolean isReroll, Granularity delayedMetricsRerollGranularity, Granularity delayedMetricsStorageGranularity) { Set<Locator> locators = new HashSet<Locator>(); if (RECORD_DELAYED_METRICS && isReroll && !getGranularity().isCoarser(delayedMetricsRerollGranularity)) { if (getGranularity().isCoarser(delayedMetricsStorageGranularity)) { for (SlotKey slotKey: parentSlotKey.getChildrenKeys(delayedMetricsStorageGranularity)) { locators.addAll(getDelayedLocators(executionContext, slotKey)); } } else { locators = getDelayedLocators(executionContext, parentSlotKey.extrapolate(delayedMetricsStorageGranularity)); } } else { locators = getLocators(executionContext); } return locators; } } | LocatorFetchRunnable implements Runnable { protected Set<Locator> getLocators(RollupExecutionContext executionContext, boolean isReroll, Granularity delayedMetricsRerollGranularity, Granularity delayedMetricsStorageGranularity) { Set<Locator> locators = new HashSet<Locator>(); if (RECORD_DELAYED_METRICS && isReroll && !getGranularity().isCoarser(delayedMetricsRerollGranularity)) { if (getGranularity().isCoarser(delayedMetricsStorageGranularity)) { for (SlotKey slotKey: parentSlotKey.getChildrenKeys(delayedMetricsStorageGranularity)) { locators.addAll(getDelayedLocators(executionContext, slotKey)); } } else { locators = getDelayedLocators(executionContext, parentSlotKey.extrapolate(delayedMetricsStorageGranularity)); } } else { locators = getLocators(executionContext); } return locators; } LocatorFetchRunnable(ScheduleContext scheduleCtx,
SlotKey destSlotKey,
ExecutorService rollupReadExecutor,
ThreadPoolExecutor rollupWriteExecutor); } | LocatorFetchRunnable implements Runnable { protected Set<Locator> getLocators(RollupExecutionContext executionContext, boolean isReroll, Granularity delayedMetricsRerollGranularity, Granularity delayedMetricsStorageGranularity) { Set<Locator> locators = new HashSet<Locator>(); if (RECORD_DELAYED_METRICS && isReroll && !getGranularity().isCoarser(delayedMetricsRerollGranularity)) { if (getGranularity().isCoarser(delayedMetricsStorageGranularity)) { for (SlotKey slotKey: parentSlotKey.getChildrenKeys(delayedMetricsStorageGranularity)) { locators.addAll(getDelayedLocators(executionContext, slotKey)); } } else { locators = getDelayedLocators(executionContext, parentSlotKey.extrapolate(delayedMetricsStorageGranularity)); } } else { locators = getLocators(executionContext); } return locators; } LocatorFetchRunnable(ScheduleContext scheduleCtx,
SlotKey destSlotKey,
ExecutorService rollupReadExecutor,
ThreadPoolExecutor rollupWriteExecutor); @VisibleForTesting void initialize(ScheduleContext scheduleCtx,
SlotKey destSlotKey,
ExecutorService rollupReadExecutor,
ThreadPoolExecutor rollupWriteExecutor); void run(); void drainExecutionContext(long waitStart, int rollCount, RollupExecutionContext executionContext, RollupBatchWriter rollupBatchWriter); void finishExecution(long waitStart, RollupExecutionContext executionContext); int processLocator(int rollCount, RollupExecutionContext executionContext, RollupBatchWriter rollupBatchWriter, Locator locator); void executeRollupForLocator(RollupExecutionContext executionContext, RollupBatchWriter rollupBatchWriter, Locator locator); Set<Locator> getDelayedLocators(RollupExecutionContext executionContext, SlotKey slotkey); Set<Locator> getLocators(RollupExecutionContext executionContext); } | LocatorFetchRunnable implements Runnable { protected Set<Locator> getLocators(RollupExecutionContext executionContext, boolean isReroll, Granularity delayedMetricsRerollGranularity, Granularity delayedMetricsStorageGranularity) { Set<Locator> locators = new HashSet<Locator>(); if (RECORD_DELAYED_METRICS && isReroll && !getGranularity().isCoarser(delayedMetricsRerollGranularity)) { if (getGranularity().isCoarser(delayedMetricsStorageGranularity)) { for (SlotKey slotKey: parentSlotKey.getChildrenKeys(delayedMetricsStorageGranularity)) { locators.addAll(getDelayedLocators(executionContext, slotKey)); } } else { locators = getDelayedLocators(executionContext, parentSlotKey.extrapolate(delayedMetricsStorageGranularity)); } } else { locators = getLocators(executionContext); } return locators; } LocatorFetchRunnable(ScheduleContext scheduleCtx,
SlotKey destSlotKey,
ExecutorService rollupReadExecutor,
ThreadPoolExecutor rollupWriteExecutor); @VisibleForTesting void initialize(ScheduleContext scheduleCtx,
SlotKey destSlotKey,
ExecutorService rollupReadExecutor,
ThreadPoolExecutor rollupWriteExecutor); void run(); void drainExecutionContext(long waitStart, int rollCount, RollupExecutionContext executionContext, RollupBatchWriter rollupBatchWriter); void finishExecution(long waitStart, RollupExecutionContext executionContext); int processLocator(int rollCount, RollupExecutionContext executionContext, RollupBatchWriter rollupBatchWriter, Locator locator); void executeRollupForLocator(RollupExecutionContext executionContext, RollupBatchWriter rollupBatchWriter, Locator locator); Set<Locator> getDelayedLocators(RollupExecutionContext executionContext, SlotKey slotkey); Set<Locator> getLocators(RollupExecutionContext executionContext); } |
@Test public void testGetLocatorsForReRollSameAsStorageGranularity() throws IOException { boolean isReroll = true; SlotKey destSlotKey = SlotKey.of(Granularity.MIN_20, 0, TEST_SHARD); Granularity delayedMetricsRerollGranularity = Granularity.MIN_60; Granularity delayedMetricsStorageGranularity = Granularity.MIN_20; LocatorFetchRunnable lfrunnable = new LocatorFetchRunnable(scheduleCtx, destSlotKey, rollupReadExecutor, rollupWriteExecutor); HashSet<Locator> delayedLocators = new HashSet<Locator>() {{ add(locators.get(0)); }}; when(delayedLocatorIO.getLocators(SlotKey.of(Granularity.MIN_20, 0, TEST_SHARD))).thenReturn(delayedLocators); Set<Locator> locatorsForRollup = lfrunnable.getLocators(executionContext, isReroll, delayedMetricsRerollGranularity, delayedMetricsStorageGranularity); assertEquals(delayedLocators.size(), locatorsForRollup.size()); } | protected Set<Locator> getLocators(RollupExecutionContext executionContext, boolean isReroll, Granularity delayedMetricsRerollGranularity, Granularity delayedMetricsStorageGranularity) { Set<Locator> locators = new HashSet<Locator>(); if (RECORD_DELAYED_METRICS && isReroll && !getGranularity().isCoarser(delayedMetricsRerollGranularity)) { if (getGranularity().isCoarser(delayedMetricsStorageGranularity)) { for (SlotKey slotKey: parentSlotKey.getChildrenKeys(delayedMetricsStorageGranularity)) { locators.addAll(getDelayedLocators(executionContext, slotKey)); } } else { locators = getDelayedLocators(executionContext, parentSlotKey.extrapolate(delayedMetricsStorageGranularity)); } } else { locators = getLocators(executionContext); } return locators; } | LocatorFetchRunnable implements Runnable { protected Set<Locator> getLocators(RollupExecutionContext executionContext, boolean isReroll, Granularity delayedMetricsRerollGranularity, Granularity delayedMetricsStorageGranularity) { Set<Locator> locators = new HashSet<Locator>(); if (RECORD_DELAYED_METRICS && isReroll && !getGranularity().isCoarser(delayedMetricsRerollGranularity)) { if (getGranularity().isCoarser(delayedMetricsStorageGranularity)) { for (SlotKey slotKey: parentSlotKey.getChildrenKeys(delayedMetricsStorageGranularity)) { locators.addAll(getDelayedLocators(executionContext, slotKey)); } } else { locators = getDelayedLocators(executionContext, parentSlotKey.extrapolate(delayedMetricsStorageGranularity)); } } else { locators = getLocators(executionContext); } return locators; } } | LocatorFetchRunnable implements Runnable { protected Set<Locator> getLocators(RollupExecutionContext executionContext, boolean isReroll, Granularity delayedMetricsRerollGranularity, Granularity delayedMetricsStorageGranularity) { Set<Locator> locators = new HashSet<Locator>(); if (RECORD_DELAYED_METRICS && isReroll && !getGranularity().isCoarser(delayedMetricsRerollGranularity)) { if (getGranularity().isCoarser(delayedMetricsStorageGranularity)) { for (SlotKey slotKey: parentSlotKey.getChildrenKeys(delayedMetricsStorageGranularity)) { locators.addAll(getDelayedLocators(executionContext, slotKey)); } } else { locators = getDelayedLocators(executionContext, parentSlotKey.extrapolate(delayedMetricsStorageGranularity)); } } else { locators = getLocators(executionContext); } return locators; } LocatorFetchRunnable(ScheduleContext scheduleCtx,
SlotKey destSlotKey,
ExecutorService rollupReadExecutor,
ThreadPoolExecutor rollupWriteExecutor); } | LocatorFetchRunnable implements Runnable { protected Set<Locator> getLocators(RollupExecutionContext executionContext, boolean isReroll, Granularity delayedMetricsRerollGranularity, Granularity delayedMetricsStorageGranularity) { Set<Locator> locators = new HashSet<Locator>(); if (RECORD_DELAYED_METRICS && isReroll && !getGranularity().isCoarser(delayedMetricsRerollGranularity)) { if (getGranularity().isCoarser(delayedMetricsStorageGranularity)) { for (SlotKey slotKey: parentSlotKey.getChildrenKeys(delayedMetricsStorageGranularity)) { locators.addAll(getDelayedLocators(executionContext, slotKey)); } } else { locators = getDelayedLocators(executionContext, parentSlotKey.extrapolate(delayedMetricsStorageGranularity)); } } else { locators = getLocators(executionContext); } return locators; } LocatorFetchRunnable(ScheduleContext scheduleCtx,
SlotKey destSlotKey,
ExecutorService rollupReadExecutor,
ThreadPoolExecutor rollupWriteExecutor); @VisibleForTesting void initialize(ScheduleContext scheduleCtx,
SlotKey destSlotKey,
ExecutorService rollupReadExecutor,
ThreadPoolExecutor rollupWriteExecutor); void run(); void drainExecutionContext(long waitStart, int rollCount, RollupExecutionContext executionContext, RollupBatchWriter rollupBatchWriter); void finishExecution(long waitStart, RollupExecutionContext executionContext); int processLocator(int rollCount, RollupExecutionContext executionContext, RollupBatchWriter rollupBatchWriter, Locator locator); void executeRollupForLocator(RollupExecutionContext executionContext, RollupBatchWriter rollupBatchWriter, Locator locator); Set<Locator> getDelayedLocators(RollupExecutionContext executionContext, SlotKey slotkey); Set<Locator> getLocators(RollupExecutionContext executionContext); } | LocatorFetchRunnable implements Runnable { protected Set<Locator> getLocators(RollupExecutionContext executionContext, boolean isReroll, Granularity delayedMetricsRerollGranularity, Granularity delayedMetricsStorageGranularity) { Set<Locator> locators = new HashSet<Locator>(); if (RECORD_DELAYED_METRICS && isReroll && !getGranularity().isCoarser(delayedMetricsRerollGranularity)) { if (getGranularity().isCoarser(delayedMetricsStorageGranularity)) { for (SlotKey slotKey: parentSlotKey.getChildrenKeys(delayedMetricsStorageGranularity)) { locators.addAll(getDelayedLocators(executionContext, slotKey)); } } else { locators = getDelayedLocators(executionContext, parentSlotKey.extrapolate(delayedMetricsStorageGranularity)); } } else { locators = getLocators(executionContext); } return locators; } LocatorFetchRunnable(ScheduleContext scheduleCtx,
SlotKey destSlotKey,
ExecutorService rollupReadExecutor,
ThreadPoolExecutor rollupWriteExecutor); @VisibleForTesting void initialize(ScheduleContext scheduleCtx,
SlotKey destSlotKey,
ExecutorService rollupReadExecutor,
ThreadPoolExecutor rollupWriteExecutor); void run(); void drainExecutionContext(long waitStart, int rollCount, RollupExecutionContext executionContext, RollupBatchWriter rollupBatchWriter); void finishExecution(long waitStart, RollupExecutionContext executionContext); int processLocator(int rollCount, RollupExecutionContext executionContext, RollupBatchWriter rollupBatchWriter, Locator locator); void executeRollupForLocator(RollupExecutionContext executionContext, RollupBatchWriter rollupBatchWriter, Locator locator); Set<Locator> getDelayedLocators(RollupExecutionContext executionContext, SlotKey slotkey); Set<Locator> getLocators(RollupExecutionContext executionContext); } |
@Test public void testGetLocatorsForReRollHigherLevelToStorageGranularity() throws IOException { boolean isReroll = true; SlotKey destSlotKey = SlotKey.of(Granularity.MIN_60, 0, TEST_SHARD); Granularity delayedMetricsRerollGranularity = Granularity.MIN_60; Granularity delayedMetricsStorageGranularity = Granularity.MIN_20; LocatorFetchRunnable lfrunnable = new LocatorFetchRunnable(scheduleCtx, destSlotKey, rollupReadExecutor, rollupWriteExecutor); HashSet<Locator> delayedLocators1 = new HashSet<Locator>() {{ add(locators.get(0)); }}; HashSet<Locator> delayedLocators2 = new HashSet<Locator>() {{ add(locators.get(1)); }}; when(delayedLocatorIO.getLocators(SlotKey.of(Granularity.MIN_20, 0, TEST_SHARD))).thenReturn(delayedLocators1); when(delayedLocatorIO.getLocators(SlotKey.of(Granularity.MIN_20, 1, TEST_SHARD))).thenReturn(delayedLocators1); when(delayedLocatorIO.getLocators(SlotKey.of(Granularity.MIN_20, 2, TEST_SHARD))).thenReturn(delayedLocators2); Set<Locator> locatorsForRollup = lfrunnable.getLocators(executionContext, isReroll, delayedMetricsRerollGranularity, delayedMetricsStorageGranularity); assertEquals(delayedLocators1.size() + delayedLocators2.size(), locatorsForRollup.size()); } | protected Set<Locator> getLocators(RollupExecutionContext executionContext, boolean isReroll, Granularity delayedMetricsRerollGranularity, Granularity delayedMetricsStorageGranularity) { Set<Locator> locators = new HashSet<Locator>(); if (RECORD_DELAYED_METRICS && isReroll && !getGranularity().isCoarser(delayedMetricsRerollGranularity)) { if (getGranularity().isCoarser(delayedMetricsStorageGranularity)) { for (SlotKey slotKey: parentSlotKey.getChildrenKeys(delayedMetricsStorageGranularity)) { locators.addAll(getDelayedLocators(executionContext, slotKey)); } } else { locators = getDelayedLocators(executionContext, parentSlotKey.extrapolate(delayedMetricsStorageGranularity)); } } else { locators = getLocators(executionContext); } return locators; } | LocatorFetchRunnable implements Runnable { protected Set<Locator> getLocators(RollupExecutionContext executionContext, boolean isReroll, Granularity delayedMetricsRerollGranularity, Granularity delayedMetricsStorageGranularity) { Set<Locator> locators = new HashSet<Locator>(); if (RECORD_DELAYED_METRICS && isReroll && !getGranularity().isCoarser(delayedMetricsRerollGranularity)) { if (getGranularity().isCoarser(delayedMetricsStorageGranularity)) { for (SlotKey slotKey: parentSlotKey.getChildrenKeys(delayedMetricsStorageGranularity)) { locators.addAll(getDelayedLocators(executionContext, slotKey)); } } else { locators = getDelayedLocators(executionContext, parentSlotKey.extrapolate(delayedMetricsStorageGranularity)); } } else { locators = getLocators(executionContext); } return locators; } } | LocatorFetchRunnable implements Runnable { protected Set<Locator> getLocators(RollupExecutionContext executionContext, boolean isReroll, Granularity delayedMetricsRerollGranularity, Granularity delayedMetricsStorageGranularity) { Set<Locator> locators = new HashSet<Locator>(); if (RECORD_DELAYED_METRICS && isReroll && !getGranularity().isCoarser(delayedMetricsRerollGranularity)) { if (getGranularity().isCoarser(delayedMetricsStorageGranularity)) { for (SlotKey slotKey: parentSlotKey.getChildrenKeys(delayedMetricsStorageGranularity)) { locators.addAll(getDelayedLocators(executionContext, slotKey)); } } else { locators = getDelayedLocators(executionContext, parentSlotKey.extrapolate(delayedMetricsStorageGranularity)); } } else { locators = getLocators(executionContext); } return locators; } LocatorFetchRunnable(ScheduleContext scheduleCtx,
SlotKey destSlotKey,
ExecutorService rollupReadExecutor,
ThreadPoolExecutor rollupWriteExecutor); } | LocatorFetchRunnable implements Runnable { protected Set<Locator> getLocators(RollupExecutionContext executionContext, boolean isReroll, Granularity delayedMetricsRerollGranularity, Granularity delayedMetricsStorageGranularity) { Set<Locator> locators = new HashSet<Locator>(); if (RECORD_DELAYED_METRICS && isReroll && !getGranularity().isCoarser(delayedMetricsRerollGranularity)) { if (getGranularity().isCoarser(delayedMetricsStorageGranularity)) { for (SlotKey slotKey: parentSlotKey.getChildrenKeys(delayedMetricsStorageGranularity)) { locators.addAll(getDelayedLocators(executionContext, slotKey)); } } else { locators = getDelayedLocators(executionContext, parentSlotKey.extrapolate(delayedMetricsStorageGranularity)); } } else { locators = getLocators(executionContext); } return locators; } LocatorFetchRunnable(ScheduleContext scheduleCtx,
SlotKey destSlotKey,
ExecutorService rollupReadExecutor,
ThreadPoolExecutor rollupWriteExecutor); @VisibleForTesting void initialize(ScheduleContext scheduleCtx,
SlotKey destSlotKey,
ExecutorService rollupReadExecutor,
ThreadPoolExecutor rollupWriteExecutor); void run(); void drainExecutionContext(long waitStart, int rollCount, RollupExecutionContext executionContext, RollupBatchWriter rollupBatchWriter); void finishExecution(long waitStart, RollupExecutionContext executionContext); int processLocator(int rollCount, RollupExecutionContext executionContext, RollupBatchWriter rollupBatchWriter, Locator locator); void executeRollupForLocator(RollupExecutionContext executionContext, RollupBatchWriter rollupBatchWriter, Locator locator); Set<Locator> getDelayedLocators(RollupExecutionContext executionContext, SlotKey slotkey); Set<Locator> getLocators(RollupExecutionContext executionContext); } | LocatorFetchRunnable implements Runnable { protected Set<Locator> getLocators(RollupExecutionContext executionContext, boolean isReroll, Granularity delayedMetricsRerollGranularity, Granularity delayedMetricsStorageGranularity) { Set<Locator> locators = new HashSet<Locator>(); if (RECORD_DELAYED_METRICS && isReroll && !getGranularity().isCoarser(delayedMetricsRerollGranularity)) { if (getGranularity().isCoarser(delayedMetricsStorageGranularity)) { for (SlotKey slotKey: parentSlotKey.getChildrenKeys(delayedMetricsStorageGranularity)) { locators.addAll(getDelayedLocators(executionContext, slotKey)); } } else { locators = getDelayedLocators(executionContext, parentSlotKey.extrapolate(delayedMetricsStorageGranularity)); } } else { locators = getLocators(executionContext); } return locators; } LocatorFetchRunnable(ScheduleContext scheduleCtx,
SlotKey destSlotKey,
ExecutorService rollupReadExecutor,
ThreadPoolExecutor rollupWriteExecutor); @VisibleForTesting void initialize(ScheduleContext scheduleCtx,
SlotKey destSlotKey,
ExecutorService rollupReadExecutor,
ThreadPoolExecutor rollupWriteExecutor); void run(); void drainExecutionContext(long waitStart, int rollCount, RollupExecutionContext executionContext, RollupBatchWriter rollupBatchWriter); void finishExecution(long waitStart, RollupExecutionContext executionContext); int processLocator(int rollCount, RollupExecutionContext executionContext, RollupBatchWriter rollupBatchWriter, Locator locator); void executeRollupForLocator(RollupExecutionContext executionContext, RollupBatchWriter rollupBatchWriter, Locator locator); Set<Locator> getDelayedLocators(RollupExecutionContext executionContext, SlotKey slotkey); Set<Locator> getLocators(RollupExecutionContext executionContext); } |
@Test public void testGetLocatorsForReRollHigherLevelToRerollGranularity() throws IOException { boolean isReroll = true; SlotKey destSlotKey = SlotKey.of(Granularity.MIN_240, 0, TEST_SHARD); Granularity delayedMetricsRerollGranularity = Granularity.MIN_60; Granularity delayedMetricsStorageGranularity = Granularity.MIN_20; LocatorFetchRunnable lfrunnable = new LocatorFetchRunnable(scheduleCtx, destSlotKey, rollupReadExecutor, rollupWriteExecutor); Set<Locator> locatorsForRollup = lfrunnable.getLocators(executionContext, isReroll, delayedMetricsRerollGranularity, delayedMetricsStorageGranularity); assertEquals(locators.size(), locatorsForRollup.size()); } | protected Set<Locator> getLocators(RollupExecutionContext executionContext, boolean isReroll, Granularity delayedMetricsRerollGranularity, Granularity delayedMetricsStorageGranularity) { Set<Locator> locators = new HashSet<Locator>(); if (RECORD_DELAYED_METRICS && isReroll && !getGranularity().isCoarser(delayedMetricsRerollGranularity)) { if (getGranularity().isCoarser(delayedMetricsStorageGranularity)) { for (SlotKey slotKey: parentSlotKey.getChildrenKeys(delayedMetricsStorageGranularity)) { locators.addAll(getDelayedLocators(executionContext, slotKey)); } } else { locators = getDelayedLocators(executionContext, parentSlotKey.extrapolate(delayedMetricsStorageGranularity)); } } else { locators = getLocators(executionContext); } return locators; } | LocatorFetchRunnable implements Runnable { protected Set<Locator> getLocators(RollupExecutionContext executionContext, boolean isReroll, Granularity delayedMetricsRerollGranularity, Granularity delayedMetricsStorageGranularity) { Set<Locator> locators = new HashSet<Locator>(); if (RECORD_DELAYED_METRICS && isReroll && !getGranularity().isCoarser(delayedMetricsRerollGranularity)) { if (getGranularity().isCoarser(delayedMetricsStorageGranularity)) { for (SlotKey slotKey: parentSlotKey.getChildrenKeys(delayedMetricsStorageGranularity)) { locators.addAll(getDelayedLocators(executionContext, slotKey)); } } else { locators = getDelayedLocators(executionContext, parentSlotKey.extrapolate(delayedMetricsStorageGranularity)); } } else { locators = getLocators(executionContext); } return locators; } } | LocatorFetchRunnable implements Runnable { protected Set<Locator> getLocators(RollupExecutionContext executionContext, boolean isReroll, Granularity delayedMetricsRerollGranularity, Granularity delayedMetricsStorageGranularity) { Set<Locator> locators = new HashSet<Locator>(); if (RECORD_DELAYED_METRICS && isReroll && !getGranularity().isCoarser(delayedMetricsRerollGranularity)) { if (getGranularity().isCoarser(delayedMetricsStorageGranularity)) { for (SlotKey slotKey: parentSlotKey.getChildrenKeys(delayedMetricsStorageGranularity)) { locators.addAll(getDelayedLocators(executionContext, slotKey)); } } else { locators = getDelayedLocators(executionContext, parentSlotKey.extrapolate(delayedMetricsStorageGranularity)); } } else { locators = getLocators(executionContext); } return locators; } LocatorFetchRunnable(ScheduleContext scheduleCtx,
SlotKey destSlotKey,
ExecutorService rollupReadExecutor,
ThreadPoolExecutor rollupWriteExecutor); } | LocatorFetchRunnable implements Runnable { protected Set<Locator> getLocators(RollupExecutionContext executionContext, boolean isReroll, Granularity delayedMetricsRerollGranularity, Granularity delayedMetricsStorageGranularity) { Set<Locator> locators = new HashSet<Locator>(); if (RECORD_DELAYED_METRICS && isReroll && !getGranularity().isCoarser(delayedMetricsRerollGranularity)) { if (getGranularity().isCoarser(delayedMetricsStorageGranularity)) { for (SlotKey slotKey: parentSlotKey.getChildrenKeys(delayedMetricsStorageGranularity)) { locators.addAll(getDelayedLocators(executionContext, slotKey)); } } else { locators = getDelayedLocators(executionContext, parentSlotKey.extrapolate(delayedMetricsStorageGranularity)); } } else { locators = getLocators(executionContext); } return locators; } LocatorFetchRunnable(ScheduleContext scheduleCtx,
SlotKey destSlotKey,
ExecutorService rollupReadExecutor,
ThreadPoolExecutor rollupWriteExecutor); @VisibleForTesting void initialize(ScheduleContext scheduleCtx,
SlotKey destSlotKey,
ExecutorService rollupReadExecutor,
ThreadPoolExecutor rollupWriteExecutor); void run(); void drainExecutionContext(long waitStart, int rollCount, RollupExecutionContext executionContext, RollupBatchWriter rollupBatchWriter); void finishExecution(long waitStart, RollupExecutionContext executionContext); int processLocator(int rollCount, RollupExecutionContext executionContext, RollupBatchWriter rollupBatchWriter, Locator locator); void executeRollupForLocator(RollupExecutionContext executionContext, RollupBatchWriter rollupBatchWriter, Locator locator); Set<Locator> getDelayedLocators(RollupExecutionContext executionContext, SlotKey slotkey); Set<Locator> getLocators(RollupExecutionContext executionContext); } | LocatorFetchRunnable implements Runnable { protected Set<Locator> getLocators(RollupExecutionContext executionContext, boolean isReroll, Granularity delayedMetricsRerollGranularity, Granularity delayedMetricsStorageGranularity) { Set<Locator> locators = new HashSet<Locator>(); if (RECORD_DELAYED_METRICS && isReroll && !getGranularity().isCoarser(delayedMetricsRerollGranularity)) { if (getGranularity().isCoarser(delayedMetricsStorageGranularity)) { for (SlotKey slotKey: parentSlotKey.getChildrenKeys(delayedMetricsStorageGranularity)) { locators.addAll(getDelayedLocators(executionContext, slotKey)); } } else { locators = getDelayedLocators(executionContext, parentSlotKey.extrapolate(delayedMetricsStorageGranularity)); } } else { locators = getLocators(executionContext); } return locators; } LocatorFetchRunnable(ScheduleContext scheduleCtx,
SlotKey destSlotKey,
ExecutorService rollupReadExecutor,
ThreadPoolExecutor rollupWriteExecutor); @VisibleForTesting void initialize(ScheduleContext scheduleCtx,
SlotKey destSlotKey,
ExecutorService rollupReadExecutor,
ThreadPoolExecutor rollupWriteExecutor); void run(); void drainExecutionContext(long waitStart, int rollCount, RollupExecutionContext executionContext, RollupBatchWriter rollupBatchWriter); void finishExecution(long waitStart, RollupExecutionContext executionContext); int processLocator(int rollCount, RollupExecutionContext executionContext, RollupBatchWriter rollupBatchWriter, Locator locator); void executeRollupForLocator(RollupExecutionContext executionContext, RollupBatchWriter rollupBatchWriter, Locator locator); Set<Locator> getDelayedLocators(RollupExecutionContext executionContext, SlotKey slotkey); Set<Locator> getLocators(RollupExecutionContext executionContext); } |
@Test public void testOnce() { emitter.once(testEventName, listener); emitter.emit(testEventName, new RollupEvent(null, null, "payload1", "gran", 0)); Assert.assertEquals(store.size(), 1); store.clear(); emitter.emit(testEventName, new RollupEvent(null, null, "payload1", "gran", 0)); Assert.assertEquals(store.size(), 0); } | public Emitter once(final String event, final Listener<T> fn) { Listener on = new Listener<T>() { @Override public void call(T... args) { Emitter.this.off(event, this); fn.call(args); } }; this.onceCallbacks.put(fn, on); this.on(event, on); return this; } | Emitter { public Emitter once(final String event, final Listener<T> fn) { Listener on = new Listener<T>() { @Override public void call(T... args) { Emitter.this.off(event, this); fn.call(args); } }; this.onceCallbacks.put(fn, on); this.on(event, on); return this; } } | Emitter { public Emitter once(final String event, final Listener<T> fn) { Listener on = new Listener<T>() { @Override public void call(T... args) { Emitter.this.off(event, this); fn.call(args); } }; this.onceCallbacks.put(fn, on); this.on(event, on); return this; } } | Emitter { public Emitter once(final String event, final Listener<T> fn) { Listener on = new Listener<T>() { @Override public void call(T... args) { Emitter.this.off(event, this); fn.call(args); } }; this.onceCallbacks.put(fn, on); this.on(event, on); return this; } Emitter on(String event, Listener fn); Emitter once(final String event, final Listener<T> fn); Emitter off(); Emitter off(String event); Emitter off(String event, Listener fn); Future emit(String event, T... args); List<Listener> listeners(String event); boolean hasListeners(String event); } | Emitter { public Emitter once(final String event, final Listener<T> fn) { Listener on = new Listener<T>() { @Override public void call(T... args) { Emitter.this.off(event, this); fn.call(args); } }; this.onceCallbacks.put(fn, on); this.on(event, on); return this; } Emitter on(String event, Listener fn); Emitter once(final String event, final Listener<T> fn); Emitter off(); Emitter off(String event); Emitter off(String event, Listener fn); Future emit(String event, T... args); List<Listener> listeners(String event); boolean hasListeners(String event); } |
@Test public void testOn() { emitter.on(testEventName, listener); Assert.assertEquals(0, store.size()); emitter.emit(testEventName, event1); Assert.assertEquals(1, store.size()); Assert.assertSame(event1, store.get(0)); emitter.emit(testEventName, event2); Assert.assertEquals(2, store.size()); Assert.assertSame(event1, store.get(0)); Assert.assertSame(event2, store.get(1)); } | public Emitter on(String event, Listener fn) { ConcurrentLinkedQueue<Listener> callbacks = this.callbacks.get(event); if (callbacks == null) { callbacks = new ConcurrentLinkedQueue<Listener>(); ConcurrentLinkedQueue<Listener> _callbacks = this.callbacks.putIfAbsent(event, callbacks); if (_callbacks != null) { callbacks = _callbacks; } } callbacks.add(fn); return this; } | Emitter { public Emitter on(String event, Listener fn) { ConcurrentLinkedQueue<Listener> callbacks = this.callbacks.get(event); if (callbacks == null) { callbacks = new ConcurrentLinkedQueue<Listener>(); ConcurrentLinkedQueue<Listener> _callbacks = this.callbacks.putIfAbsent(event, callbacks); if (_callbacks != null) { callbacks = _callbacks; } } callbacks.add(fn); return this; } } | Emitter { public Emitter on(String event, Listener fn) { ConcurrentLinkedQueue<Listener> callbacks = this.callbacks.get(event); if (callbacks == null) { callbacks = new ConcurrentLinkedQueue<Listener>(); ConcurrentLinkedQueue<Listener> _callbacks = this.callbacks.putIfAbsent(event, callbacks); if (_callbacks != null) { callbacks = _callbacks; } } callbacks.add(fn); return this; } } | Emitter { public Emitter on(String event, Listener fn) { ConcurrentLinkedQueue<Listener> callbacks = this.callbacks.get(event); if (callbacks == null) { callbacks = new ConcurrentLinkedQueue<Listener>(); ConcurrentLinkedQueue<Listener> _callbacks = this.callbacks.putIfAbsent(event, callbacks); if (_callbacks != null) { callbacks = _callbacks; } } callbacks.add(fn); return this; } Emitter on(String event, Listener fn); Emitter once(final String event, final Listener<T> fn); Emitter off(); Emitter off(String event); Emitter off(String event, Listener fn); Future emit(String event, T... args); List<Listener> listeners(String event); boolean hasListeners(String event); } | Emitter { public Emitter on(String event, Listener fn) { ConcurrentLinkedQueue<Listener> callbacks = this.callbacks.get(event); if (callbacks == null) { callbacks = new ConcurrentLinkedQueue<Listener>(); ConcurrentLinkedQueue<Listener> _callbacks = this.callbacks.putIfAbsent(event, callbacks); if (_callbacks != null) { callbacks = _callbacks; } } callbacks.add(fn); return this; } Emitter on(String event, Listener fn); Emitter once(final String event, final Listener<T> fn); Emitter off(); Emitter off(String event); Emitter off(String event, Listener fn); Future emit(String event, T... args); List<Listener> listeners(String event); boolean hasListeners(String event); } |
@Test public void locatorGetsSetInConstructor() { Assert.assertSame(locator, event.getLocator()); } | public Locator getLocator() { return locator; } | RollupEvent { public Locator getLocator() { return locator; } } | RollupEvent { public Locator getLocator() { return locator; } RollupEvent(Locator loc, Rollup rollup, String unit, String gran, long ts); } | RollupEvent { public Locator getLocator() { return locator; } RollupEvent(Locator loc, Rollup rollup, String unit, String gran, long ts); Rollup getRollup(); Locator getLocator(); String getUnit(); String getGranularityName(); long getTimestamp(); void setUnit(String unit); } | RollupEvent { public Locator getLocator() { return locator; } RollupEvent(Locator loc, Rollup rollup, String unit, String gran, long ts); Rollup getRollup(); Locator getLocator(); String getUnit(); String getGranularityName(); long getTimestamp(); void setUnit(String unit); } |
@Test public void rollupGetsSetInConstructor() { Assert.assertSame(rollup, event.getRollup()); } | public Rollup getRollup() { return rollup; } | RollupEvent { public Rollup getRollup() { return rollup; } } | RollupEvent { public Rollup getRollup() { return rollup; } RollupEvent(Locator loc, Rollup rollup, String unit, String gran, long ts); } | RollupEvent { public Rollup getRollup() { return rollup; } RollupEvent(Locator loc, Rollup rollup, String unit, String gran, long ts); Rollup getRollup(); Locator getLocator(); String getUnit(); String getGranularityName(); long getTimestamp(); void setUnit(String unit); } | RollupEvent { public Rollup getRollup() { return rollup; } RollupEvent(Locator loc, Rollup rollup, String unit, String gran, long ts); Rollup getRollup(); Locator getLocator(); String getUnit(); String getGranularityName(); long getTimestamp(); void setUnit(String unit); } |
@Test public void unitGetsSetInConstructor() { Assert.assertEquals(unit, event.getUnit()); } | public String getUnit() { return unit; } | RollupEvent { public String getUnit() { return unit; } } | RollupEvent { public String getUnit() { return unit; } RollupEvent(Locator loc, Rollup rollup, String unit, String gran, long ts); } | RollupEvent { public String getUnit() { return unit; } RollupEvent(Locator loc, Rollup rollup, String unit, String gran, long ts); Rollup getRollup(); Locator getLocator(); String getUnit(); String getGranularityName(); long getTimestamp(); void setUnit(String unit); } | RollupEvent { public String getUnit() { return unit; } RollupEvent(Locator loc, Rollup rollup, String unit, String gran, long ts); Rollup getRollup(); Locator getLocator(); String getUnit(); String getGranularityName(); long getTimestamp(); void setUnit(String unit); } |
@Test public void granularityGetsSetInConstructor() { Assert.assertEquals(granularity, event.getGranularityName()); } | public String getGranularityName() { return granularityName; } | RollupEvent { public String getGranularityName() { return granularityName; } } | RollupEvent { public String getGranularityName() { return granularityName; } RollupEvent(Locator loc, Rollup rollup, String unit, String gran, long ts); } | RollupEvent { public String getGranularityName() { return granularityName; } RollupEvent(Locator loc, Rollup rollup, String unit, String gran, long ts); Rollup getRollup(); Locator getLocator(); String getUnit(); String getGranularityName(); long getTimestamp(); void setUnit(String unit); } | RollupEvent { public String getGranularityName() { return granularityName; } RollupEvent(Locator loc, Rollup rollup, String unit, String gran, long ts); Rollup getRollup(); Locator getLocator(); String getUnit(); String getGranularityName(); long getTimestamp(); void setUnit(String unit); } |
@Test public void firstTimeRetryOnWriteTimeout_shouldRetry() throws Exception { RetryNTimes retryPolicy = new RetryNTimes(3, 3, 3); Statement mockStatement = mock( Statement.class ); RetryPolicy.RetryDecision retryResult = retryPolicy.onWriteTimeout(mockStatement, ConsistencyLevel.LOCAL_ONE, WriteType.BATCH, 1, 0, 0); RetryPolicy.RetryDecision retryExpected = RetryPolicy.RetryDecision.retry(ConsistencyLevel.LOCAL_ONE); assertRetryDecisionEquals(retryExpected, retryResult); } | @Override public RetryDecision onWriteTimeout(Statement stmnt, ConsistencyLevel cl, WriteType wt, int requiredResponses, int receivedResponses, int wTime) { if (wTime < writeAttempts) { LOG.info(String.format("Retrying on WriteTimeout: stmnt %s, " + "consistency %s, writeType %s, requiredResponse %d, " + "receivedResponse %d, rTime %d", stmnt, cl, wt.toString(), requiredResponses, receivedResponses, wTime)); return RetryDecision.retry(cl); } return RetryDecision.rethrow(); } | RetryNTimes implements RetryPolicy { @Override public RetryDecision onWriteTimeout(Statement stmnt, ConsistencyLevel cl, WriteType wt, int requiredResponses, int receivedResponses, int wTime) { if (wTime < writeAttempts) { LOG.info(String.format("Retrying on WriteTimeout: stmnt %s, " + "consistency %s, writeType %s, requiredResponse %d, " + "receivedResponse %d, rTime %d", stmnt, cl, wt.toString(), requiredResponses, receivedResponses, wTime)); return RetryDecision.retry(cl); } return RetryDecision.rethrow(); } } | RetryNTimes implements RetryPolicy { @Override public RetryDecision onWriteTimeout(Statement stmnt, ConsistencyLevel cl, WriteType wt, int requiredResponses, int receivedResponses, int wTime) { if (wTime < writeAttempts) { LOG.info(String.format("Retrying on WriteTimeout: stmnt %s, " + "consistency %s, writeType %s, requiredResponse %d, " + "receivedResponse %d, rTime %d", stmnt, cl, wt.toString(), requiredResponses, receivedResponses, wTime)); return RetryDecision.retry(cl); } return RetryDecision.rethrow(); } RetryNTimes(int readAttempts, int writeAttempts, int unavailableAttempts); } | RetryNTimes implements RetryPolicy { @Override public RetryDecision onWriteTimeout(Statement stmnt, ConsistencyLevel cl, WriteType wt, int requiredResponses, int receivedResponses, int wTime) { if (wTime < writeAttempts) { LOG.info(String.format("Retrying on WriteTimeout: stmnt %s, " + "consistency %s, writeType %s, requiredResponse %d, " + "receivedResponse %d, rTime %d", stmnt, cl, wt.toString(), requiredResponses, receivedResponses, wTime)); return RetryDecision.retry(cl); } return RetryDecision.rethrow(); } RetryNTimes(int readAttempts, int writeAttempts, int unavailableAttempts); @Override RetryDecision onReadTimeout(Statement stmnt, ConsistencyLevel cl,
int requiredResponses, int receivedResponses,
boolean dataReceived, int rTime); @Override RetryDecision onWriteTimeout(Statement stmnt, ConsistencyLevel cl,
WriteType wt, int requiredResponses,
int receivedResponses, int wTime); @Override RetryDecision onUnavailable(Statement stmnt, ConsistencyLevel cl,
int requiredResponses, int receivedResponses, int uTime); @Override RetryDecision onRequestError(Statement statement, ConsistencyLevel cl, DriverException e, int nbRetry); @Override void init(Cluster cluster); @Override void close(); } | RetryNTimes implements RetryPolicy { @Override public RetryDecision onWriteTimeout(Statement stmnt, ConsistencyLevel cl, WriteType wt, int requiredResponses, int receivedResponses, int wTime) { if (wTime < writeAttempts) { LOG.info(String.format("Retrying on WriteTimeout: stmnt %s, " + "consistency %s, writeType %s, requiredResponse %d, " + "receivedResponse %d, rTime %d", stmnt, cl, wt.toString(), requiredResponses, receivedResponses, wTime)); return RetryDecision.retry(cl); } return RetryDecision.rethrow(); } RetryNTimes(int readAttempts, int writeAttempts, int unavailableAttempts); @Override RetryDecision onReadTimeout(Statement stmnt, ConsistencyLevel cl,
int requiredResponses, int receivedResponses,
boolean dataReceived, int rTime); @Override RetryDecision onWriteTimeout(Statement stmnt, ConsistencyLevel cl,
WriteType wt, int requiredResponses,
int receivedResponses, int wTime); @Override RetryDecision onUnavailable(Statement stmnt, ConsistencyLevel cl,
int requiredResponses, int receivedResponses, int uTime); @Override RetryDecision onRequestError(Statement statement, ConsistencyLevel cl, DriverException e, int nbRetry); @Override void init(Cluster cluster); @Override void close(); } |
@Test public void timestampGetsSetInConstructor() { Assert.assertEquals(timestamp, event.getTimestamp()); } | public long getTimestamp() { return timestamp; } | RollupEvent { public long getTimestamp() { return timestamp; } } | RollupEvent { public long getTimestamp() { return timestamp; } RollupEvent(Locator loc, Rollup rollup, String unit, String gran, long ts); } | RollupEvent { public long getTimestamp() { return timestamp; } RollupEvent(Locator loc, Rollup rollup, String unit, String gran, long ts); Rollup getRollup(); Locator getLocator(); String getUnit(); String getGranularityName(); long getTimestamp(); void setUnit(String unit); } | RollupEvent { public long getTimestamp() { return timestamp; } RollupEvent(Locator loc, Rollup rollup, String unit, String gran, long ts); Rollup getRollup(); Locator getLocator(); String getUnit(); String getGranularityName(); long getTimestamp(); void setUnit(String unit); } |
@Test public void testConcurrentEmission() throws InterruptedException, ExecutionException { emitter.on(testEventName, listener); ThreadPoolExecutor executors = new ThreadPoolBuilder() .withCorePoolSize(2) .withMaxPoolSize(3) .build(); final CountDownLatch startLatch = new CountDownLatch(1); Future<Object> f1 = executors.submit(new Callable<Object>() { @Override public Object call() throws Exception { startLatch.await(); emitter.emit(testEventName, event1); return null; } }); Future<Object> f2 = executors.submit(new Callable<Object>() { @Override public Object call() throws Exception { startLatch.await(); emitter.emit(testEventName, event2); return null; } }); Thread.sleep(1000); Assert.assertTrue(store.isEmpty()); startLatch.countDown(); f1.get(); f2.get(); Assert.assertEquals(store.size(), 2); Assert.assertTrue(store.contains(event1)); Assert.assertTrue(store.contains(event2)); } | @Override public Future emit(final String event, final RollupEvent... eventPayload) { Future emitFuture = null; if(eventPayload[0].getRollup() instanceof BasicRollup && super.hasListeners(ROLLUP_EVENT_NAME)) { emitFuture = eventExecutors.submit(new Callable() { @Override public Future call() { if (Util.shouldUseESForUnits()) { final DiscoveryIO discoveryIO = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Lists.transform(Arrays.asList(eventPayload), new Function<RollupEvent, RollupEvent>() { @Override public RollupEvent apply(RollupEvent event) { String unit; try { unit = discoveryIO.search(event.getLocator().getTenantId(), event.getLocator().getMetricName()).get(0).getUnit(); } catch (Exception e) { log.warn("Exception encountered while getting units out of ES : %s", e.getMessage()); unit = Util.UNKNOWN; } event.setUnit(unit); return event; } }); } return RollupEventEmitter.super.emit(event, eventPayload); } }); } return emitFuture; } | RollupEventEmitter extends Emitter<RollupEvent> { @Override public Future emit(final String event, final RollupEvent... eventPayload) { Future emitFuture = null; if(eventPayload[0].getRollup() instanceof BasicRollup && super.hasListeners(ROLLUP_EVENT_NAME)) { emitFuture = eventExecutors.submit(new Callable() { @Override public Future call() { if (Util.shouldUseESForUnits()) { final DiscoveryIO discoveryIO = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Lists.transform(Arrays.asList(eventPayload), new Function<RollupEvent, RollupEvent>() { @Override public RollupEvent apply(RollupEvent event) { String unit; try { unit = discoveryIO.search(event.getLocator().getTenantId(), event.getLocator().getMetricName()).get(0).getUnit(); } catch (Exception e) { log.warn("Exception encountered while getting units out of ES : %s", e.getMessage()); unit = Util.UNKNOWN; } event.setUnit(unit); return event; } }); } return RollupEventEmitter.super.emit(event, eventPayload); } }); } return emitFuture; } } | RollupEventEmitter extends Emitter<RollupEvent> { @Override public Future emit(final String event, final RollupEvent... eventPayload) { Future emitFuture = null; if(eventPayload[0].getRollup() instanceof BasicRollup && super.hasListeners(ROLLUP_EVENT_NAME)) { emitFuture = eventExecutors.submit(new Callable() { @Override public Future call() { if (Util.shouldUseESForUnits()) { final DiscoveryIO discoveryIO = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Lists.transform(Arrays.asList(eventPayload), new Function<RollupEvent, RollupEvent>() { @Override public RollupEvent apply(RollupEvent event) { String unit; try { unit = discoveryIO.search(event.getLocator().getTenantId(), event.getLocator().getMetricName()).get(0).getUnit(); } catch (Exception e) { log.warn("Exception encountered while getting units out of ES : %s", e.getMessage()); unit = Util.UNKNOWN; } event.setUnit(unit); return event; } }); } return RollupEventEmitter.super.emit(event, eventPayload); } }); } return emitFuture; } RollupEventEmitter(); @VisibleForTesting RollupEventEmitter(ExecutorService executor); } | RollupEventEmitter extends Emitter<RollupEvent> { @Override public Future emit(final String event, final RollupEvent... eventPayload) { Future emitFuture = null; if(eventPayload[0].getRollup() instanceof BasicRollup && super.hasListeners(ROLLUP_EVENT_NAME)) { emitFuture = eventExecutors.submit(new Callable() { @Override public Future call() { if (Util.shouldUseESForUnits()) { final DiscoveryIO discoveryIO = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Lists.transform(Arrays.asList(eventPayload), new Function<RollupEvent, RollupEvent>() { @Override public RollupEvent apply(RollupEvent event) { String unit; try { unit = discoveryIO.search(event.getLocator().getTenantId(), event.getLocator().getMetricName()).get(0).getUnit(); } catch (Exception e) { log.warn("Exception encountered while getting units out of ES : %s", e.getMessage()); unit = Util.UNKNOWN; } event.setUnit(unit); return event; } }); } return RollupEventEmitter.super.emit(event, eventPayload); } }); } return emitFuture; } RollupEventEmitter(); @VisibleForTesting RollupEventEmitter(ExecutorService executor); static RollupEventEmitter getInstance(); @Override Future emit(final String event, final RollupEvent... eventPayload); } | RollupEventEmitter extends Emitter<RollupEvent> { @Override public Future emit(final String event, final RollupEvent... eventPayload) { Future emitFuture = null; if(eventPayload[0].getRollup() instanceof BasicRollup && super.hasListeners(ROLLUP_EVENT_NAME)) { emitFuture = eventExecutors.submit(new Callable() { @Override public Future call() { if (Util.shouldUseESForUnits()) { final DiscoveryIO discoveryIO = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Lists.transform(Arrays.asList(eventPayload), new Function<RollupEvent, RollupEvent>() { @Override public RollupEvent apply(RollupEvent event) { String unit; try { unit = discoveryIO.search(event.getLocator().getTenantId(), event.getLocator().getMetricName()).get(0).getUnit(); } catch (Exception e) { log.warn("Exception encountered while getting units out of ES : %s", e.getMessage()); unit = Util.UNKNOWN; } event.setUnit(unit); return event; } }); } return RollupEventEmitter.super.emit(event, eventPayload); } }); } return emitFuture; } RollupEventEmitter(); @VisibleForTesting RollupEventEmitter(ExecutorService executor); static RollupEventEmitter getInstance(); @Override Future emit(final String event, final RollupEvent... eventPayload); static final String ROLLUP_EVENT_NAME; } |
@Test public void testUnsubscription() { emitter.on(testEventName, listener); emitter.off(testEventName, listener); Assert.assertFalse(emitter.listeners(testEventName).contains(listener)); store.clear(); emitter.emit(testEventName, new RollupEvent(null, null, "payload3", "gran", 0)); Assert.assertTrue(store.isEmpty()); } | @Override public Future emit(final String event, final RollupEvent... eventPayload) { Future emitFuture = null; if(eventPayload[0].getRollup() instanceof BasicRollup && super.hasListeners(ROLLUP_EVENT_NAME)) { emitFuture = eventExecutors.submit(new Callable() { @Override public Future call() { if (Util.shouldUseESForUnits()) { final DiscoveryIO discoveryIO = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Lists.transform(Arrays.asList(eventPayload), new Function<RollupEvent, RollupEvent>() { @Override public RollupEvent apply(RollupEvent event) { String unit; try { unit = discoveryIO.search(event.getLocator().getTenantId(), event.getLocator().getMetricName()).get(0).getUnit(); } catch (Exception e) { log.warn("Exception encountered while getting units out of ES : %s", e.getMessage()); unit = Util.UNKNOWN; } event.setUnit(unit); return event; } }); } return RollupEventEmitter.super.emit(event, eventPayload); } }); } return emitFuture; } | RollupEventEmitter extends Emitter<RollupEvent> { @Override public Future emit(final String event, final RollupEvent... eventPayload) { Future emitFuture = null; if(eventPayload[0].getRollup() instanceof BasicRollup && super.hasListeners(ROLLUP_EVENT_NAME)) { emitFuture = eventExecutors.submit(new Callable() { @Override public Future call() { if (Util.shouldUseESForUnits()) { final DiscoveryIO discoveryIO = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Lists.transform(Arrays.asList(eventPayload), new Function<RollupEvent, RollupEvent>() { @Override public RollupEvent apply(RollupEvent event) { String unit; try { unit = discoveryIO.search(event.getLocator().getTenantId(), event.getLocator().getMetricName()).get(0).getUnit(); } catch (Exception e) { log.warn("Exception encountered while getting units out of ES : %s", e.getMessage()); unit = Util.UNKNOWN; } event.setUnit(unit); return event; } }); } return RollupEventEmitter.super.emit(event, eventPayload); } }); } return emitFuture; } } | RollupEventEmitter extends Emitter<RollupEvent> { @Override public Future emit(final String event, final RollupEvent... eventPayload) { Future emitFuture = null; if(eventPayload[0].getRollup() instanceof BasicRollup && super.hasListeners(ROLLUP_EVENT_NAME)) { emitFuture = eventExecutors.submit(new Callable() { @Override public Future call() { if (Util.shouldUseESForUnits()) { final DiscoveryIO discoveryIO = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Lists.transform(Arrays.asList(eventPayload), new Function<RollupEvent, RollupEvent>() { @Override public RollupEvent apply(RollupEvent event) { String unit; try { unit = discoveryIO.search(event.getLocator().getTenantId(), event.getLocator().getMetricName()).get(0).getUnit(); } catch (Exception e) { log.warn("Exception encountered while getting units out of ES : %s", e.getMessage()); unit = Util.UNKNOWN; } event.setUnit(unit); return event; } }); } return RollupEventEmitter.super.emit(event, eventPayload); } }); } return emitFuture; } RollupEventEmitter(); @VisibleForTesting RollupEventEmitter(ExecutorService executor); } | RollupEventEmitter extends Emitter<RollupEvent> { @Override public Future emit(final String event, final RollupEvent... eventPayload) { Future emitFuture = null; if(eventPayload[0].getRollup() instanceof BasicRollup && super.hasListeners(ROLLUP_EVENT_NAME)) { emitFuture = eventExecutors.submit(new Callable() { @Override public Future call() { if (Util.shouldUseESForUnits()) { final DiscoveryIO discoveryIO = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Lists.transform(Arrays.asList(eventPayload), new Function<RollupEvent, RollupEvent>() { @Override public RollupEvent apply(RollupEvent event) { String unit; try { unit = discoveryIO.search(event.getLocator().getTenantId(), event.getLocator().getMetricName()).get(0).getUnit(); } catch (Exception e) { log.warn("Exception encountered while getting units out of ES : %s", e.getMessage()); unit = Util.UNKNOWN; } event.setUnit(unit); return event; } }); } return RollupEventEmitter.super.emit(event, eventPayload); } }); } return emitFuture; } RollupEventEmitter(); @VisibleForTesting RollupEventEmitter(ExecutorService executor); static RollupEventEmitter getInstance(); @Override Future emit(final String event, final RollupEvent... eventPayload); } | RollupEventEmitter extends Emitter<RollupEvent> { @Override public Future emit(final String event, final RollupEvent... eventPayload) { Future emitFuture = null; if(eventPayload[0].getRollup() instanceof BasicRollup && super.hasListeners(ROLLUP_EVENT_NAME)) { emitFuture = eventExecutors.submit(new Callable() { @Override public Future call() { if (Util.shouldUseESForUnits()) { final DiscoveryIO discoveryIO = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Lists.transform(Arrays.asList(eventPayload), new Function<RollupEvent, RollupEvent>() { @Override public RollupEvent apply(RollupEvent event) { String unit; try { unit = discoveryIO.search(event.getLocator().getTenantId(), event.getLocator().getMetricName()).get(0).getUnit(); } catch (Exception e) { log.warn("Exception encountered while getting units out of ES : %s", e.getMessage()); unit = Util.UNKNOWN; } event.setUnit(unit); return event; } }); } return RollupEventEmitter.super.emit(event, eventPayload); } }); } return emitFuture; } RollupEventEmitter(); @VisibleForTesting RollupEventEmitter(ExecutorService executor); static RollupEventEmitter getInstance(); @Override Future emit(final String event, final RollupEvent... eventPayload); static final String ROLLUP_EVENT_NAME; } |
@Test public void testOnce() throws ExecutionException, InterruptedException { emitter.once(testEventName, listener); Future f = emitter.emit(testEventName, event1); f.get(); Assert.assertEquals(store.size(), 1); store.clear(); emitter.emit(testEventName, event2); Assert.assertEquals(store.size(), 0); } | @Override public Future emit(final String event, final RollupEvent... eventPayload) { Future emitFuture = null; if(eventPayload[0].getRollup() instanceof BasicRollup && super.hasListeners(ROLLUP_EVENT_NAME)) { emitFuture = eventExecutors.submit(new Callable() { @Override public Future call() { if (Util.shouldUseESForUnits()) { final DiscoveryIO discoveryIO = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Lists.transform(Arrays.asList(eventPayload), new Function<RollupEvent, RollupEvent>() { @Override public RollupEvent apply(RollupEvent event) { String unit; try { unit = discoveryIO.search(event.getLocator().getTenantId(), event.getLocator().getMetricName()).get(0).getUnit(); } catch (Exception e) { log.warn("Exception encountered while getting units out of ES : %s", e.getMessage()); unit = Util.UNKNOWN; } event.setUnit(unit); return event; } }); } return RollupEventEmitter.super.emit(event, eventPayload); } }); } return emitFuture; } | RollupEventEmitter extends Emitter<RollupEvent> { @Override public Future emit(final String event, final RollupEvent... eventPayload) { Future emitFuture = null; if(eventPayload[0].getRollup() instanceof BasicRollup && super.hasListeners(ROLLUP_EVENT_NAME)) { emitFuture = eventExecutors.submit(new Callable() { @Override public Future call() { if (Util.shouldUseESForUnits()) { final DiscoveryIO discoveryIO = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Lists.transform(Arrays.asList(eventPayload), new Function<RollupEvent, RollupEvent>() { @Override public RollupEvent apply(RollupEvent event) { String unit; try { unit = discoveryIO.search(event.getLocator().getTenantId(), event.getLocator().getMetricName()).get(0).getUnit(); } catch (Exception e) { log.warn("Exception encountered while getting units out of ES : %s", e.getMessage()); unit = Util.UNKNOWN; } event.setUnit(unit); return event; } }); } return RollupEventEmitter.super.emit(event, eventPayload); } }); } return emitFuture; } } | RollupEventEmitter extends Emitter<RollupEvent> { @Override public Future emit(final String event, final RollupEvent... eventPayload) { Future emitFuture = null; if(eventPayload[0].getRollup() instanceof BasicRollup && super.hasListeners(ROLLUP_EVENT_NAME)) { emitFuture = eventExecutors.submit(new Callable() { @Override public Future call() { if (Util.shouldUseESForUnits()) { final DiscoveryIO discoveryIO = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Lists.transform(Arrays.asList(eventPayload), new Function<RollupEvent, RollupEvent>() { @Override public RollupEvent apply(RollupEvent event) { String unit; try { unit = discoveryIO.search(event.getLocator().getTenantId(), event.getLocator().getMetricName()).get(0).getUnit(); } catch (Exception e) { log.warn("Exception encountered while getting units out of ES : %s", e.getMessage()); unit = Util.UNKNOWN; } event.setUnit(unit); return event; } }); } return RollupEventEmitter.super.emit(event, eventPayload); } }); } return emitFuture; } RollupEventEmitter(); @VisibleForTesting RollupEventEmitter(ExecutorService executor); } | RollupEventEmitter extends Emitter<RollupEvent> { @Override public Future emit(final String event, final RollupEvent... eventPayload) { Future emitFuture = null; if(eventPayload[0].getRollup() instanceof BasicRollup && super.hasListeners(ROLLUP_EVENT_NAME)) { emitFuture = eventExecutors.submit(new Callable() { @Override public Future call() { if (Util.shouldUseESForUnits()) { final DiscoveryIO discoveryIO = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Lists.transform(Arrays.asList(eventPayload), new Function<RollupEvent, RollupEvent>() { @Override public RollupEvent apply(RollupEvent event) { String unit; try { unit = discoveryIO.search(event.getLocator().getTenantId(), event.getLocator().getMetricName()).get(0).getUnit(); } catch (Exception e) { log.warn("Exception encountered while getting units out of ES : %s", e.getMessage()); unit = Util.UNKNOWN; } event.setUnit(unit); return event; } }); } return RollupEventEmitter.super.emit(event, eventPayload); } }); } return emitFuture; } RollupEventEmitter(); @VisibleForTesting RollupEventEmitter(ExecutorService executor); static RollupEventEmitter getInstance(); @Override Future emit(final String event, final RollupEvent... eventPayload); } | RollupEventEmitter extends Emitter<RollupEvent> { @Override public Future emit(final String event, final RollupEvent... eventPayload) { Future emitFuture = null; if(eventPayload[0].getRollup() instanceof BasicRollup && super.hasListeners(ROLLUP_EVENT_NAME)) { emitFuture = eventExecutors.submit(new Callable() { @Override public Future call() { if (Util.shouldUseESForUnits()) { final DiscoveryIO discoveryIO = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Lists.transform(Arrays.asList(eventPayload), new Function<RollupEvent, RollupEvent>() { @Override public RollupEvent apply(RollupEvent event) { String unit; try { unit = discoveryIO.search(event.getLocator().getTenantId(), event.getLocator().getMetricName()).get(0).getUnit(); } catch (Exception e) { log.warn("Exception encountered while getting units out of ES : %s", e.getMessage()); unit = Util.UNKNOWN; } event.setUnit(unit); return event; } }); } return RollupEventEmitter.super.emit(event, eventPayload); } }); } return emitFuture; } RollupEventEmitter(); @VisibleForTesting RollupEventEmitter(ExecutorService executor); static RollupEventEmitter getInstance(); @Override Future emit(final String event, final RollupEvent... eventPayload); static final String ROLLUP_EVENT_NAME; } |
@Test public void testOn() { emitter.on(testEventName, listener); Assert.assertEquals(0, store.size()); emitter.emit(testEventName, event1); Assert.assertEquals(1, store.size()); Assert.assertSame(event1, store.get(0)); emitter.emit(testEventName, event2); Assert.assertEquals(2, store.size()); Assert.assertSame(event1, store.get(0)); Assert.assertSame(event2, store.get(1)); } | @Override public Future emit(final String event, final RollupEvent... eventPayload) { Future emitFuture = null; if(eventPayload[0].getRollup() instanceof BasicRollup && super.hasListeners(ROLLUP_EVENT_NAME)) { emitFuture = eventExecutors.submit(new Callable() { @Override public Future call() { if (Util.shouldUseESForUnits()) { final DiscoveryIO discoveryIO = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Lists.transform(Arrays.asList(eventPayload), new Function<RollupEvent, RollupEvent>() { @Override public RollupEvent apply(RollupEvent event) { String unit; try { unit = discoveryIO.search(event.getLocator().getTenantId(), event.getLocator().getMetricName()).get(0).getUnit(); } catch (Exception e) { log.warn("Exception encountered while getting units out of ES : %s", e.getMessage()); unit = Util.UNKNOWN; } event.setUnit(unit); return event; } }); } return RollupEventEmitter.super.emit(event, eventPayload); } }); } return emitFuture; } | RollupEventEmitter extends Emitter<RollupEvent> { @Override public Future emit(final String event, final RollupEvent... eventPayload) { Future emitFuture = null; if(eventPayload[0].getRollup() instanceof BasicRollup && super.hasListeners(ROLLUP_EVENT_NAME)) { emitFuture = eventExecutors.submit(new Callable() { @Override public Future call() { if (Util.shouldUseESForUnits()) { final DiscoveryIO discoveryIO = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Lists.transform(Arrays.asList(eventPayload), new Function<RollupEvent, RollupEvent>() { @Override public RollupEvent apply(RollupEvent event) { String unit; try { unit = discoveryIO.search(event.getLocator().getTenantId(), event.getLocator().getMetricName()).get(0).getUnit(); } catch (Exception e) { log.warn("Exception encountered while getting units out of ES : %s", e.getMessage()); unit = Util.UNKNOWN; } event.setUnit(unit); return event; } }); } return RollupEventEmitter.super.emit(event, eventPayload); } }); } return emitFuture; } } | RollupEventEmitter extends Emitter<RollupEvent> { @Override public Future emit(final String event, final RollupEvent... eventPayload) { Future emitFuture = null; if(eventPayload[0].getRollup() instanceof BasicRollup && super.hasListeners(ROLLUP_EVENT_NAME)) { emitFuture = eventExecutors.submit(new Callable() { @Override public Future call() { if (Util.shouldUseESForUnits()) { final DiscoveryIO discoveryIO = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Lists.transform(Arrays.asList(eventPayload), new Function<RollupEvent, RollupEvent>() { @Override public RollupEvent apply(RollupEvent event) { String unit; try { unit = discoveryIO.search(event.getLocator().getTenantId(), event.getLocator().getMetricName()).get(0).getUnit(); } catch (Exception e) { log.warn("Exception encountered while getting units out of ES : %s", e.getMessage()); unit = Util.UNKNOWN; } event.setUnit(unit); return event; } }); } return RollupEventEmitter.super.emit(event, eventPayload); } }); } return emitFuture; } RollupEventEmitter(); @VisibleForTesting RollupEventEmitter(ExecutorService executor); } | RollupEventEmitter extends Emitter<RollupEvent> { @Override public Future emit(final String event, final RollupEvent... eventPayload) { Future emitFuture = null; if(eventPayload[0].getRollup() instanceof BasicRollup && super.hasListeners(ROLLUP_EVENT_NAME)) { emitFuture = eventExecutors.submit(new Callable() { @Override public Future call() { if (Util.shouldUseESForUnits()) { final DiscoveryIO discoveryIO = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Lists.transform(Arrays.asList(eventPayload), new Function<RollupEvent, RollupEvent>() { @Override public RollupEvent apply(RollupEvent event) { String unit; try { unit = discoveryIO.search(event.getLocator().getTenantId(), event.getLocator().getMetricName()).get(0).getUnit(); } catch (Exception e) { log.warn("Exception encountered while getting units out of ES : %s", e.getMessage()); unit = Util.UNKNOWN; } event.setUnit(unit); return event; } }); } return RollupEventEmitter.super.emit(event, eventPayload); } }); } return emitFuture; } RollupEventEmitter(); @VisibleForTesting RollupEventEmitter(ExecutorService executor); static RollupEventEmitter getInstance(); @Override Future emit(final String event, final RollupEvent... eventPayload); } | RollupEventEmitter extends Emitter<RollupEvent> { @Override public Future emit(final String event, final RollupEvent... eventPayload) { Future emitFuture = null; if(eventPayload[0].getRollup() instanceof BasicRollup && super.hasListeners(ROLLUP_EVENT_NAME)) { emitFuture = eventExecutors.submit(new Callable() { @Override public Future call() { if (Util.shouldUseESForUnits()) { final DiscoveryIO discoveryIO = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Lists.transform(Arrays.asList(eventPayload), new Function<RollupEvent, RollupEvent>() { @Override public RollupEvent apply(RollupEvent event) { String unit; try { unit = discoveryIO.search(event.getLocator().getTenantId(), event.getLocator().getMetricName()).get(0).getUnit(); } catch (Exception e) { log.warn("Exception encountered while getting units out of ES : %s", e.getMessage()); unit = Util.UNKNOWN; } event.setUnit(unit); return event; } }); } return RollupEventEmitter.super.emit(event, eventPayload); } }); } return emitFuture; } RollupEventEmitter(); @VisibleForTesting RollupEventEmitter(ExecutorService executor); static RollupEventEmitter getInstance(); @Override Future emit(final String event, final RollupEvent... eventPayload); static final String ROLLUP_EVENT_NAME; } |
@Test public void offClearsRegularCallbacks() { emitter.on(testEventName, listener); Assert.assertEquals(0, store.size()); emitter.off(); emitter.emit(testEventName, event1); Assert.assertEquals(0, store.size()); } | @Override public Future emit(final String event, final RollupEvent... eventPayload) { Future emitFuture = null; if(eventPayload[0].getRollup() instanceof BasicRollup && super.hasListeners(ROLLUP_EVENT_NAME)) { emitFuture = eventExecutors.submit(new Callable() { @Override public Future call() { if (Util.shouldUseESForUnits()) { final DiscoveryIO discoveryIO = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Lists.transform(Arrays.asList(eventPayload), new Function<RollupEvent, RollupEvent>() { @Override public RollupEvent apply(RollupEvent event) { String unit; try { unit = discoveryIO.search(event.getLocator().getTenantId(), event.getLocator().getMetricName()).get(0).getUnit(); } catch (Exception e) { log.warn("Exception encountered while getting units out of ES : %s", e.getMessage()); unit = Util.UNKNOWN; } event.setUnit(unit); return event; } }); } return RollupEventEmitter.super.emit(event, eventPayload); } }); } return emitFuture; } | RollupEventEmitter extends Emitter<RollupEvent> { @Override public Future emit(final String event, final RollupEvent... eventPayload) { Future emitFuture = null; if(eventPayload[0].getRollup() instanceof BasicRollup && super.hasListeners(ROLLUP_EVENT_NAME)) { emitFuture = eventExecutors.submit(new Callable() { @Override public Future call() { if (Util.shouldUseESForUnits()) { final DiscoveryIO discoveryIO = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Lists.transform(Arrays.asList(eventPayload), new Function<RollupEvent, RollupEvent>() { @Override public RollupEvent apply(RollupEvent event) { String unit; try { unit = discoveryIO.search(event.getLocator().getTenantId(), event.getLocator().getMetricName()).get(0).getUnit(); } catch (Exception e) { log.warn("Exception encountered while getting units out of ES : %s", e.getMessage()); unit = Util.UNKNOWN; } event.setUnit(unit); return event; } }); } return RollupEventEmitter.super.emit(event, eventPayload); } }); } return emitFuture; } } | RollupEventEmitter extends Emitter<RollupEvent> { @Override public Future emit(final String event, final RollupEvent... eventPayload) { Future emitFuture = null; if(eventPayload[0].getRollup() instanceof BasicRollup && super.hasListeners(ROLLUP_EVENT_NAME)) { emitFuture = eventExecutors.submit(new Callable() { @Override public Future call() { if (Util.shouldUseESForUnits()) { final DiscoveryIO discoveryIO = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Lists.transform(Arrays.asList(eventPayload), new Function<RollupEvent, RollupEvent>() { @Override public RollupEvent apply(RollupEvent event) { String unit; try { unit = discoveryIO.search(event.getLocator().getTenantId(), event.getLocator().getMetricName()).get(0).getUnit(); } catch (Exception e) { log.warn("Exception encountered while getting units out of ES : %s", e.getMessage()); unit = Util.UNKNOWN; } event.setUnit(unit); return event; } }); } return RollupEventEmitter.super.emit(event, eventPayload); } }); } return emitFuture; } RollupEventEmitter(); @VisibleForTesting RollupEventEmitter(ExecutorService executor); } | RollupEventEmitter extends Emitter<RollupEvent> { @Override public Future emit(final String event, final RollupEvent... eventPayload) { Future emitFuture = null; if(eventPayload[0].getRollup() instanceof BasicRollup && super.hasListeners(ROLLUP_EVENT_NAME)) { emitFuture = eventExecutors.submit(new Callable() { @Override public Future call() { if (Util.shouldUseESForUnits()) { final DiscoveryIO discoveryIO = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Lists.transform(Arrays.asList(eventPayload), new Function<RollupEvent, RollupEvent>() { @Override public RollupEvent apply(RollupEvent event) { String unit; try { unit = discoveryIO.search(event.getLocator().getTenantId(), event.getLocator().getMetricName()).get(0).getUnit(); } catch (Exception e) { log.warn("Exception encountered while getting units out of ES : %s", e.getMessage()); unit = Util.UNKNOWN; } event.setUnit(unit); return event; } }); } return RollupEventEmitter.super.emit(event, eventPayload); } }); } return emitFuture; } RollupEventEmitter(); @VisibleForTesting RollupEventEmitter(ExecutorService executor); static RollupEventEmitter getInstance(); @Override Future emit(final String event, final RollupEvent... eventPayload); } | RollupEventEmitter extends Emitter<RollupEvent> { @Override public Future emit(final String event, final RollupEvent... eventPayload) { Future emitFuture = null; if(eventPayload[0].getRollup() instanceof BasicRollup && super.hasListeners(ROLLUP_EVENT_NAME)) { emitFuture = eventExecutors.submit(new Callable() { @Override public Future call() { if (Util.shouldUseESForUnits()) { final DiscoveryIO discoveryIO = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Lists.transform(Arrays.asList(eventPayload), new Function<RollupEvent, RollupEvent>() { @Override public RollupEvent apply(RollupEvent event) { String unit; try { unit = discoveryIO.search(event.getLocator().getTenantId(), event.getLocator().getMetricName()).get(0).getUnit(); } catch (Exception e) { log.warn("Exception encountered while getting units out of ES : %s", e.getMessage()); unit = Util.UNKNOWN; } event.setUnit(unit); return event; } }); } return RollupEventEmitter.super.emit(event, eventPayload); } }); } return emitFuture; } RollupEventEmitter(); @VisibleForTesting RollupEventEmitter(ExecutorService executor); static RollupEventEmitter getInstance(); @Override Future emit(final String event, final RollupEvent... eventPayload); static final String ROLLUP_EVENT_NAME; } |
@Test public void offClearsOnceCallbacks() { emitter.once(testEventName, listener); Assert.assertEquals(0, store.size()); emitter.off(); emitter.emit(testEventName, event1); Assert.assertEquals(0, store.size()); } | @Override public Future emit(final String event, final RollupEvent... eventPayload) { Future emitFuture = null; if(eventPayload[0].getRollup() instanceof BasicRollup && super.hasListeners(ROLLUP_EVENT_NAME)) { emitFuture = eventExecutors.submit(new Callable() { @Override public Future call() { if (Util.shouldUseESForUnits()) { final DiscoveryIO discoveryIO = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Lists.transform(Arrays.asList(eventPayload), new Function<RollupEvent, RollupEvent>() { @Override public RollupEvent apply(RollupEvent event) { String unit; try { unit = discoveryIO.search(event.getLocator().getTenantId(), event.getLocator().getMetricName()).get(0).getUnit(); } catch (Exception e) { log.warn("Exception encountered while getting units out of ES : %s", e.getMessage()); unit = Util.UNKNOWN; } event.setUnit(unit); return event; } }); } return RollupEventEmitter.super.emit(event, eventPayload); } }); } return emitFuture; } | RollupEventEmitter extends Emitter<RollupEvent> { @Override public Future emit(final String event, final RollupEvent... eventPayload) { Future emitFuture = null; if(eventPayload[0].getRollup() instanceof BasicRollup && super.hasListeners(ROLLUP_EVENT_NAME)) { emitFuture = eventExecutors.submit(new Callable() { @Override public Future call() { if (Util.shouldUseESForUnits()) { final DiscoveryIO discoveryIO = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Lists.transform(Arrays.asList(eventPayload), new Function<RollupEvent, RollupEvent>() { @Override public RollupEvent apply(RollupEvent event) { String unit; try { unit = discoveryIO.search(event.getLocator().getTenantId(), event.getLocator().getMetricName()).get(0).getUnit(); } catch (Exception e) { log.warn("Exception encountered while getting units out of ES : %s", e.getMessage()); unit = Util.UNKNOWN; } event.setUnit(unit); return event; } }); } return RollupEventEmitter.super.emit(event, eventPayload); } }); } return emitFuture; } } | RollupEventEmitter extends Emitter<RollupEvent> { @Override public Future emit(final String event, final RollupEvent... eventPayload) { Future emitFuture = null; if(eventPayload[0].getRollup() instanceof BasicRollup && super.hasListeners(ROLLUP_EVENT_NAME)) { emitFuture = eventExecutors.submit(new Callable() { @Override public Future call() { if (Util.shouldUseESForUnits()) { final DiscoveryIO discoveryIO = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Lists.transform(Arrays.asList(eventPayload), new Function<RollupEvent, RollupEvent>() { @Override public RollupEvent apply(RollupEvent event) { String unit; try { unit = discoveryIO.search(event.getLocator().getTenantId(), event.getLocator().getMetricName()).get(0).getUnit(); } catch (Exception e) { log.warn("Exception encountered while getting units out of ES : %s", e.getMessage()); unit = Util.UNKNOWN; } event.setUnit(unit); return event; } }); } return RollupEventEmitter.super.emit(event, eventPayload); } }); } return emitFuture; } RollupEventEmitter(); @VisibleForTesting RollupEventEmitter(ExecutorService executor); } | RollupEventEmitter extends Emitter<RollupEvent> { @Override public Future emit(final String event, final RollupEvent... eventPayload) { Future emitFuture = null; if(eventPayload[0].getRollup() instanceof BasicRollup && super.hasListeners(ROLLUP_EVENT_NAME)) { emitFuture = eventExecutors.submit(new Callable() { @Override public Future call() { if (Util.shouldUseESForUnits()) { final DiscoveryIO discoveryIO = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Lists.transform(Arrays.asList(eventPayload), new Function<RollupEvent, RollupEvent>() { @Override public RollupEvent apply(RollupEvent event) { String unit; try { unit = discoveryIO.search(event.getLocator().getTenantId(), event.getLocator().getMetricName()).get(0).getUnit(); } catch (Exception e) { log.warn("Exception encountered while getting units out of ES : %s", e.getMessage()); unit = Util.UNKNOWN; } event.setUnit(unit); return event; } }); } return RollupEventEmitter.super.emit(event, eventPayload); } }); } return emitFuture; } RollupEventEmitter(); @VisibleForTesting RollupEventEmitter(ExecutorService executor); static RollupEventEmitter getInstance(); @Override Future emit(final String event, final RollupEvent... eventPayload); } | RollupEventEmitter extends Emitter<RollupEvent> { @Override public Future emit(final String event, final RollupEvent... eventPayload) { Future emitFuture = null; if(eventPayload[0].getRollup() instanceof BasicRollup && super.hasListeners(ROLLUP_EVENT_NAME)) { emitFuture = eventExecutors.submit(new Callable() { @Override public Future call() { if (Util.shouldUseESForUnits()) { final DiscoveryIO discoveryIO = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Lists.transform(Arrays.asList(eventPayload), new Function<RollupEvent, RollupEvent>() { @Override public RollupEvent apply(RollupEvent event) { String unit; try { unit = discoveryIO.search(event.getLocator().getTenantId(), event.getLocator().getMetricName()).get(0).getUnit(); } catch (Exception e) { log.warn("Exception encountered while getting units out of ES : %s", e.getMessage()); unit = Util.UNKNOWN; } event.setUnit(unit); return event; } }); } return RollupEventEmitter.super.emit(event, eventPayload); } }); } return emitFuture; } RollupEventEmitter(); @VisibleForTesting RollupEventEmitter(ExecutorService executor); static RollupEventEmitter getInstance(); @Override Future emit(final String event, final RollupEvent... eventPayload); static final String ROLLUP_EVENT_NAME; } |
@Test public void emitOnlyTriggersForGivenEvent1() { emitter.on(testEventName, listener); emitter.on(testEventName2, listener); Assert.assertEquals(0, store.size()); emitter.emit(testEventName, event1); Assert.assertEquals(1, store.size()); Assert.assertSame(event1, store.get(0)); } | @Override public Future emit(final String event, final RollupEvent... eventPayload) { Future emitFuture = null; if(eventPayload[0].getRollup() instanceof BasicRollup && super.hasListeners(ROLLUP_EVENT_NAME)) { emitFuture = eventExecutors.submit(new Callable() { @Override public Future call() { if (Util.shouldUseESForUnits()) { final DiscoveryIO discoveryIO = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Lists.transform(Arrays.asList(eventPayload), new Function<RollupEvent, RollupEvent>() { @Override public RollupEvent apply(RollupEvent event) { String unit; try { unit = discoveryIO.search(event.getLocator().getTenantId(), event.getLocator().getMetricName()).get(0).getUnit(); } catch (Exception e) { log.warn("Exception encountered while getting units out of ES : %s", e.getMessage()); unit = Util.UNKNOWN; } event.setUnit(unit); return event; } }); } return RollupEventEmitter.super.emit(event, eventPayload); } }); } return emitFuture; } | RollupEventEmitter extends Emitter<RollupEvent> { @Override public Future emit(final String event, final RollupEvent... eventPayload) { Future emitFuture = null; if(eventPayload[0].getRollup() instanceof BasicRollup && super.hasListeners(ROLLUP_EVENT_NAME)) { emitFuture = eventExecutors.submit(new Callable() { @Override public Future call() { if (Util.shouldUseESForUnits()) { final DiscoveryIO discoveryIO = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Lists.transform(Arrays.asList(eventPayload), new Function<RollupEvent, RollupEvent>() { @Override public RollupEvent apply(RollupEvent event) { String unit; try { unit = discoveryIO.search(event.getLocator().getTenantId(), event.getLocator().getMetricName()).get(0).getUnit(); } catch (Exception e) { log.warn("Exception encountered while getting units out of ES : %s", e.getMessage()); unit = Util.UNKNOWN; } event.setUnit(unit); return event; } }); } return RollupEventEmitter.super.emit(event, eventPayload); } }); } return emitFuture; } } | RollupEventEmitter extends Emitter<RollupEvent> { @Override public Future emit(final String event, final RollupEvent... eventPayload) { Future emitFuture = null; if(eventPayload[0].getRollup() instanceof BasicRollup && super.hasListeners(ROLLUP_EVENT_NAME)) { emitFuture = eventExecutors.submit(new Callable() { @Override public Future call() { if (Util.shouldUseESForUnits()) { final DiscoveryIO discoveryIO = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Lists.transform(Arrays.asList(eventPayload), new Function<RollupEvent, RollupEvent>() { @Override public RollupEvent apply(RollupEvent event) { String unit; try { unit = discoveryIO.search(event.getLocator().getTenantId(), event.getLocator().getMetricName()).get(0).getUnit(); } catch (Exception e) { log.warn("Exception encountered while getting units out of ES : %s", e.getMessage()); unit = Util.UNKNOWN; } event.setUnit(unit); return event; } }); } return RollupEventEmitter.super.emit(event, eventPayload); } }); } return emitFuture; } RollupEventEmitter(); @VisibleForTesting RollupEventEmitter(ExecutorService executor); } | RollupEventEmitter extends Emitter<RollupEvent> { @Override public Future emit(final String event, final RollupEvent... eventPayload) { Future emitFuture = null; if(eventPayload[0].getRollup() instanceof BasicRollup && super.hasListeners(ROLLUP_EVENT_NAME)) { emitFuture = eventExecutors.submit(new Callable() { @Override public Future call() { if (Util.shouldUseESForUnits()) { final DiscoveryIO discoveryIO = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Lists.transform(Arrays.asList(eventPayload), new Function<RollupEvent, RollupEvent>() { @Override public RollupEvent apply(RollupEvent event) { String unit; try { unit = discoveryIO.search(event.getLocator().getTenantId(), event.getLocator().getMetricName()).get(0).getUnit(); } catch (Exception e) { log.warn("Exception encountered while getting units out of ES : %s", e.getMessage()); unit = Util.UNKNOWN; } event.setUnit(unit); return event; } }); } return RollupEventEmitter.super.emit(event, eventPayload); } }); } return emitFuture; } RollupEventEmitter(); @VisibleForTesting RollupEventEmitter(ExecutorService executor); static RollupEventEmitter getInstance(); @Override Future emit(final String event, final RollupEvent... eventPayload); } | RollupEventEmitter extends Emitter<RollupEvent> { @Override public Future emit(final String event, final RollupEvent... eventPayload) { Future emitFuture = null; if(eventPayload[0].getRollup() instanceof BasicRollup && super.hasListeners(ROLLUP_EVENT_NAME)) { emitFuture = eventExecutors.submit(new Callable() { @Override public Future call() { if (Util.shouldUseESForUnits()) { final DiscoveryIO discoveryIO = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Lists.transform(Arrays.asList(eventPayload), new Function<RollupEvent, RollupEvent>() { @Override public RollupEvent apply(RollupEvent event) { String unit; try { unit = discoveryIO.search(event.getLocator().getTenantId(), event.getLocator().getMetricName()).get(0).getUnit(); } catch (Exception e) { log.warn("Exception encountered while getting units out of ES : %s", e.getMessage()); unit = Util.UNKNOWN; } event.setUnit(unit); return event; } }); } return RollupEventEmitter.super.emit(event, eventPayload); } }); } return emitFuture; } RollupEventEmitter(); @VisibleForTesting RollupEventEmitter(ExecutorService executor); static RollupEventEmitter getInstance(); @Override Future emit(final String event, final RollupEvent... eventPayload); static final String ROLLUP_EVENT_NAME; } |
@Test public void emitOnlyTriggersForGivenEvent2() { emitter.on(testEventName, listener); emitter.on(testEventName2, listener); Assert.assertEquals(0, store.size()); emitter.emit(testEventName2, event2); Assert.assertEquals(1, store.size()); Assert.assertSame(event2, store.get(0)); } | @Override public Future emit(final String event, final RollupEvent... eventPayload) { Future emitFuture = null; if(eventPayload[0].getRollup() instanceof BasicRollup && super.hasListeners(ROLLUP_EVENT_NAME)) { emitFuture = eventExecutors.submit(new Callable() { @Override public Future call() { if (Util.shouldUseESForUnits()) { final DiscoveryIO discoveryIO = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Lists.transform(Arrays.asList(eventPayload), new Function<RollupEvent, RollupEvent>() { @Override public RollupEvent apply(RollupEvent event) { String unit; try { unit = discoveryIO.search(event.getLocator().getTenantId(), event.getLocator().getMetricName()).get(0).getUnit(); } catch (Exception e) { log.warn("Exception encountered while getting units out of ES : %s", e.getMessage()); unit = Util.UNKNOWN; } event.setUnit(unit); return event; } }); } return RollupEventEmitter.super.emit(event, eventPayload); } }); } return emitFuture; } | RollupEventEmitter extends Emitter<RollupEvent> { @Override public Future emit(final String event, final RollupEvent... eventPayload) { Future emitFuture = null; if(eventPayload[0].getRollup() instanceof BasicRollup && super.hasListeners(ROLLUP_EVENT_NAME)) { emitFuture = eventExecutors.submit(new Callable() { @Override public Future call() { if (Util.shouldUseESForUnits()) { final DiscoveryIO discoveryIO = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Lists.transform(Arrays.asList(eventPayload), new Function<RollupEvent, RollupEvent>() { @Override public RollupEvent apply(RollupEvent event) { String unit; try { unit = discoveryIO.search(event.getLocator().getTenantId(), event.getLocator().getMetricName()).get(0).getUnit(); } catch (Exception e) { log.warn("Exception encountered while getting units out of ES : %s", e.getMessage()); unit = Util.UNKNOWN; } event.setUnit(unit); return event; } }); } return RollupEventEmitter.super.emit(event, eventPayload); } }); } return emitFuture; } } | RollupEventEmitter extends Emitter<RollupEvent> { @Override public Future emit(final String event, final RollupEvent... eventPayload) { Future emitFuture = null; if(eventPayload[0].getRollup() instanceof BasicRollup && super.hasListeners(ROLLUP_EVENT_NAME)) { emitFuture = eventExecutors.submit(new Callable() { @Override public Future call() { if (Util.shouldUseESForUnits()) { final DiscoveryIO discoveryIO = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Lists.transform(Arrays.asList(eventPayload), new Function<RollupEvent, RollupEvent>() { @Override public RollupEvent apply(RollupEvent event) { String unit; try { unit = discoveryIO.search(event.getLocator().getTenantId(), event.getLocator().getMetricName()).get(0).getUnit(); } catch (Exception e) { log.warn("Exception encountered while getting units out of ES : %s", e.getMessage()); unit = Util.UNKNOWN; } event.setUnit(unit); return event; } }); } return RollupEventEmitter.super.emit(event, eventPayload); } }); } return emitFuture; } RollupEventEmitter(); @VisibleForTesting RollupEventEmitter(ExecutorService executor); } | RollupEventEmitter extends Emitter<RollupEvent> { @Override public Future emit(final String event, final RollupEvent... eventPayload) { Future emitFuture = null; if(eventPayload[0].getRollup() instanceof BasicRollup && super.hasListeners(ROLLUP_EVENT_NAME)) { emitFuture = eventExecutors.submit(new Callable() { @Override public Future call() { if (Util.shouldUseESForUnits()) { final DiscoveryIO discoveryIO = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Lists.transform(Arrays.asList(eventPayload), new Function<RollupEvent, RollupEvent>() { @Override public RollupEvent apply(RollupEvent event) { String unit; try { unit = discoveryIO.search(event.getLocator().getTenantId(), event.getLocator().getMetricName()).get(0).getUnit(); } catch (Exception e) { log.warn("Exception encountered while getting units out of ES : %s", e.getMessage()); unit = Util.UNKNOWN; } event.setUnit(unit); return event; } }); } return RollupEventEmitter.super.emit(event, eventPayload); } }); } return emitFuture; } RollupEventEmitter(); @VisibleForTesting RollupEventEmitter(ExecutorService executor); static RollupEventEmitter getInstance(); @Override Future emit(final String event, final RollupEvent... eventPayload); } | RollupEventEmitter extends Emitter<RollupEvent> { @Override public Future emit(final String event, final RollupEvent... eventPayload) { Future emitFuture = null; if(eventPayload[0].getRollup() instanceof BasicRollup && super.hasListeners(ROLLUP_EVENT_NAME)) { emitFuture = eventExecutors.submit(new Callable() { @Override public Future call() { if (Util.shouldUseESForUnits()) { final DiscoveryIO discoveryIO = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Lists.transform(Arrays.asList(eventPayload), new Function<RollupEvent, RollupEvent>() { @Override public RollupEvent apply(RollupEvent event) { String unit; try { unit = discoveryIO.search(event.getLocator().getTenantId(), event.getLocator().getMetricName()).get(0).getUnit(); } catch (Exception e) { log.warn("Exception encountered while getting units out of ES : %s", e.getMessage()); unit = Util.UNKNOWN; } event.setUnit(unit); return event; } }); } return RollupEventEmitter.super.emit(event, eventPayload); } }); } return emitFuture; } RollupEventEmitter(); @VisibleForTesting RollupEventEmitter(ExecutorService executor); static RollupEventEmitter getInstance(); @Override Future emit(final String event, final RollupEvent... eventPayload); static final String ROLLUP_EVENT_NAME; } |
@Test public void emitTriggersListenerInSameOrder1() { emitter.on(testEventName, listener); emitter.on(testEventName2, listener); Assert.assertEquals(0, store.size()); emitter.emit(testEventName, event1); emitter.emit(testEventName2, event2); Assert.assertEquals(2, store.size()); Assert.assertSame(event1, store.get(0)); Assert.assertSame(event2, store.get(1)); } | @Override public Future emit(final String event, final RollupEvent... eventPayload) { Future emitFuture = null; if(eventPayload[0].getRollup() instanceof BasicRollup && super.hasListeners(ROLLUP_EVENT_NAME)) { emitFuture = eventExecutors.submit(new Callable() { @Override public Future call() { if (Util.shouldUseESForUnits()) { final DiscoveryIO discoveryIO = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Lists.transform(Arrays.asList(eventPayload), new Function<RollupEvent, RollupEvent>() { @Override public RollupEvent apply(RollupEvent event) { String unit; try { unit = discoveryIO.search(event.getLocator().getTenantId(), event.getLocator().getMetricName()).get(0).getUnit(); } catch (Exception e) { log.warn("Exception encountered while getting units out of ES : %s", e.getMessage()); unit = Util.UNKNOWN; } event.setUnit(unit); return event; } }); } return RollupEventEmitter.super.emit(event, eventPayload); } }); } return emitFuture; } | RollupEventEmitter extends Emitter<RollupEvent> { @Override public Future emit(final String event, final RollupEvent... eventPayload) { Future emitFuture = null; if(eventPayload[0].getRollup() instanceof BasicRollup && super.hasListeners(ROLLUP_EVENT_NAME)) { emitFuture = eventExecutors.submit(new Callable() { @Override public Future call() { if (Util.shouldUseESForUnits()) { final DiscoveryIO discoveryIO = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Lists.transform(Arrays.asList(eventPayload), new Function<RollupEvent, RollupEvent>() { @Override public RollupEvent apply(RollupEvent event) { String unit; try { unit = discoveryIO.search(event.getLocator().getTenantId(), event.getLocator().getMetricName()).get(0).getUnit(); } catch (Exception e) { log.warn("Exception encountered while getting units out of ES : %s", e.getMessage()); unit = Util.UNKNOWN; } event.setUnit(unit); return event; } }); } return RollupEventEmitter.super.emit(event, eventPayload); } }); } return emitFuture; } } | RollupEventEmitter extends Emitter<RollupEvent> { @Override public Future emit(final String event, final RollupEvent... eventPayload) { Future emitFuture = null; if(eventPayload[0].getRollup() instanceof BasicRollup && super.hasListeners(ROLLUP_EVENT_NAME)) { emitFuture = eventExecutors.submit(new Callable() { @Override public Future call() { if (Util.shouldUseESForUnits()) { final DiscoveryIO discoveryIO = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Lists.transform(Arrays.asList(eventPayload), new Function<RollupEvent, RollupEvent>() { @Override public RollupEvent apply(RollupEvent event) { String unit; try { unit = discoveryIO.search(event.getLocator().getTenantId(), event.getLocator().getMetricName()).get(0).getUnit(); } catch (Exception e) { log.warn("Exception encountered while getting units out of ES : %s", e.getMessage()); unit = Util.UNKNOWN; } event.setUnit(unit); return event; } }); } return RollupEventEmitter.super.emit(event, eventPayload); } }); } return emitFuture; } RollupEventEmitter(); @VisibleForTesting RollupEventEmitter(ExecutorService executor); } | RollupEventEmitter extends Emitter<RollupEvent> { @Override public Future emit(final String event, final RollupEvent... eventPayload) { Future emitFuture = null; if(eventPayload[0].getRollup() instanceof BasicRollup && super.hasListeners(ROLLUP_EVENT_NAME)) { emitFuture = eventExecutors.submit(new Callable() { @Override public Future call() { if (Util.shouldUseESForUnits()) { final DiscoveryIO discoveryIO = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Lists.transform(Arrays.asList(eventPayload), new Function<RollupEvent, RollupEvent>() { @Override public RollupEvent apply(RollupEvent event) { String unit; try { unit = discoveryIO.search(event.getLocator().getTenantId(), event.getLocator().getMetricName()).get(0).getUnit(); } catch (Exception e) { log.warn("Exception encountered while getting units out of ES : %s", e.getMessage()); unit = Util.UNKNOWN; } event.setUnit(unit); return event; } }); } return RollupEventEmitter.super.emit(event, eventPayload); } }); } return emitFuture; } RollupEventEmitter(); @VisibleForTesting RollupEventEmitter(ExecutorService executor); static RollupEventEmitter getInstance(); @Override Future emit(final String event, final RollupEvent... eventPayload); } | RollupEventEmitter extends Emitter<RollupEvent> { @Override public Future emit(final String event, final RollupEvent... eventPayload) { Future emitFuture = null; if(eventPayload[0].getRollup() instanceof BasicRollup && super.hasListeners(ROLLUP_EVENT_NAME)) { emitFuture = eventExecutors.submit(new Callable() { @Override public Future call() { if (Util.shouldUseESForUnits()) { final DiscoveryIO discoveryIO = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Lists.transform(Arrays.asList(eventPayload), new Function<RollupEvent, RollupEvent>() { @Override public RollupEvent apply(RollupEvent event) { String unit; try { unit = discoveryIO.search(event.getLocator().getTenantId(), event.getLocator().getMetricName()).get(0).getUnit(); } catch (Exception e) { log.warn("Exception encountered while getting units out of ES : %s", e.getMessage()); unit = Util.UNKNOWN; } event.setUnit(unit); return event; } }); } return RollupEventEmitter.super.emit(event, eventPayload); } }); } return emitFuture; } RollupEventEmitter(); @VisibleForTesting RollupEventEmitter(ExecutorService executor); static RollupEventEmitter getInstance(); @Override Future emit(final String event, final RollupEvent... eventPayload); static final String ROLLUP_EVENT_NAME; } |
@Test public void maxTimeRetryOnWriteTimeout_shouldRethrow() throws Exception { RetryNTimes retryPolicy = new RetryNTimes(3, 3, 3); Statement mockStatement = mock( Statement.class ); RetryPolicy.RetryDecision retryResult = retryPolicy.onWriteTimeout(mockStatement, ConsistencyLevel.LOCAL_ONE, WriteType.BATCH, 1, 0, 3); RetryPolicy.RetryDecision retryExpected = RetryPolicy.RetryDecision.rethrow(); assertRetryDecisionEquals(retryExpected, retryResult); } | @Override public RetryDecision onWriteTimeout(Statement stmnt, ConsistencyLevel cl, WriteType wt, int requiredResponses, int receivedResponses, int wTime) { if (wTime < writeAttempts) { LOG.info(String.format("Retrying on WriteTimeout: stmnt %s, " + "consistency %s, writeType %s, requiredResponse %d, " + "receivedResponse %d, rTime %d", stmnt, cl, wt.toString(), requiredResponses, receivedResponses, wTime)); return RetryDecision.retry(cl); } return RetryDecision.rethrow(); } | RetryNTimes implements RetryPolicy { @Override public RetryDecision onWriteTimeout(Statement stmnt, ConsistencyLevel cl, WriteType wt, int requiredResponses, int receivedResponses, int wTime) { if (wTime < writeAttempts) { LOG.info(String.format("Retrying on WriteTimeout: stmnt %s, " + "consistency %s, writeType %s, requiredResponse %d, " + "receivedResponse %d, rTime %d", stmnt, cl, wt.toString(), requiredResponses, receivedResponses, wTime)); return RetryDecision.retry(cl); } return RetryDecision.rethrow(); } } | RetryNTimes implements RetryPolicy { @Override public RetryDecision onWriteTimeout(Statement stmnt, ConsistencyLevel cl, WriteType wt, int requiredResponses, int receivedResponses, int wTime) { if (wTime < writeAttempts) { LOG.info(String.format("Retrying on WriteTimeout: stmnt %s, " + "consistency %s, writeType %s, requiredResponse %d, " + "receivedResponse %d, rTime %d", stmnt, cl, wt.toString(), requiredResponses, receivedResponses, wTime)); return RetryDecision.retry(cl); } return RetryDecision.rethrow(); } RetryNTimes(int readAttempts, int writeAttempts, int unavailableAttempts); } | RetryNTimes implements RetryPolicy { @Override public RetryDecision onWriteTimeout(Statement stmnt, ConsistencyLevel cl, WriteType wt, int requiredResponses, int receivedResponses, int wTime) { if (wTime < writeAttempts) { LOG.info(String.format("Retrying on WriteTimeout: stmnt %s, " + "consistency %s, writeType %s, requiredResponse %d, " + "receivedResponse %d, rTime %d", stmnt, cl, wt.toString(), requiredResponses, receivedResponses, wTime)); return RetryDecision.retry(cl); } return RetryDecision.rethrow(); } RetryNTimes(int readAttempts, int writeAttempts, int unavailableAttempts); @Override RetryDecision onReadTimeout(Statement stmnt, ConsistencyLevel cl,
int requiredResponses, int receivedResponses,
boolean dataReceived, int rTime); @Override RetryDecision onWriteTimeout(Statement stmnt, ConsistencyLevel cl,
WriteType wt, int requiredResponses,
int receivedResponses, int wTime); @Override RetryDecision onUnavailable(Statement stmnt, ConsistencyLevel cl,
int requiredResponses, int receivedResponses, int uTime); @Override RetryDecision onRequestError(Statement statement, ConsistencyLevel cl, DriverException e, int nbRetry); @Override void init(Cluster cluster); @Override void close(); } | RetryNTimes implements RetryPolicy { @Override public RetryDecision onWriteTimeout(Statement stmnt, ConsistencyLevel cl, WriteType wt, int requiredResponses, int receivedResponses, int wTime) { if (wTime < writeAttempts) { LOG.info(String.format("Retrying on WriteTimeout: stmnt %s, " + "consistency %s, writeType %s, requiredResponse %d, " + "receivedResponse %d, rTime %d", stmnt, cl, wt.toString(), requiredResponses, receivedResponses, wTime)); return RetryDecision.retry(cl); } return RetryDecision.rethrow(); } RetryNTimes(int readAttempts, int writeAttempts, int unavailableAttempts); @Override RetryDecision onReadTimeout(Statement stmnt, ConsistencyLevel cl,
int requiredResponses, int receivedResponses,
boolean dataReceived, int rTime); @Override RetryDecision onWriteTimeout(Statement stmnt, ConsistencyLevel cl,
WriteType wt, int requiredResponses,
int receivedResponses, int wTime); @Override RetryDecision onUnavailable(Statement stmnt, ConsistencyLevel cl,
int requiredResponses, int receivedResponses, int uTime); @Override RetryDecision onRequestError(Statement statement, ConsistencyLevel cl, DriverException e, int nbRetry); @Override void init(Cluster cluster); @Override void close(); } |
@Test public void emitTriggersListenerInSameOrder2() { emitter.on(testEventName, listener); emitter.on(testEventName2, listener); Assert.assertEquals(0, store.size()); emitter.emit(testEventName2, event2); emitter.emit(testEventName, event1); Assert.assertEquals(2, store.size()); Assert.assertSame(event2, store.get(0)); Assert.assertSame(event1, store.get(1)); } | @Override public Future emit(final String event, final RollupEvent... eventPayload) { Future emitFuture = null; if(eventPayload[0].getRollup() instanceof BasicRollup && super.hasListeners(ROLLUP_EVENT_NAME)) { emitFuture = eventExecutors.submit(new Callable() { @Override public Future call() { if (Util.shouldUseESForUnits()) { final DiscoveryIO discoveryIO = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Lists.transform(Arrays.asList(eventPayload), new Function<RollupEvent, RollupEvent>() { @Override public RollupEvent apply(RollupEvent event) { String unit; try { unit = discoveryIO.search(event.getLocator().getTenantId(), event.getLocator().getMetricName()).get(0).getUnit(); } catch (Exception e) { log.warn("Exception encountered while getting units out of ES : %s", e.getMessage()); unit = Util.UNKNOWN; } event.setUnit(unit); return event; } }); } return RollupEventEmitter.super.emit(event, eventPayload); } }); } return emitFuture; } | RollupEventEmitter extends Emitter<RollupEvent> { @Override public Future emit(final String event, final RollupEvent... eventPayload) { Future emitFuture = null; if(eventPayload[0].getRollup() instanceof BasicRollup && super.hasListeners(ROLLUP_EVENT_NAME)) { emitFuture = eventExecutors.submit(new Callable() { @Override public Future call() { if (Util.shouldUseESForUnits()) { final DiscoveryIO discoveryIO = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Lists.transform(Arrays.asList(eventPayload), new Function<RollupEvent, RollupEvent>() { @Override public RollupEvent apply(RollupEvent event) { String unit; try { unit = discoveryIO.search(event.getLocator().getTenantId(), event.getLocator().getMetricName()).get(0).getUnit(); } catch (Exception e) { log.warn("Exception encountered while getting units out of ES : %s", e.getMessage()); unit = Util.UNKNOWN; } event.setUnit(unit); return event; } }); } return RollupEventEmitter.super.emit(event, eventPayload); } }); } return emitFuture; } } | RollupEventEmitter extends Emitter<RollupEvent> { @Override public Future emit(final String event, final RollupEvent... eventPayload) { Future emitFuture = null; if(eventPayload[0].getRollup() instanceof BasicRollup && super.hasListeners(ROLLUP_EVENT_NAME)) { emitFuture = eventExecutors.submit(new Callable() { @Override public Future call() { if (Util.shouldUseESForUnits()) { final DiscoveryIO discoveryIO = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Lists.transform(Arrays.asList(eventPayload), new Function<RollupEvent, RollupEvent>() { @Override public RollupEvent apply(RollupEvent event) { String unit; try { unit = discoveryIO.search(event.getLocator().getTenantId(), event.getLocator().getMetricName()).get(0).getUnit(); } catch (Exception e) { log.warn("Exception encountered while getting units out of ES : %s", e.getMessage()); unit = Util.UNKNOWN; } event.setUnit(unit); return event; } }); } return RollupEventEmitter.super.emit(event, eventPayload); } }); } return emitFuture; } RollupEventEmitter(); @VisibleForTesting RollupEventEmitter(ExecutorService executor); } | RollupEventEmitter extends Emitter<RollupEvent> { @Override public Future emit(final String event, final RollupEvent... eventPayload) { Future emitFuture = null; if(eventPayload[0].getRollup() instanceof BasicRollup && super.hasListeners(ROLLUP_EVENT_NAME)) { emitFuture = eventExecutors.submit(new Callable() { @Override public Future call() { if (Util.shouldUseESForUnits()) { final DiscoveryIO discoveryIO = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Lists.transform(Arrays.asList(eventPayload), new Function<RollupEvent, RollupEvent>() { @Override public RollupEvent apply(RollupEvent event) { String unit; try { unit = discoveryIO.search(event.getLocator().getTenantId(), event.getLocator().getMetricName()).get(0).getUnit(); } catch (Exception e) { log.warn("Exception encountered while getting units out of ES : %s", e.getMessage()); unit = Util.UNKNOWN; } event.setUnit(unit); return event; } }); } return RollupEventEmitter.super.emit(event, eventPayload); } }); } return emitFuture; } RollupEventEmitter(); @VisibleForTesting RollupEventEmitter(ExecutorService executor); static RollupEventEmitter getInstance(); @Override Future emit(final String event, final RollupEvent... eventPayload); } | RollupEventEmitter extends Emitter<RollupEvent> { @Override public Future emit(final String event, final RollupEvent... eventPayload) { Future emitFuture = null; if(eventPayload[0].getRollup() instanceof BasicRollup && super.hasListeners(ROLLUP_EVENT_NAME)) { emitFuture = eventExecutors.submit(new Callable() { @Override public Future call() { if (Util.shouldUseESForUnits()) { final DiscoveryIO discoveryIO = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Lists.transform(Arrays.asList(eventPayload), new Function<RollupEvent, RollupEvent>() { @Override public RollupEvent apply(RollupEvent event) { String unit; try { unit = discoveryIO.search(event.getLocator().getTenantId(), event.getLocator().getMetricName()).get(0).getUnit(); } catch (Exception e) { log.warn("Exception encountered while getting units out of ES : %s", e.getMessage()); unit = Util.UNKNOWN; } event.setUnit(unit); return event; } }); } return RollupEventEmitter.super.emit(event, eventPayload); } }); } return emitFuture; } RollupEventEmitter(); @VisibleForTesting RollupEventEmitter(ExecutorService executor); static RollupEventEmitter getInstance(); @Override Future emit(final String event, final RollupEvent... eventPayload); static final String ROLLUP_EVENT_NAME; } |
@Test public void offOnlyClearsForGivenEvent() { emitter.on(testEventName, listener); emitter.on(testEventName2, listener); Assert.assertEquals(0, store.size()); emitter.off(testEventName); emitter.emit(testEventName, event1); emitter.emit(testEventName2, event2); Assert.assertEquals(1, store.size()); Assert.assertSame(event2, store.get(0)); } | @Override public Future emit(final String event, final RollupEvent... eventPayload) { Future emitFuture = null; if(eventPayload[0].getRollup() instanceof BasicRollup && super.hasListeners(ROLLUP_EVENT_NAME)) { emitFuture = eventExecutors.submit(new Callable() { @Override public Future call() { if (Util.shouldUseESForUnits()) { final DiscoveryIO discoveryIO = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Lists.transform(Arrays.asList(eventPayload), new Function<RollupEvent, RollupEvent>() { @Override public RollupEvent apply(RollupEvent event) { String unit; try { unit = discoveryIO.search(event.getLocator().getTenantId(), event.getLocator().getMetricName()).get(0).getUnit(); } catch (Exception e) { log.warn("Exception encountered while getting units out of ES : %s", e.getMessage()); unit = Util.UNKNOWN; } event.setUnit(unit); return event; } }); } return RollupEventEmitter.super.emit(event, eventPayload); } }); } return emitFuture; } | RollupEventEmitter extends Emitter<RollupEvent> { @Override public Future emit(final String event, final RollupEvent... eventPayload) { Future emitFuture = null; if(eventPayload[0].getRollup() instanceof BasicRollup && super.hasListeners(ROLLUP_EVENT_NAME)) { emitFuture = eventExecutors.submit(new Callable() { @Override public Future call() { if (Util.shouldUseESForUnits()) { final DiscoveryIO discoveryIO = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Lists.transform(Arrays.asList(eventPayload), new Function<RollupEvent, RollupEvent>() { @Override public RollupEvent apply(RollupEvent event) { String unit; try { unit = discoveryIO.search(event.getLocator().getTenantId(), event.getLocator().getMetricName()).get(0).getUnit(); } catch (Exception e) { log.warn("Exception encountered while getting units out of ES : %s", e.getMessage()); unit = Util.UNKNOWN; } event.setUnit(unit); return event; } }); } return RollupEventEmitter.super.emit(event, eventPayload); } }); } return emitFuture; } } | RollupEventEmitter extends Emitter<RollupEvent> { @Override public Future emit(final String event, final RollupEvent... eventPayload) { Future emitFuture = null; if(eventPayload[0].getRollup() instanceof BasicRollup && super.hasListeners(ROLLUP_EVENT_NAME)) { emitFuture = eventExecutors.submit(new Callable() { @Override public Future call() { if (Util.shouldUseESForUnits()) { final DiscoveryIO discoveryIO = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Lists.transform(Arrays.asList(eventPayload), new Function<RollupEvent, RollupEvent>() { @Override public RollupEvent apply(RollupEvent event) { String unit; try { unit = discoveryIO.search(event.getLocator().getTenantId(), event.getLocator().getMetricName()).get(0).getUnit(); } catch (Exception e) { log.warn("Exception encountered while getting units out of ES : %s", e.getMessage()); unit = Util.UNKNOWN; } event.setUnit(unit); return event; } }); } return RollupEventEmitter.super.emit(event, eventPayload); } }); } return emitFuture; } RollupEventEmitter(); @VisibleForTesting RollupEventEmitter(ExecutorService executor); } | RollupEventEmitter extends Emitter<RollupEvent> { @Override public Future emit(final String event, final RollupEvent... eventPayload) { Future emitFuture = null; if(eventPayload[0].getRollup() instanceof BasicRollup && super.hasListeners(ROLLUP_EVENT_NAME)) { emitFuture = eventExecutors.submit(new Callable() { @Override public Future call() { if (Util.shouldUseESForUnits()) { final DiscoveryIO discoveryIO = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Lists.transform(Arrays.asList(eventPayload), new Function<RollupEvent, RollupEvent>() { @Override public RollupEvent apply(RollupEvent event) { String unit; try { unit = discoveryIO.search(event.getLocator().getTenantId(), event.getLocator().getMetricName()).get(0).getUnit(); } catch (Exception e) { log.warn("Exception encountered while getting units out of ES : %s", e.getMessage()); unit = Util.UNKNOWN; } event.setUnit(unit); return event; } }); } return RollupEventEmitter.super.emit(event, eventPayload); } }); } return emitFuture; } RollupEventEmitter(); @VisibleForTesting RollupEventEmitter(ExecutorService executor); static RollupEventEmitter getInstance(); @Override Future emit(final String event, final RollupEvent... eventPayload); } | RollupEventEmitter extends Emitter<RollupEvent> { @Override public Future emit(final String event, final RollupEvent... eventPayload) { Future emitFuture = null; if(eventPayload[0].getRollup() instanceof BasicRollup && super.hasListeners(ROLLUP_EVENT_NAME)) { emitFuture = eventExecutors.submit(new Callable() { @Override public Future call() { if (Util.shouldUseESForUnits()) { final DiscoveryIO discoveryIO = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Lists.transform(Arrays.asList(eventPayload), new Function<RollupEvent, RollupEvent>() { @Override public RollupEvent apply(RollupEvent event) { String unit; try { unit = discoveryIO.search(event.getLocator().getTenantId(), event.getLocator().getMetricName()).get(0).getUnit(); } catch (Exception e) { log.warn("Exception encountered while getting units out of ES : %s", e.getMessage()); unit = Util.UNKNOWN; } event.setUnit(unit); return event; } }); } return RollupEventEmitter.super.emit(event, eventPayload); } }); } return emitFuture; } RollupEventEmitter(); @VisibleForTesting RollupEventEmitter(ExecutorService executor); static RollupEventEmitter getInstance(); @Override Future emit(final String event, final RollupEvent... eventPayload); static final String ROLLUP_EVENT_NAME; } |
@Test public void multipleAttachedListenersShouldAllBeTriggeredByOneEvent() { emitter.on(testEventName, listener); emitter.on(testEventName, listener2); Assert.assertEquals(0, store.size()); Assert.assertEquals(0, store2.size()); emitter.emit(testEventName, event1); Assert.assertEquals(1, store.size()); Assert.assertSame(event1, store.get(0)); Assert.assertEquals(1, store2.size()); Assert.assertSame(event1, store2.get(0)); } | @Override public Future emit(final String event, final RollupEvent... eventPayload) { Future emitFuture = null; if(eventPayload[0].getRollup() instanceof BasicRollup && super.hasListeners(ROLLUP_EVENT_NAME)) { emitFuture = eventExecutors.submit(new Callable() { @Override public Future call() { if (Util.shouldUseESForUnits()) { final DiscoveryIO discoveryIO = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Lists.transform(Arrays.asList(eventPayload), new Function<RollupEvent, RollupEvent>() { @Override public RollupEvent apply(RollupEvent event) { String unit; try { unit = discoveryIO.search(event.getLocator().getTenantId(), event.getLocator().getMetricName()).get(0).getUnit(); } catch (Exception e) { log.warn("Exception encountered while getting units out of ES : %s", e.getMessage()); unit = Util.UNKNOWN; } event.setUnit(unit); return event; } }); } return RollupEventEmitter.super.emit(event, eventPayload); } }); } return emitFuture; } | RollupEventEmitter extends Emitter<RollupEvent> { @Override public Future emit(final String event, final RollupEvent... eventPayload) { Future emitFuture = null; if(eventPayload[0].getRollup() instanceof BasicRollup && super.hasListeners(ROLLUP_EVENT_NAME)) { emitFuture = eventExecutors.submit(new Callable() { @Override public Future call() { if (Util.shouldUseESForUnits()) { final DiscoveryIO discoveryIO = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Lists.transform(Arrays.asList(eventPayload), new Function<RollupEvent, RollupEvent>() { @Override public RollupEvent apply(RollupEvent event) { String unit; try { unit = discoveryIO.search(event.getLocator().getTenantId(), event.getLocator().getMetricName()).get(0).getUnit(); } catch (Exception e) { log.warn("Exception encountered while getting units out of ES : %s", e.getMessage()); unit = Util.UNKNOWN; } event.setUnit(unit); return event; } }); } return RollupEventEmitter.super.emit(event, eventPayload); } }); } return emitFuture; } } | RollupEventEmitter extends Emitter<RollupEvent> { @Override public Future emit(final String event, final RollupEvent... eventPayload) { Future emitFuture = null; if(eventPayload[0].getRollup() instanceof BasicRollup && super.hasListeners(ROLLUP_EVENT_NAME)) { emitFuture = eventExecutors.submit(new Callable() { @Override public Future call() { if (Util.shouldUseESForUnits()) { final DiscoveryIO discoveryIO = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Lists.transform(Arrays.asList(eventPayload), new Function<RollupEvent, RollupEvent>() { @Override public RollupEvent apply(RollupEvent event) { String unit; try { unit = discoveryIO.search(event.getLocator().getTenantId(), event.getLocator().getMetricName()).get(0).getUnit(); } catch (Exception e) { log.warn("Exception encountered while getting units out of ES : %s", e.getMessage()); unit = Util.UNKNOWN; } event.setUnit(unit); return event; } }); } return RollupEventEmitter.super.emit(event, eventPayload); } }); } return emitFuture; } RollupEventEmitter(); @VisibleForTesting RollupEventEmitter(ExecutorService executor); } | RollupEventEmitter extends Emitter<RollupEvent> { @Override public Future emit(final String event, final RollupEvent... eventPayload) { Future emitFuture = null; if(eventPayload[0].getRollup() instanceof BasicRollup && super.hasListeners(ROLLUP_EVENT_NAME)) { emitFuture = eventExecutors.submit(new Callable() { @Override public Future call() { if (Util.shouldUseESForUnits()) { final DiscoveryIO discoveryIO = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Lists.transform(Arrays.asList(eventPayload), new Function<RollupEvent, RollupEvent>() { @Override public RollupEvent apply(RollupEvent event) { String unit; try { unit = discoveryIO.search(event.getLocator().getTenantId(), event.getLocator().getMetricName()).get(0).getUnit(); } catch (Exception e) { log.warn("Exception encountered while getting units out of ES : %s", e.getMessage()); unit = Util.UNKNOWN; } event.setUnit(unit); return event; } }); } return RollupEventEmitter.super.emit(event, eventPayload); } }); } return emitFuture; } RollupEventEmitter(); @VisibleForTesting RollupEventEmitter(ExecutorService executor); static RollupEventEmitter getInstance(); @Override Future emit(final String event, final RollupEvent... eventPayload); } | RollupEventEmitter extends Emitter<RollupEvent> { @Override public Future emit(final String event, final RollupEvent... eventPayload) { Future emitFuture = null; if(eventPayload[0].getRollup() instanceof BasicRollup && super.hasListeners(ROLLUP_EVENT_NAME)) { emitFuture = eventExecutors.submit(new Callable() { @Override public Future call() { if (Util.shouldUseESForUnits()) { final DiscoveryIO discoveryIO = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Lists.transform(Arrays.asList(eventPayload), new Function<RollupEvent, RollupEvent>() { @Override public RollupEvent apply(RollupEvent event) { String unit; try { unit = discoveryIO.search(event.getLocator().getTenantId(), event.getLocator().getMetricName()).get(0).getUnit(); } catch (Exception e) { log.warn("Exception encountered while getting units out of ES : %s", e.getMessage()); unit = Util.UNKNOWN; } event.setUnit(unit); return event; } }); } return RollupEventEmitter.super.emit(event, eventPayload); } }); } return emitFuture; } RollupEventEmitter(); @VisibleForTesting RollupEventEmitter(ExecutorService executor); static RollupEventEmitter getInstance(); @Override Future emit(final String event, final RollupEvent... eventPayload); static final String ROLLUP_EVENT_NAME; } |
@Test public void testForCloseness() { int desiredPoints = 10; long start = Calendar.getInstance().getTimeInMillis(); Assert.assertEquals(Granularity.MIN_20, Granularity.granularityFromPointsInInterval("TENANTID1234",start, start + 10000000, desiredPoints)); Assert.assertEquals(Granularity.MIN_5, Granularity.granularityFromPointsInInterval("TENANTID1234",start, start + 1000000, desiredPoints)); Map<Integer, Granularity> expectedGranularities = new HashMap<Integer, Granularity>() {{ put(5000, Granularity.FULL); put(1055, Granularity.FULL); put(1054, Granularity.MIN_5); put(167, Granularity.MIN_5); put(166, Granularity.MIN_20); put(49, Granularity.MIN_20); put(48, Granularity.MIN_60); put(14, Granularity.MIN_60); put(13, Granularity.MIN_240); put(3, Granularity.MIN_240); put(2, Granularity.MIN_1440); put(1, Granularity.MIN_1440); }}; for (Map.Entry<Integer, Granularity> entry : expectedGranularities.entrySet()) { Granularity actual = Granularity.granularityFromPointsInInterval("TENANTID1234",start, start+100000000, entry.getKey()); Assert.assertEquals( String.format("%d points", entry.getKey()), entry.getValue(), actual); } } | public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test public void testCommonPointRequests() { long HOUR = 3600000; long DAY = 24 * HOUR; Assert.assertEquals(Granularity.FULL, Granularity.granularityFromPointsInInterval("TENANTID1234",fromBaseMillis, fromBaseMillis+HOUR, 300)); Assert.assertEquals(Granularity.MIN_5, Granularity.granularityFromPointsInInterval("TENANTID1234",fromBaseMillis, fromBaseMillis+(8 * HOUR), 300)); Assert.assertEquals(Granularity.MIN_5, Granularity.granularityFromPointsInInterval("TENANTID1234",fromBaseMillis, fromBaseMillis+(12 * HOUR), 300)); Assert.assertEquals(Granularity.MIN_5, Granularity.granularityFromPointsInInterval("TENANTID1234",fromBaseMillis, fromBaseMillis+DAY, 300)); Assert.assertEquals(Granularity.MIN_20, Granularity.granularityFromPointsInInterval("TENANTID1234",fromBaseMillis, fromBaseMillis+(7 * DAY), 300)); Assert.assertEquals(Granularity.MIN_240, Granularity.granularityFromPointsInInterval("TENANTID1234",fromBaseMillis, fromBaseMillis+(30 * DAY), 300)); } | public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test public void coarserReturnsCoarser() throws GranularityException { Assert.assertSame(Granularity.MIN_5, Granularity.FULL.coarser()); Assert.assertSame(Granularity.MIN_20, Granularity.MIN_5.coarser()); Assert.assertSame(Granularity.MIN_60, Granularity.MIN_20.coarser()); Assert.assertSame(Granularity.MIN_240, Granularity.MIN_60.coarser()); Assert.assertSame(Granularity.MIN_1440, Granularity.MIN_240.coarser()); } | public Granularity coarser() throws GranularityException { if (this == LAST) throw new GranularityException("Nothing coarser than " + name()); return granularities[index + 1]; } | Granularity { public Granularity coarser() throws GranularityException { if (this == LAST) throw new GranularityException("Nothing coarser than " + name()); return granularities[index + 1]; } } | Granularity { public Granularity coarser() throws GranularityException { if (this == LAST) throw new GranularityException("Nothing coarser than " + name()); return granularities[index + 1]; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { public Granularity coarser() throws GranularityException { if (this == LAST) throw new GranularityException("Nothing coarser than " + name()); return granularities[index + 1]; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { public Granularity coarser() throws GranularityException { if (this == LAST) throw new GranularityException("Nothing coarser than " + name()); return granularities[index + 1]; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test(expected = GranularityException.class) public void testTooCoarse() throws Exception { Granularity.MIN_1440.coarser(); } | public Granularity coarser() throws GranularityException { if (this == LAST) throw new GranularityException("Nothing coarser than " + name()); return granularities[index + 1]; } | Granularity { public Granularity coarser() throws GranularityException { if (this == LAST) throw new GranularityException("Nothing coarser than " + name()); return granularities[index + 1]; } } | Granularity { public Granularity coarser() throws GranularityException { if (this == LAST) throw new GranularityException("Nothing coarser than " + name()); return granularities[index + 1]; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { public Granularity coarser() throws GranularityException { if (this == LAST) throw new GranularityException("Nothing coarser than " + name()); return granularities[index + 1]; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { public Granularity coarser() throws GranularityException { if (this == LAST) throw new GranularityException("Nothing coarser than " + name()); return granularities[index + 1]; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test public void finerReturnsFiner() throws GranularityException { Assert.assertSame(Granularity.FULL, Granularity.MIN_5.finer()); Assert.assertSame(Granularity.MIN_5, Granularity.MIN_20.finer()); Assert.assertSame(Granularity.MIN_20, Granularity.MIN_60.finer()); Assert.assertSame(Granularity.MIN_60, Granularity.MIN_240.finer()); Assert.assertSame(Granularity.MIN_240, Granularity.MIN_1440.finer()); } | public Granularity finer() throws GranularityException { if (this == FULL) throw new GranularityException("Nothing finer than " + name()); return granularities[index - 1]; } | Granularity { public Granularity finer() throws GranularityException { if (this == FULL) throw new GranularityException("Nothing finer than " + name()); return granularities[index - 1]; } } | Granularity { public Granularity finer() throws GranularityException { if (this == FULL) throw new GranularityException("Nothing finer than " + name()); return granularities[index - 1]; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { public Granularity finer() throws GranularityException { if (this == FULL) throw new GranularityException("Nothing finer than " + name()); return granularities[index - 1]; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { public Granularity finer() throws GranularityException { if (this == FULL) throw new GranularityException("Nothing finer than " + name()); return granularities[index - 1]; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test(expected = GranularityException.class) public void testTooFine() throws Exception { Granularity.FULL.finer(); } | public Granularity finer() throws GranularityException { if (this == FULL) throw new GranularityException("Nothing finer than " + name()); return granularities[index - 1]; } | Granularity { public Granularity finer() throws GranularityException { if (this == FULL) throw new GranularityException("Nothing finer than " + name()); return granularities[index - 1]; } } | Granularity { public Granularity finer() throws GranularityException { if (this == FULL) throw new GranularityException("Nothing finer than " + name()); return granularities[index - 1]; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { public Granularity finer() throws GranularityException { if (this == FULL) throw new GranularityException("Nothing finer than " + name()); return granularities[index - 1]; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { public Granularity finer() throws GranularityException { if (this == FULL) throw new GranularityException("Nothing finer than " + name()); return granularities[index - 1]; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test(expected = RuntimeException.class) public void testToBeforeFromInterval() { Granularity.granularityFromPointsInInterval("TENANTID1234",fromBaseMillis+10000000, fromBaseMillis+0, 100); } | public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test public void firstTimeRetryOnUnavailable_shouldRetry() throws Exception { RetryNTimes retryPolicy = new RetryNTimes(3, 3, 3); Statement mockStatement = mock( Statement.class ); RetryPolicy.RetryDecision retryResult = retryPolicy.onUnavailable(mockStatement, ConsistencyLevel.LOCAL_ONE, 1, 0, 0); RetryPolicy.RetryDecision retryExpected = RetryPolicy.RetryDecision.retry(ConsistencyLevel.ONE); assertRetryDecisionEquals(retryExpected, retryResult); } | @Override public RetryDecision onUnavailable(Statement stmnt, ConsistencyLevel cl, int requiredResponses, int receivedResponses, int uTime) { if (uTime < unavailableAttempts) { LOG.info(String.format("Retrying on unavailable: stmnt %s, consistency %s, " + "requiredResponse %d, receivedResponse %d, rTime %d", stmnt, cl, requiredResponses, receivedResponses, uTime)); return RetryDecision.retry(ConsistencyLevel.ONE); } return RetryDecision.rethrow(); } | RetryNTimes implements RetryPolicy { @Override public RetryDecision onUnavailable(Statement stmnt, ConsistencyLevel cl, int requiredResponses, int receivedResponses, int uTime) { if (uTime < unavailableAttempts) { LOG.info(String.format("Retrying on unavailable: stmnt %s, consistency %s, " + "requiredResponse %d, receivedResponse %d, rTime %d", stmnt, cl, requiredResponses, receivedResponses, uTime)); return RetryDecision.retry(ConsistencyLevel.ONE); } return RetryDecision.rethrow(); } } | RetryNTimes implements RetryPolicy { @Override public RetryDecision onUnavailable(Statement stmnt, ConsistencyLevel cl, int requiredResponses, int receivedResponses, int uTime) { if (uTime < unavailableAttempts) { LOG.info(String.format("Retrying on unavailable: stmnt %s, consistency %s, " + "requiredResponse %d, receivedResponse %d, rTime %d", stmnt, cl, requiredResponses, receivedResponses, uTime)); return RetryDecision.retry(ConsistencyLevel.ONE); } return RetryDecision.rethrow(); } RetryNTimes(int readAttempts, int writeAttempts, int unavailableAttempts); } | RetryNTimes implements RetryPolicy { @Override public RetryDecision onUnavailable(Statement stmnt, ConsistencyLevel cl, int requiredResponses, int receivedResponses, int uTime) { if (uTime < unavailableAttempts) { LOG.info(String.format("Retrying on unavailable: stmnt %s, consistency %s, " + "requiredResponse %d, receivedResponse %d, rTime %d", stmnt, cl, requiredResponses, receivedResponses, uTime)); return RetryDecision.retry(ConsistencyLevel.ONE); } return RetryDecision.rethrow(); } RetryNTimes(int readAttempts, int writeAttempts, int unavailableAttempts); @Override RetryDecision onReadTimeout(Statement stmnt, ConsistencyLevel cl,
int requiredResponses, int receivedResponses,
boolean dataReceived, int rTime); @Override RetryDecision onWriteTimeout(Statement stmnt, ConsistencyLevel cl,
WriteType wt, int requiredResponses,
int receivedResponses, int wTime); @Override RetryDecision onUnavailable(Statement stmnt, ConsistencyLevel cl,
int requiredResponses, int receivedResponses, int uTime); @Override RetryDecision onRequestError(Statement statement, ConsistencyLevel cl, DriverException e, int nbRetry); @Override void init(Cluster cluster); @Override void close(); } | RetryNTimes implements RetryPolicy { @Override public RetryDecision onUnavailable(Statement stmnt, ConsistencyLevel cl, int requiredResponses, int receivedResponses, int uTime) { if (uTime < unavailableAttempts) { LOG.info(String.format("Retrying on unavailable: stmnt %s, consistency %s, " + "requiredResponse %d, receivedResponse %d, rTime %d", stmnt, cl, requiredResponses, receivedResponses, uTime)); return RetryDecision.retry(ConsistencyLevel.ONE); } return RetryDecision.rethrow(); } RetryNTimes(int readAttempts, int writeAttempts, int unavailableAttempts); @Override RetryDecision onReadTimeout(Statement stmnt, ConsistencyLevel cl,
int requiredResponses, int receivedResponses,
boolean dataReceived, int rTime); @Override RetryDecision onWriteTimeout(Statement stmnt, ConsistencyLevel cl,
WriteType wt, int requiredResponses,
int receivedResponses, int wTime); @Override RetryDecision onUnavailable(Statement stmnt, ConsistencyLevel cl,
int requiredResponses, int receivedResponses, int uTime); @Override RetryDecision onRequestError(Statement statement, ConsistencyLevel cl, DriverException e, int nbRetry); @Override void init(Cluster cluster); @Override void close(); } |
@Test public void equalsWithSameValueReturnsTrue() { Assert.assertTrue(Granularity.FULL.equals(Granularity.FULL)); Assert.assertTrue(Granularity.MIN_5.equals(Granularity.MIN_5)); Assert.assertTrue(Granularity.MIN_20.equals(Granularity.MIN_20)); Assert.assertTrue(Granularity.MIN_60.equals(Granularity.MIN_60)); Assert.assertTrue(Granularity.MIN_240.equals(Granularity.MIN_240)); Assert.assertTrue(Granularity.MIN_1440.equals(Granularity.MIN_1440)); } | @Override public boolean equals(Object obj) { if (!(obj instanceof Granularity)) return false; else return obj == this; } | Granularity { @Override public boolean equals(Object obj) { if (!(obj instanceof Granularity)) return false; else return obj == this; } } | Granularity { @Override public boolean equals(Object obj) { if (!(obj instanceof Granularity)) return false; else return obj == this; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { @Override public boolean equals(Object obj) { if (!(obj instanceof Granularity)) return false; else return obj == this; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { @Override public boolean equals(Object obj) { if (!(obj instanceof Granularity)) return false; else return obj == this; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test public void equalsWithDifferentValueReturnsFalse() { Assert.assertFalse(Granularity.FULL.equals(Granularity.MIN_5)); Assert.assertFalse(Granularity.FULL.equals(Granularity.MIN_20)); Assert.assertFalse(Granularity.FULL.equals(Granularity.MIN_60)); Assert.assertFalse(Granularity.FULL.equals(Granularity.MIN_240)); Assert.assertFalse(Granularity.FULL.equals(Granularity.MIN_1440)); Assert.assertFalse(Granularity.MIN_5.equals(Granularity.FULL)); Assert.assertFalse(Granularity.MIN_5.equals(Granularity.MIN_20)); Assert.assertFalse(Granularity.MIN_5.equals(Granularity.MIN_60)); Assert.assertFalse(Granularity.MIN_5.equals(Granularity.MIN_240)); Assert.assertFalse(Granularity.MIN_5.equals(Granularity.MIN_1440)); Assert.assertFalse(Granularity.MIN_20.equals(Granularity.FULL)); Assert.assertFalse(Granularity.MIN_20.equals(Granularity.MIN_5)); Assert.assertFalse(Granularity.MIN_20.equals(Granularity.MIN_60)); Assert.assertFalse(Granularity.MIN_20.equals(Granularity.MIN_240)); Assert.assertFalse(Granularity.MIN_20.equals(Granularity.MIN_1440)); Assert.assertFalse(Granularity.MIN_60.equals(Granularity.FULL)); Assert.assertFalse(Granularity.MIN_60.equals(Granularity.MIN_5)); Assert.assertFalse(Granularity.MIN_60.equals(Granularity.MIN_20)); Assert.assertFalse(Granularity.MIN_60.equals(Granularity.MIN_240)); Assert.assertFalse(Granularity.MIN_60.equals(Granularity.MIN_1440)); Assert.assertFalse(Granularity.MIN_240.equals(Granularity.FULL)); Assert.assertFalse(Granularity.MIN_240.equals(Granularity.MIN_5)); Assert.assertFalse(Granularity.MIN_240.equals(Granularity.MIN_20)); Assert.assertFalse(Granularity.MIN_240.equals(Granularity.MIN_60)); Assert.assertFalse(Granularity.MIN_240.equals(Granularity.MIN_1440)); Assert.assertFalse(Granularity.MIN_1440.equals(Granularity.FULL)); Assert.assertFalse(Granularity.MIN_1440.equals(Granularity.MIN_5)); Assert.assertFalse(Granularity.MIN_1440.equals(Granularity.MIN_20)); Assert.assertFalse(Granularity.MIN_1440.equals(Granularity.MIN_60)); Assert.assertFalse(Granularity.MIN_1440.equals(Granularity.MIN_240)); } | @Override public boolean equals(Object obj) { if (!(obj instanceof Granularity)) return false; else return obj == this; } | Granularity { @Override public boolean equals(Object obj) { if (!(obj instanceof Granularity)) return false; else return obj == this; } } | Granularity { @Override public boolean equals(Object obj) { if (!(obj instanceof Granularity)) return false; else return obj == this; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { @Override public boolean equals(Object obj) { if (!(obj instanceof Granularity)) return false; else return obj == this; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { @Override public boolean equals(Object obj) { if (!(obj instanceof Granularity)) return false; else return obj == this; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test public void equalsWithNullReturnsFalse() { Assert.assertFalse(Granularity.FULL.equals(null)); Assert.assertFalse(Granularity.MIN_5.equals(null)); Assert.assertFalse(Granularity.MIN_20.equals(null)); Assert.assertFalse(Granularity.MIN_60.equals(null)); Assert.assertFalse(Granularity.MIN_240.equals(null)); Assert.assertFalse(Granularity.MIN_1440.equals(null)); } | @Override public boolean equals(Object obj) { if (!(obj instanceof Granularity)) return false; else return obj == this; } | Granularity { @Override public boolean equals(Object obj) { if (!(obj instanceof Granularity)) return false; else return obj == this; } } | Granularity { @Override public boolean equals(Object obj) { if (!(obj instanceof Granularity)) return false; else return obj == this; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { @Override public boolean equals(Object obj) { if (!(obj instanceof Granularity)) return false; else return obj == this; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { @Override public boolean equals(Object obj) { if (!(obj instanceof Granularity)) return false; else return obj == this; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test public void equalsWithNonGranularityObjectReturnsFalse() { Assert.assertFalse(Granularity.FULL.equals(new Object())); Assert.assertFalse(Granularity.MIN_5.equals(new Object())); Assert.assertFalse(Granularity.MIN_20.equals(new Object())); Assert.assertFalse(Granularity.MIN_60.equals(new Object())); Assert.assertFalse(Granularity.MIN_240.equals(new Object())); Assert.assertFalse(Granularity.MIN_1440.equals(new Object())); } | @Override public boolean equals(Object obj) { if (!(obj instanceof Granularity)) return false; else return obj == this; } | Granularity { @Override public boolean equals(Object obj) { if (!(obj instanceof Granularity)) return false; else return obj == this; } } | Granularity { @Override public boolean equals(Object obj) { if (!(obj instanceof Granularity)) return false; else return obj == this; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { @Override public boolean equals(Object obj) { if (!(obj instanceof Granularity)) return false; else return obj == this; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { @Override public boolean equals(Object obj) { if (!(obj instanceof Granularity)) return false; else return obj == this; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test public void fromStringFull() { String s = "metrics_full"; Granularity gran = Granularity.fromString(s); Assert.assertNotNull(gran); Assert.assertSame(Granularity.FULL, gran); } | public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } | Granularity { public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } } | Granularity { public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test public void fromString5m() { String s = "metrics_5m"; Granularity gran = Granularity.fromString(s); Assert.assertNotNull(gran); Assert.assertSame(Granularity.MIN_5, gran); } | public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } | Granularity { public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } } | Granularity { public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test public void fromString20m() { String s = "metrics_20m"; Granularity gran = Granularity.fromString(s); Assert.assertNotNull(gran); Assert.assertSame(Granularity.MIN_20, gran); } | public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } | Granularity { public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } } | Granularity { public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test public void fromString60m() { String s = "metrics_60m"; Granularity gran = Granularity.fromString(s); Assert.assertNotNull(gran); Assert.assertSame(Granularity.MIN_60, gran); } | public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } | Granularity { public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } } | Granularity { public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test public void fromString240m() { String s = "metrics_240m"; Granularity gran = Granularity.fromString(s); Assert.assertSame(Granularity.MIN_240, gran); } | public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } | Granularity { public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } } | Granularity { public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
Subsets and Splits