Return-Path: X-Original-To: apmail-incubator-jena-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-jena-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 8C4777620 for ; Mon, 7 Nov 2011 13:37:46 +0000 (UTC) Received: (qmail 59640 invoked by uid 500); 7 Nov 2011 13:37:46 -0000 Delivered-To: apmail-incubator-jena-commits-archive@incubator.apache.org Received: (qmail 59616 invoked by uid 500); 7 Nov 2011 13:37:46 -0000 Mailing-List: contact jena-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: jena-dev@incubator.apache.org Delivered-To: mailing list jena-commits@incubator.apache.org Received: (qmail 59609 invoked by uid 99); 7 Nov 2011 13:37:46 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 07 Nov 2011 13:37:46 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 07 Nov 2011 13:37:39 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 99C642388B46; Mon, 7 Nov 2011 13:36:42 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1198733 [8/13] - in /incubator/jena/Scratch/AFS/Dev/trunk: src-archive/riot/comms/ src-archive/riot/comms/client/ src-archive/riot/comms/server0/ src-archive/riot/comms/server1/nio/ src-archive/riot/comms/server1/socket/ src-archive/riot/c... Date: Mon, 07 Nov 2011 13:36:34 -0000 To: jena-commits@incubator.apache.org From: andy@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20111107133642.99C642388B46@eris.apache.org> Modified: incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/structure/ttree/TTreeNode.java URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/structure/ttree/TTreeNode.java?rev=1198733&r1=1198732&r2=1198733&view=diff ============================================================================== --- incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/structure/ttree/TTreeNode.java (original) +++ incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/structure/ttree/TTreeNode.java Mon Nov 7 13:36:30 2011 @@ -1,4 +1,4 @@ -/** +/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -16,477 +16,477 @@ * limitations under the License. */ -package structure.ttree; - -import static structure.ttree.TTree.Checking ; -import static structure.ttree.TTree.error ; - -import java.util.List ; - -import migrate.lib.ArrayOps ; -import org.openjena.atlas.io.IndentedWriter ; -import org.openjena.atlas.io.PrintUtils ; -import org.openjena.atlas.io.Printable ; -import org.openjena.atlas.lib.Alg ; -import org.openjena.atlas.lib.Lib ; - -final -class TTreeNode> implements Printable -{ - // Debug - private static int counter = 0 ; - // Make this static (or remove). - private int id ; - - int height = TTree.InitialHeight ; // New nodes are always leaves. - TTreeNode parent ; - TTreeNode left ; - TTreeNode right ; - // Need to record start and stop if want slicing. - // Or nulls at low end during insert into a full node. - int nodeSize ; - T elements[] ; - - /** Create a new T-Tree node */ - @SuppressWarnings("unchecked") - TTreeNode(TTreeNodeparent, int size) - { - id = (++counter) ; - this.elements = (T[])new Comparable[size] ; - this.nodeSize = 0 ; - this.height = TTree.InitialHeight ; - this.parent = parent ; - //Arrays.fill(elements, null) ; - } - - void set(T[] elements, int els, TTreeNode parent, TTreeNode left, TTreeNode right) - { - this.elements = elements ; - this.nodeSize = els ; - this.parent = parent ; - this.left = left ; - this.right = right ; - this.parent = parent ; - this.height = -1 ; - } - - /** Insert a item into a node. - * - * @param item - * @return true if the node changed (replace a different element or insert the element) - */ - boolean add(T item) - { - int idx = find(item) ; - - if ( idx < 0 ) - { - if ( elements.length == nodeSize ) - error("Already full") ; - insertAt(Alg.decodeIndex(idx), item) ; - return true ; - } - else - { - T orig = elements[idx] ; - if ( Lib.equal(item, orig) ) - return false ; - elements[idx] = item ; - return true ; - } - } - - void insertAt(int idx,T item) - { - ArrayOps.insert(elements, idx, item) ; - nodeSize++ ; - } - - T removeBottom() - { - if ( Checking && isEmpty() ) - throw new TTreeException("node empty") ; - T item = elements[0] ; - ArrayOps.shiftDown(elements, 0, nodeSize) ; - nodeSize-- ; - return item ; - } - - T removeTop() - { - if ( Checking && isEmpty() ) - throw new TTreeException("node empty") ; - T item = elements[nodeSize-1] ; - if ( TTree.NullOut ) elements[nodeSize-1] = null ; - nodeSize-- ; - return item ; - } - - /** Find an item - return the index in the array or -(index+1) - * encoding the insertion point. - * - * @param item - * @return encoded index. - */ - int find(T item) - { - int x = Alg.binarySearch(elements, 0, nodeSize, item) ; - return x ; - } - - /** Delete from this TTreeNode - * - * @param item - * @return true if a change to the node occurred - */ - boolean delete(T item) - { - if ( elements.length == 0 ) - error("Already empty") ; - int idx = find(item) ; - if ( idx < 0 ) - return false ; - T item2 = ArrayOps.delete(elements, idx) ; - nodeSize-- ; - //if ( Checking ) check() ; // Can be invalid pending fixup - return true ; - } - - boolean isFull() { return nodeSize == elements.length ; } - boolean isEmpty() { return nodeSize == 0 ; } - - /** Both sides have nodes below them */ - boolean isInternal() { return left != null && right != null ; } - - /** One side or the other has a node, the other does not */ - boolean isHalfLeaf() { return isLeftHalfLeaf() || isRightHalfLeaf() ; } - - /** LeftHalfLeaf - no node below on the left, but there is one on the right */ - boolean isLeftHalfLeaf() { return left == null && right != null ; } - /** LeftHalfLeaf - node below on the left, but not on the right */ - boolean isRightHalfLeaf() { return left != null && right == null ; } - - /** No nodes below this one, to left or to the right */ - boolean isLeaf() { return left == null && right == null ; } - - int nodeSize() { return nodeSize ; } - - private static final String undef = "_" ; - /** Only makes sense when the "id" is being allocated for all nodes */ - static > String label(TTreeNode n) - { - if ( n == null ) - return undef ; - return Integer.toString(n.id) ; - } - - - T getMin() - { - if ( isEmpty() ) - return null ; - return elements[0] ; - } - - T getMax() - { - if ( isEmpty() ) - return null ; - return elements[nodeSize-1] ; - } - -// T getGreatestLowerBound() -// { -// if ( isEmpty() ) -// return null ; -// TTreeNode node = this ; -// if ( node.left != null ) -// node = getRightDeep(node.left) ; -// return node.getMax() ; -// } -// -// T getLeastUpperBound() -// { -// if ( isEmpty() ) -// return null ; -// TTreeNode node = this ; -// if ( node.right != null ) -// node = getLeftDeep(node.right) ; -// return node.getMin() ; -// } - - static > TTreeNode getLeftDeep(TTreeNode node) - { - TTreeNode node2 = node.left ; - while( node2 != null ) - { - node = node2 ; - node2 = node2.left ; - } - return node ; - } - - static > TTreeNode getRightDeep(TTreeNode node) - { - TTreeNode node2 = node.right ; - while( node2 != null ) - { - node = node2 ; - node2 = node2.right ; - } - return node ; - } - -// TTreeNode getParent() -// { -// return parent ; -// } -// -// TTreeNode getLeft() -// { -// return left ; -// } -// -// TTreeNode getRight() -// { -// return right ; -// } - - void elements(List acc) - { - if ( left != null ) - left.elements(acc) ; - for ( T item : elements ) - { - if ( item == null ) break ; - acc.add(item) ; - } - if ( right != null ) - right.elements(acc) ; - } - - long sizeDeep() - { - long size = 0 ; - if ( left != null ) - size += left.sizeDeep() ; - size += nodeSize ; - if ( right != null ) - size += right.sizeDeep() ; - return size ; - } - - // ---- Output - @Override - public void output(IndentedWriter out) - { - out.printf("id=%d parent=%s h=%d len=%d left=%s right=%s [",id, label(parent), height, nodeSize, label(left), label(right)) ; - for ( int i = 0 ; i < nodeSize ; i++ ) - { - if ( i != 0 ) out.print(" ") ; - out.print(elements[i]) ; - } - out.print("]") ; - } - - /** Print structured */ - void outputNested(IndentedWriter out, boolean detailed) - { - out.print("(") ; - output(out) ; - if ( left == null && right == null ) - { - out.println(")") ; - return ; - } - out.println() ; - - - out.incIndent() ; - if ( left != null ) - { - out.ensureStartOfLine() ; - left.outputNested(out, detailed) ; - } - else - { - out.ensureStartOfLine() ; - out.println("()") ; - } - out.decIndent() ; - - out.incIndent() ; - if ( right != null ) - { - out.ensureStartOfLine() ; - right.outputNested(out, detailed) ; - } - else - { - out.ensureStartOfLine() ; - out.println("()") ; - } - out.decIndent() ; - out.print(")") ; - } - - @Override - public String toString() { return PrintUtils.toString(this) ; } - - // ---- Check - - final void checkDeep(TTree ttree) - { - if ( ! Checking ) - return ; - check(ttree) ; - if ( left != null ) - left.checkDeep(ttree); - if ( right != null ) - right.checkDeep(ttree); - } - - final void check(TTree ttree) - { - if ( ! Checking ) - return ; - if ( nodeSize > elements.length ) - error("Node size %d, Array size: %d : %s", nodeSize, elements.length, this) ; - - // -- Structure checks - if ( parent != null ) - { - if ( parent.left == this ) - { - if ( parent.left.id != this.id ) - error("Parent.left does not point to this node by id") ; - } - else if ( parent.right == this ) - { - if ( parent.right.id != this.id ) - error("Parent.right does not point to this node by id") ; - } - else - error("Parent does not point to this node") ; - } - - if ( isInternal() || isHalfLeaf() ) - { - if ( ttree != null ) - { - // Internal nodes are always full - // Half-leaves are always full (by modified half-leaf rule on deletion) - if ( nodeSize < ttree.NodeSizeMin ) - error("Internal node too small") ; - } - } - else if ( isLeftHalfLeaf() ) - { - if ( ! right.isLeaf() ) - error("LeftHalfLeaf has no leaf to the right") ; - } - else if ( isRightHalfLeaf() ) - { - if ( ! left.isLeaf() ) - error("RightHalfLeaf has no leaf to the left") ; - } - else if ( isLeaf()) - { - if ( parent != null && nodeSize <= 0 ) - error("Zero length node") ; - } - else - error("Node has no leaf status") ; - - // Children checks - if ( left != null && left.parent != this ) - error("Left child does not point back to this node") ; - - if ( left != null && left.parent.id != this.id ) - error("Left child does not point back to this node by id") ; - - if ( right != null && right.parent != this ) - error("Right child does not point back to this node") ; - - if ( right != null && right.parent.id != this.id ) - error("Right child does not point back to this node by id") ; - - // -- Ordering checks - // Order within this node - T prev = null ; - for ( int i = 0 ; i < nodeSize ; i++ ) - { - if ( elements[i] == null ) - error("Null array entry idx=%d : %s", i, this) ; - if ( prev != null ) - { - if ( prev.compareTo(elements[i]) >= 0 ) - error("Unordered: idx=%d : %s %s : %s", i, prev, elements[i], this) ; - } - prev = elements[i] ; - } - // Check upper area is cleared. - if ( TTree.NullOut ) - { - for ( int i = nodeSize ; i < elements.length ; i++ ) - { - if ( elements[i] != null ) - error("Not null array entry idx=%d : %s", i, this) ; - } - } - - if ( nodeSize > 0 ) - { - // Check ordering from left and right. - if ( left != null && left.nodeSize>0 && left.getMax().compareTo(getMin()) > 0 ) // If this less than left. - error("Out of order (left): [id=%s] %s/%s", label(left), left.getMax(), getMin()) ; - - if ( left != null && left.nodeSize>0 && left.getMax().compareTo(getMin()) == 0 ) // Duplicate. - error("Duplicate (left): [id=%s] %s/%s", label(left), left.getMax(), getMin()) ; - - if ( right != null && right.nodeSize>0 && right.getMin().compareTo(getMax()) < 0 ) // If this more than right - error("Out of order (right): [id=%s] %s/%s", label(right), right.getMin(), getMax()) ; - - if ( right != null && right.nodeSize>0 && right.getMin().compareTo(getMax()) == 0 ) // Duplicate. - error("Duplicate (right): [id=%s] %s/%s", label(right), right.getMin(), getMin()) ; - } - - // -- Balance checks - int x = TTree.balance(this) ; - if ( x < -1 || x > 1 ) - error("Out of balance %d: %s", x, this) ; - - // -- Height checks - - if ( left != null && height < left.height ) - error("Height error (left) [%d,%d]", height, left.height) ; - - if ( right != null && height < right.height ) - error("Height error (right) [%d,%d]", height, right.height) ; - - if ( left == null && right != null ) - { - if ( height != right.height+1 ) - error("Bad height (right) - not %d", right.height+1) ; - } - else if ( left != null && right == null ) - { - if ( height != left.height+1 ) - error("Bad height (left) - not %d", left.height+1) ; - - } - else if ( left != null && right != null ) - { - if ( height < left.height || height < right.height ) - {} - - if ( height != left.height+1 && height != right.height+1 ) - error("Bad height (%d) - not %d or %d", id, left.height+1, right.height+1) ; - } - else - { - if ( height != TTree.InitialHeight ) - error("Leaf node height not %d", TTree.InitialHeight) ; - } - } +package structure.ttree; + +import static structure.ttree.TTree.Checking ; +import static structure.ttree.TTree.error ; + +import java.util.List ; + +import migrate.lib.ArrayOps ; +import org.openjena.atlas.io.IndentedWriter ; +import org.openjena.atlas.io.PrintUtils ; +import org.openjena.atlas.io.Printable ; +import org.openjena.atlas.lib.Alg ; +import org.openjena.atlas.lib.Lib ; + +final +class TTreeNode> implements Printable +{ + // Debug + private static int counter = 0 ; + // Make this static (or remove). + private int id ; + + int height = TTree.InitialHeight ; // New nodes are always leaves. + TTreeNode parent ; + TTreeNode left ; + TTreeNode right ; + // Need to record start and stop if want slicing. + // Or nulls at low end during insert into a full node. + int nodeSize ; + T elements[] ; + + /** Create a new T-Tree node */ + @SuppressWarnings("unchecked") + TTreeNode(TTreeNodeparent, int size) + { + id = (++counter) ; + this.elements = (T[])new Comparable[size] ; + this.nodeSize = 0 ; + this.height = TTree.InitialHeight ; + this.parent = parent ; + //Arrays.fill(elements, null) ; + } + + void set(T[] elements, int els, TTreeNode parent, TTreeNode left, TTreeNode right) + { + this.elements = elements ; + this.nodeSize = els ; + this.parent = parent ; + this.left = left ; + this.right = right ; + this.parent = parent ; + this.height = -1 ; + } + + /** Insert a item into a node. + * + * @param item + * @return true if the node changed (replace a different element or insert the element) + */ + boolean add(T item) + { + int idx = find(item) ; + + if ( idx < 0 ) + { + if ( elements.length == nodeSize ) + error("Already full") ; + insertAt(Alg.decodeIndex(idx), item) ; + return true ; + } + else + { + T orig = elements[idx] ; + if ( Lib.equal(item, orig) ) + return false ; + elements[idx] = item ; + return true ; + } + } + + void insertAt(int idx,T item) + { + ArrayOps.insert(elements, idx, item) ; + nodeSize++ ; + } + + T removeBottom() + { + if ( Checking && isEmpty() ) + throw new TTreeException("node empty") ; + T item = elements[0] ; + ArrayOps.shiftDown(elements, 0, nodeSize) ; + nodeSize-- ; + return item ; + } + + T removeTop() + { + if ( Checking && isEmpty() ) + throw new TTreeException("node empty") ; + T item = elements[nodeSize-1] ; + if ( TTree.NullOut ) elements[nodeSize-1] = null ; + nodeSize-- ; + return item ; + } + + /** Find an item - return the index in the array or -(index+1) + * encoding the insertion point. + * + * @param item + * @return encoded index. + */ + int find(T item) + { + int x = Alg.binarySearch(elements, 0, nodeSize, item) ; + return x ; + } + + /** Delete from this TTreeNode + * + * @param item + * @return true if a change to the node occurred + */ + boolean delete(T item) + { + if ( elements.length == 0 ) + error("Already empty") ; + int idx = find(item) ; + if ( idx < 0 ) + return false ; + T item2 = ArrayOps.delete(elements, idx) ; + nodeSize-- ; + //if ( Checking ) check() ; // Can be invalid pending fixup + return true ; + } + + boolean isFull() { return nodeSize == elements.length ; } + boolean isEmpty() { return nodeSize == 0 ; } + + /** Both sides have nodes below them */ + boolean isInternal() { return left != null && right != null ; } + + /** One side or the other has a node, the other does not */ + boolean isHalfLeaf() { return isLeftHalfLeaf() || isRightHalfLeaf() ; } + + /** LeftHalfLeaf - no node below on the left, but there is one on the right */ + boolean isLeftHalfLeaf() { return left == null && right != null ; } + /** LeftHalfLeaf - node below on the left, but not on the right */ + boolean isRightHalfLeaf() { return left != null && right == null ; } + + /** No nodes below this one, to left or to the right */ + boolean isLeaf() { return left == null && right == null ; } + + int nodeSize() { return nodeSize ; } + + private static final String undef = "_" ; + /** Only makes sense when the "id" is being allocated for all nodes */ + static > String label(TTreeNode n) + { + if ( n == null ) + return undef ; + return Integer.toString(n.id) ; + } + + + T getMin() + { + if ( isEmpty() ) + return null ; + return elements[0] ; + } + + T getMax() + { + if ( isEmpty() ) + return null ; + return elements[nodeSize-1] ; + } + +// T getGreatestLowerBound() +// { +// if ( isEmpty() ) +// return null ; +// TTreeNode node = this ; +// if ( node.left != null ) +// node = getRightDeep(node.left) ; +// return node.getMax() ; +// } +// +// T getLeastUpperBound() +// { +// if ( isEmpty() ) +// return null ; +// TTreeNode node = this ; +// if ( node.right != null ) +// node = getLeftDeep(node.right) ; +// return node.getMin() ; +// } + + static > TTreeNode getLeftDeep(TTreeNode node) + { + TTreeNode node2 = node.left ; + while( node2 != null ) + { + node = node2 ; + node2 = node2.left ; + } + return node ; + } + + static > TTreeNode getRightDeep(TTreeNode node) + { + TTreeNode node2 = node.right ; + while( node2 != null ) + { + node = node2 ; + node2 = node2.right ; + } + return node ; + } + +// TTreeNode getParent() +// { +// return parent ; +// } +// +// TTreeNode getLeft() +// { +// return left ; +// } +// +// TTreeNode getRight() +// { +// return right ; +// } + + void elements(List acc) + { + if ( left != null ) + left.elements(acc) ; + for ( T item : elements ) + { + if ( item == null ) break ; + acc.add(item) ; + } + if ( right != null ) + right.elements(acc) ; + } + + long sizeDeep() + { + long size = 0 ; + if ( left != null ) + size += left.sizeDeep() ; + size += nodeSize ; + if ( right != null ) + size += right.sizeDeep() ; + return size ; + } + + // ---- Output + @Override + public void output(IndentedWriter out) + { + out.printf("id=%d parent=%s h=%d len=%d left=%s right=%s [",id, label(parent), height, nodeSize, label(left), label(right)) ; + for ( int i = 0 ; i < nodeSize ; i++ ) + { + if ( i != 0 ) out.print(" ") ; + out.print(elements[i]) ; + } + out.print("]") ; + } + + /** Print structured */ + void outputNested(IndentedWriter out, boolean detailed) + { + out.print("(") ; + output(out) ; + if ( left == null && right == null ) + { + out.println(")") ; + return ; + } + out.println() ; + + + out.incIndent() ; + if ( left != null ) + { + out.ensureStartOfLine() ; + left.outputNested(out, detailed) ; + } + else + { + out.ensureStartOfLine() ; + out.println("()") ; + } + out.decIndent() ; + + out.incIndent() ; + if ( right != null ) + { + out.ensureStartOfLine() ; + right.outputNested(out, detailed) ; + } + else + { + out.ensureStartOfLine() ; + out.println("()") ; + } + out.decIndent() ; + out.print(")") ; + } + + @Override + public String toString() { return PrintUtils.toString(this) ; } + + // ---- Check + + final void checkDeep(TTree ttree) + { + if ( ! Checking ) + return ; + check(ttree) ; + if ( left != null ) + left.checkDeep(ttree); + if ( right != null ) + right.checkDeep(ttree); + } + + final void check(TTree ttree) + { + if ( ! Checking ) + return ; + if ( nodeSize > elements.length ) + error("Node size %d, Array size: %d : %s", nodeSize, elements.length, this) ; + + // -- Structure checks + if ( parent != null ) + { + if ( parent.left == this ) + { + if ( parent.left.id != this.id ) + error("Parent.left does not point to this node by id") ; + } + else if ( parent.right == this ) + { + if ( parent.right.id != this.id ) + error("Parent.right does not point to this node by id") ; + } + else + error("Parent does not point to this node") ; + } + + if ( isInternal() || isHalfLeaf() ) + { + if ( ttree != null ) + { + // Internal nodes are always full + // Half-leaves are always full (by modified half-leaf rule on deletion) + if ( nodeSize < ttree.NodeSizeMin ) + error("Internal node too small") ; + } + } + else if ( isLeftHalfLeaf() ) + { + if ( ! right.isLeaf() ) + error("LeftHalfLeaf has no leaf to the right") ; + } + else if ( isRightHalfLeaf() ) + { + if ( ! left.isLeaf() ) + error("RightHalfLeaf has no leaf to the left") ; + } + else if ( isLeaf()) + { + if ( parent != null && nodeSize <= 0 ) + error("Zero length node") ; + } + else + error("Node has no leaf status") ; + + // Children checks + if ( left != null && left.parent != this ) + error("Left child does not point back to this node") ; + + if ( left != null && left.parent.id != this.id ) + error("Left child does not point back to this node by id") ; + + if ( right != null && right.parent != this ) + error("Right child does not point back to this node") ; + + if ( right != null && right.parent.id != this.id ) + error("Right child does not point back to this node by id") ; + + // -- Ordering checks + // Order within this node + T prev = null ; + for ( int i = 0 ; i < nodeSize ; i++ ) + { + if ( elements[i] == null ) + error("Null array entry idx=%d : %s", i, this) ; + if ( prev != null ) + { + if ( prev.compareTo(elements[i]) >= 0 ) + error("Unordered: idx=%d : %s %s : %s", i, prev, elements[i], this) ; + } + prev = elements[i] ; + } + // Check upper area is cleared. + if ( TTree.NullOut ) + { + for ( int i = nodeSize ; i < elements.length ; i++ ) + { + if ( elements[i] != null ) + error("Not null array entry idx=%d : %s", i, this) ; + } + } + + if ( nodeSize > 0 ) + { + // Check ordering from left and right. + if ( left != null && left.nodeSize>0 && left.getMax().compareTo(getMin()) > 0 ) // If this less than left. + error("Out of order (left): [id=%s] %s/%s", label(left), left.getMax(), getMin()) ; + + if ( left != null && left.nodeSize>0 && left.getMax().compareTo(getMin()) == 0 ) // Duplicate. + error("Duplicate (left): [id=%s] %s/%s", label(left), left.getMax(), getMin()) ; + + if ( right != null && right.nodeSize>0 && right.getMin().compareTo(getMax()) < 0 ) // If this more than right + error("Out of order (right): [id=%s] %s/%s", label(right), right.getMin(), getMax()) ; + + if ( right != null && right.nodeSize>0 && right.getMin().compareTo(getMax()) == 0 ) // Duplicate. + error("Duplicate (right): [id=%s] %s/%s", label(right), right.getMin(), getMin()) ; + } + + // -- Balance checks + int x = TTree.balance(this) ; + if ( x < -1 || x > 1 ) + error("Out of balance %d: %s", x, this) ; + + // -- Height checks + + if ( left != null && height < left.height ) + error("Height error (left) [%d,%d]", height, left.height) ; + + if ( right != null && height < right.height ) + error("Height error (right) [%d,%d]", height, right.height) ; + + if ( left == null && right != null ) + { + if ( height != right.height+1 ) + error("Bad height (right) - not %d", right.height+1) ; + } + else if ( left != null && right == null ) + { + if ( height != left.height+1 ) + error("Bad height (left) - not %d", left.height+1) ; + + } + else if ( left != null && right != null ) + { + if ( height < left.height || height < right.height ) + {} + + if ( height != left.height+1 && height != right.height+1 ) + error("Bad height (%d) - not %d or %d", id, left.height+1, right.height+1) ; + } + else + { + if ( height != TTree.InitialHeight ) + error("Leaf node height not %d", TTree.InitialHeight) ; + } + } } Modified: incubator/jena/Scratch/AFS/Dev/trunk/src-lib/test/java/migrate/lib/TestArrayOps.java URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Dev/trunk/src-lib/test/java/migrate/lib/TestArrayOps.java?rev=1198733&r1=1198732&r2=1198733&view=diff ============================================================================== --- incubator/jena/Scratch/AFS/Dev/trunk/src-lib/test/java/migrate/lib/TestArrayOps.java (original) +++ incubator/jena/Scratch/AFS/Dev/trunk/src-lib/test/java/migrate/lib/TestArrayOps.java Mon Nov 7 13:36:30 2011 @@ -1,4 +1,4 @@ -/** +/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -16,288 +16,288 @@ * limitations under the License. */ -package migrate.lib; - -import java.util.Iterator; - -import migrate.lib.ArrayOps; -import org.junit.BeforeClass; -import org.junit.Test; -import org.openjena.atlas.junit.BaseTest ; - -public class TestArrayOps extends BaseTest -{ - @BeforeClass public static void beforeClass() - { - //ArrayOps.NullOut = true ; - ArrayOps.Checking = true ; - } - - // ---- Clear - @Test public void clear1() - { - String[] array = {"a", "b", "c", null, null } ; - String[] array2 = {null, "b", "c", null, null } ; - ArrayOps.clear(array, 0, 1 ) ; - assertArrayEquals(array2,array) ; - } - - @Test public void clear2() - { - String[] array = {"a", "b", "c", "d", null } ; - String[] array2 = {"a", null, null, "d", null } ; - ArrayOps.clear(array, 1, 2 ) ; - assertArrayEquals(array2,array) ; - } - - @Test public void clear3() - { - String[] array = {"a", "b", "c"} ; - String[] array2 = {null, null, null} ; - ArrayOps.clear(array) ; - assertArrayEquals(array2, array) ; - } - - // ---- Shift Up - // Should shift extends the array? Yes. - @Test public void shift_up_1() - { - String[] array = {"a", "b", "c", "d", "e" } ; - String[] array2 = {null, "a", "b", "c", "e"} ; // Extends to length 4. - ArrayOps.shiftUp(array, 0, 3) ; - assertArrayEquals(array2, array) ; - } - - @Test public void shift_up_2() - { - String[] array = {"a", "b", "c", "d", "e" } ; - String[] array2 = {"a", "b", "c", null, "d"} ; - ArrayOps.shiftUp(array, 3, array.length-1) ; - assertArrayEquals(array2, array) ; - } - - @Test public void shift_up_3() - { - String[] array = {"a", "b", "c", "d", "e" } ; - String[] array2 = {"a", "b", "c", "d", null} ; - ArrayOps.shiftUp(array, 4, 5) ; - assertArrayEquals(array2, array) ; - } - - @Test public void shift_up_4() - { - String[] array = {"a", "b", "c", "d", "e" } ; - String[] array2 = {"a", "b", "c", null, "d" } ; - // Shift at top - ArrayOps.shiftUp(array, 3, 4) ; - assertArrayEquals(array2, array) ; - } - - @Test public void shift_up_5() - { - String[] array = {"a", "b", "c", "d", "e" } ; - String[] array2 = {"a", null, null, "b", "c"} ; - ArrayOps.shiftUpN(array, 1, 2, 5) ; - assertArrayEquals(array2, array) ; - } - - @Test public void shift_up_6() - { - String[] array = {"a", "b", "c", "d", "e" } ; - String[] array2 = {null, null, null, null, null} ; - ArrayOps.shiftUpN(array, 0, 5, 3) ; - assertArrayEquals(array2, array) ; - } - - @Test(expected=ArrayOps.ArrayException.class) - public void shift_up_7() - { - String[] array = {"a", "b", "c", "d", "e" } ; - String[] array2 = {null, null, null, null, null} ; - ArrayOps.shiftUpN(array, 0, 6, 3) ; - assertArrayEquals(array2, array) ; - } - - // ---- Shift Down - - @Test public void shift_down_1() - { - String[] array = {"a", "b", "c", "d", "e" } ; - String[] array2 = {"b", "c", null, "d", "e"} ; - ArrayOps.shiftDown(array, 0, 3) ; - assertArrayEquals(array2, array) ; - } - - @Test public void shift_down_2() - { - String[] array = {"a", "b", "c", "d", "e" } ; - String[] array2 = {"a", "c", null, "d", "e"} ; - ArrayOps.shiftDown(array, 1, 3) ; - assertArrayEquals(array2, array) ; - } - - @Test public void shift_down_3() - { - String[] array = {"a", "b", "c", "d", "e" } ; - String[] array2 = {"a", "b", null, "d", "e"} ; - ArrayOps.shiftDown(array, 2, 3) ; - assertArrayEquals(array2, array) ; - } - - @Test(expected=ArrayOps.ArrayException.class) - public void shift_down_4() - { - String[] array = {"a", "b", "c", "d", "e" } ; - String[] array2 = {} ; - ArrayOps.shiftDown(array, 3, 3) ; - assertArrayEquals(array2, array) ; - } - - @Test public void shift_down_5() - { - String[] array = {"a", "b", "c", "d", "e" } ; - String[] array2 = {"a", "b", "c", "d", null } ; - ArrayOps.shiftDown(array, 4, 5) ; - assertArrayEquals(array2, array) ; - } - - @Test public void shift_down_6() - { - String[] array = {"a", "b", "c", "d", "e" } ; - String[] array2 = {"a", "b", "c", null, null } ; - ArrayOps.shiftDownN(array, 3, 2, 5) ; - assertArrayEquals(array2, array) ; - } - - @Test(expected=ArrayOps.ArrayException.class) - public void shift_down_7() - { - String[] array = {"a", "b", "c", "d", "e" } ; - String[] array2 = {} ; - ArrayOps.shiftDownN(array, 4, 2, 5) ; - assertArrayEquals(array2, array) ; - } - - // ---- Insert - - @Test public void insert1() - { - String[] array = {"a", "b", "c", "d", "e" } ; - String[] array2 = {"z", "a", "b", "c", "e"} ; - ArrayOps.insert(array, 0, "z", 3) ; - assertArrayEquals(array2, array) ; - } - - @Test public void insert2() - { - String[] array = {"a", "b", "c", "d", "e" } ; - String[] array2 = {"a", "z", "b", "c", "e" } ; - ArrayOps.insert(array, 1, "z", 3) ; - assertArrayEquals(array2, array) ; - } - - @Test public void insert3() - { - String[] array = {"a", "b", "c", "d", "e" } ; - String[] array2 = {"a", "b", "z", "c", "e" } ; - ArrayOps.insert(array, 2, "z", 3) ; - assertArrayEquals(array2, array) ; - } - - @Test public void insert4() - { - String[] array = {"a", "b", "c", "d", "e" } ; - String[] array2 = {"a", "b", "c", "d", "z" } ; - ArrayOps.insert(array, 4, "z", 4) ; - assertArrayEquals(array2, array) ; - } - - @Test public void insert5() - { - String[] array = {"a", "b", "c", "d", "e" } ; - String[] array2 = {"a", "b", "c", "d", "z" } ; - ArrayOps.insert(array, 4, "z", 5) ; - assertArrayEquals(array2, array) ; - } - - @Test public void insert7() - { - String[] array = {"a", "b", "c", "d", "e" } ; - String[] array2 = {"z", "a", "b", "c", "d"} ; - ArrayOps.insert(array, 0, "z", 5) ; - assertArrayEquals(array2, array) ; - } - - @Test(expected=ArrayOps.ArrayException.class) - public void insert8() - { - String[] array = {"a", "b", "c", "d", "e" } ; - String[] array2 = {} ; - ArrayOps.insert(array, 5, "z", 5) ; - assertArrayEquals(array2, array) ; - } - - @Test(expected=ArrayOps.ArrayException.class) - public void insert9() - { - String[] array = {"a", "b", "c", "d", "e" } ; - String[] array2 = {} ; - ArrayOps.insert(array, 5, "z", 4) ; - assertArrayEquals(array2, array) ; - } - - // ---- Delete - - @Test public void delete1() - { - String[] array = {"a", "b", "c", "d", "e" } ; - String[] array2 = {"b", "c", null, "d", "e"} ; - String x = ArrayOps.delete(array, 0, 3) ; - assertArrayEquals(array2, array) ; - assertEquals("a", x) ; - } - - @Test public void delete2() - { - String[] array = {"a", "b", "c", "d", "e" } ; - String[] array2 = {"a", "c", null, "d", "e"} ; - String x = ArrayOps.delete(array, 1, 3) ; - assertArrayEquals(array2, array) ; - assertEquals("b", x) ; - } - - @Test public void delete3() - { - String[] array = {"a", "b", "c", "d", "e" } ; - String[] array2 = {"a", "b", null, "d", "e"} ; - String x = ArrayOps.delete(array, 2, 3) ; - assertArrayEquals(array2, array) ; - assertEquals("c", x) ; - } - - @Test public void delete4() - { - String[] array = {"a", "b", "c", "d", "e" } ; - String[] array2 = {"a", "b", "d", "e", null} ; - String x = ArrayOps.delete(array, 2, 5) ; - assertArrayEquals(array2, array) ; - assertEquals("c", x) ; - } - - @Test public void delete5() - { - String[] array = {"a", "b", "c", "d", "e" } ; - String[] array2 = {"a", "b", "c", "d", null} ; - String x = ArrayOps.delete(array, 4, 5) ; - assertArrayEquals(array2, array) ; - assertEquals("e", x) ; - } - - @Test public void iterate1() - { - String[] array = {"a", "b", "c", "d", "e" } ; - Iterator iter = ArrayOps.iterator(array) ; - for ( int i = 0 ; iter.hasNext() ; i++ ) - assertEquals(array[i], iter.next()) ; - } +package migrate.lib; + +import java.util.Iterator; + +import migrate.lib.ArrayOps; +import org.junit.BeforeClass; +import org.junit.Test; +import org.openjena.atlas.junit.BaseTest ; + +public class TestArrayOps extends BaseTest +{ + @BeforeClass public static void beforeClass() + { + //ArrayOps.NullOut = true ; + ArrayOps.Checking = true ; + } + + // ---- Clear + @Test public void clear1() + { + String[] array = {"a", "b", "c", null, null } ; + String[] array2 = {null, "b", "c", null, null } ; + ArrayOps.clear(array, 0, 1 ) ; + assertArrayEquals(array2,array) ; + } + + @Test public void clear2() + { + String[] array = {"a", "b", "c", "d", null } ; + String[] array2 = {"a", null, null, "d", null } ; + ArrayOps.clear(array, 1, 2 ) ; + assertArrayEquals(array2,array) ; + } + + @Test public void clear3() + { + String[] array = {"a", "b", "c"} ; + String[] array2 = {null, null, null} ; + ArrayOps.clear(array) ; + assertArrayEquals(array2, array) ; + } + + // ---- Shift Up + // Should shift extends the array? Yes. + @Test public void shift_up_1() + { + String[] array = {"a", "b", "c", "d", "e" } ; + String[] array2 = {null, "a", "b", "c", "e"} ; // Extends to length 4. + ArrayOps.shiftUp(array, 0, 3) ; + assertArrayEquals(array2, array) ; + } + + @Test public void shift_up_2() + { + String[] array = {"a", "b", "c", "d", "e" } ; + String[] array2 = {"a", "b", "c", null, "d"} ; + ArrayOps.shiftUp(array, 3, array.length-1) ; + assertArrayEquals(array2, array) ; + } + + @Test public void shift_up_3() + { + String[] array = {"a", "b", "c", "d", "e" } ; + String[] array2 = {"a", "b", "c", "d", null} ; + ArrayOps.shiftUp(array, 4, 5) ; + assertArrayEquals(array2, array) ; + } + + @Test public void shift_up_4() + { + String[] array = {"a", "b", "c", "d", "e" } ; + String[] array2 = {"a", "b", "c", null, "d" } ; + // Shift at top + ArrayOps.shiftUp(array, 3, 4) ; + assertArrayEquals(array2, array) ; + } + + @Test public void shift_up_5() + { + String[] array = {"a", "b", "c", "d", "e" } ; + String[] array2 = {"a", null, null, "b", "c"} ; + ArrayOps.shiftUpN(array, 1, 2, 5) ; + assertArrayEquals(array2, array) ; + } + + @Test public void shift_up_6() + { + String[] array = {"a", "b", "c", "d", "e" } ; + String[] array2 = {null, null, null, null, null} ; + ArrayOps.shiftUpN(array, 0, 5, 3) ; + assertArrayEquals(array2, array) ; + } + + @Test(expected=ArrayOps.ArrayException.class) + public void shift_up_7() + { + String[] array = {"a", "b", "c", "d", "e" } ; + String[] array2 = {null, null, null, null, null} ; + ArrayOps.shiftUpN(array, 0, 6, 3) ; + assertArrayEquals(array2, array) ; + } + + // ---- Shift Down + + @Test public void shift_down_1() + { + String[] array = {"a", "b", "c", "d", "e" } ; + String[] array2 = {"b", "c", null, "d", "e"} ; + ArrayOps.shiftDown(array, 0, 3) ; + assertArrayEquals(array2, array) ; + } + + @Test public void shift_down_2() + { + String[] array = {"a", "b", "c", "d", "e" } ; + String[] array2 = {"a", "c", null, "d", "e"} ; + ArrayOps.shiftDown(array, 1, 3) ; + assertArrayEquals(array2, array) ; + } + + @Test public void shift_down_3() + { + String[] array = {"a", "b", "c", "d", "e" } ; + String[] array2 = {"a", "b", null, "d", "e"} ; + ArrayOps.shiftDown(array, 2, 3) ; + assertArrayEquals(array2, array) ; + } + + @Test(expected=ArrayOps.ArrayException.class) + public void shift_down_4() + { + String[] array = {"a", "b", "c", "d", "e" } ; + String[] array2 = {} ; + ArrayOps.shiftDown(array, 3, 3) ; + assertArrayEquals(array2, array) ; + } + + @Test public void shift_down_5() + { + String[] array = {"a", "b", "c", "d", "e" } ; + String[] array2 = {"a", "b", "c", "d", null } ; + ArrayOps.shiftDown(array, 4, 5) ; + assertArrayEquals(array2, array) ; + } + + @Test public void shift_down_6() + { + String[] array = {"a", "b", "c", "d", "e" } ; + String[] array2 = {"a", "b", "c", null, null } ; + ArrayOps.shiftDownN(array, 3, 2, 5) ; + assertArrayEquals(array2, array) ; + } + + @Test(expected=ArrayOps.ArrayException.class) + public void shift_down_7() + { + String[] array = {"a", "b", "c", "d", "e" } ; + String[] array2 = {} ; + ArrayOps.shiftDownN(array, 4, 2, 5) ; + assertArrayEquals(array2, array) ; + } + + // ---- Insert + + @Test public void insert1() + { + String[] array = {"a", "b", "c", "d", "e" } ; + String[] array2 = {"z", "a", "b", "c", "e"} ; + ArrayOps.insert(array, 0, "z", 3) ; + assertArrayEquals(array2, array) ; + } + + @Test public void insert2() + { + String[] array = {"a", "b", "c", "d", "e" } ; + String[] array2 = {"a", "z", "b", "c", "e" } ; + ArrayOps.insert(array, 1, "z", 3) ; + assertArrayEquals(array2, array) ; + } + + @Test public void insert3() + { + String[] array = {"a", "b", "c", "d", "e" } ; + String[] array2 = {"a", "b", "z", "c", "e" } ; + ArrayOps.insert(array, 2, "z", 3) ; + assertArrayEquals(array2, array) ; + } + + @Test public void insert4() + { + String[] array = {"a", "b", "c", "d", "e" } ; + String[] array2 = {"a", "b", "c", "d", "z" } ; + ArrayOps.insert(array, 4, "z", 4) ; + assertArrayEquals(array2, array) ; + } + + @Test public void insert5() + { + String[] array = {"a", "b", "c", "d", "e" } ; + String[] array2 = {"a", "b", "c", "d", "z" } ; + ArrayOps.insert(array, 4, "z", 5) ; + assertArrayEquals(array2, array) ; + } + + @Test public void insert7() + { + String[] array = {"a", "b", "c", "d", "e" } ; + String[] array2 = {"z", "a", "b", "c", "d"} ; + ArrayOps.insert(array, 0, "z", 5) ; + assertArrayEquals(array2, array) ; + } + + @Test(expected=ArrayOps.ArrayException.class) + public void insert8() + { + String[] array = {"a", "b", "c", "d", "e" } ; + String[] array2 = {} ; + ArrayOps.insert(array, 5, "z", 5) ; + assertArrayEquals(array2, array) ; + } + + @Test(expected=ArrayOps.ArrayException.class) + public void insert9() + { + String[] array = {"a", "b", "c", "d", "e" } ; + String[] array2 = {} ; + ArrayOps.insert(array, 5, "z", 4) ; + assertArrayEquals(array2, array) ; + } + + // ---- Delete + + @Test public void delete1() + { + String[] array = {"a", "b", "c", "d", "e" } ; + String[] array2 = {"b", "c", null, "d", "e"} ; + String x = ArrayOps.delete(array, 0, 3) ; + assertArrayEquals(array2, array) ; + assertEquals("a", x) ; + } + + @Test public void delete2() + { + String[] array = {"a", "b", "c", "d", "e" } ; + String[] array2 = {"a", "c", null, "d", "e"} ; + String x = ArrayOps.delete(array, 1, 3) ; + assertArrayEquals(array2, array) ; + assertEquals("b", x) ; + } + + @Test public void delete3() + { + String[] array = {"a", "b", "c", "d", "e" } ; + String[] array2 = {"a", "b", null, "d", "e"} ; + String x = ArrayOps.delete(array, 2, 3) ; + assertArrayEquals(array2, array) ; + assertEquals("c", x) ; + } + + @Test public void delete4() + { + String[] array = {"a", "b", "c", "d", "e" } ; + String[] array2 = {"a", "b", "d", "e", null} ; + String x = ArrayOps.delete(array, 2, 5) ; + assertArrayEquals(array2, array) ; + assertEquals("c", x) ; + } + + @Test public void delete5() + { + String[] array = {"a", "b", "c", "d", "e" } ; + String[] array2 = {"a", "b", "c", "d", null} ; + String x = ArrayOps.delete(array, 4, 5) ; + assertArrayEquals(array2, array) ; + assertEquals("e", x) ; + } + + @Test public void iterate1() + { + String[] array = {"a", "b", "c", "d", "e" } ; + Iterator iter = ArrayOps.iterator(array) ; + for ( int i = 0 ; iter.hasNext() ; i++ ) + assertEquals(array[i], iter.next()) ; + } } Modified: incubator/jena/Scratch/AFS/Dev/trunk/src-lib/test/java/migrate/lib/TestByteArray.java URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Dev/trunk/src-lib/test/java/migrate/lib/TestByteArray.java?rev=1198733&r1=1198732&r2=1198733&view=diff ============================================================================== --- incubator/jena/Scratch/AFS/Dev/trunk/src-lib/test/java/migrate/lib/TestByteArray.java (original) +++ incubator/jena/Scratch/AFS/Dev/trunk/src-lib/test/java/migrate/lib/TestByteArray.java Mon Nov 7 13:36:30 2011 @@ -1,4 +1,4 @@ -/** +/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -16,32 +16,32 @@ * limitations under the License. */ -package migrate.lib; - -import org.junit.Test ; -import org.openjena.atlas.junit.BaseTest ; - -public class TestByteArray extends BaseTest -{ - @Test public void bytearray_01() - { - ByteArray b = new ByteArray() ; - compare(b, new byte[]{}) ; - } - - @Test public void bytearray_02() - { - ByteArray b = new ByteArray() ; - b.add((byte)1) ; - compare(b, new byte[]{1}) ; - } - - - private static void compare(ByteArray bytes, byte[] contents) - { - assertEquals(bytes.length(), contents.length) ; - for ( int i = 0 ; i < contents.length ; i++ ) - assertEquals(contents[i], bytes.get(i)) ; - - } +package migrate.lib; + +import org.junit.Test ; +import org.openjena.atlas.junit.BaseTest ; + +public class TestByteArray extends BaseTest +{ + @Test public void bytearray_01() + { + ByteArray b = new ByteArray() ; + compare(b, new byte[]{}) ; + } + + @Test public void bytearray_02() + { + ByteArray b = new ByteArray() ; + b.add((byte)1) ; + compare(b, new byte[]{1}) ; + } + + + private static void compare(ByteArray bytes, byte[] contents) + { + assertEquals(bytes.length(), contents.length) ; + for ( int i = 0 ; i < contents.length ; i++ ) + assertEquals(contents[i], bytes.get(i)) ; + + } } Modified: incubator/jena/Scratch/AFS/Dev/trunk/src-lib/test/java/migrate/lib/TestVarInteger.java URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Dev/trunk/src-lib/test/java/migrate/lib/TestVarInteger.java?rev=1198733&r1=1198732&r2=1198733&view=diff ============================================================================== --- incubator/jena/Scratch/AFS/Dev/trunk/src-lib/test/java/migrate/lib/TestVarInteger.java (original) +++ incubator/jena/Scratch/AFS/Dev/trunk/src-lib/test/java/migrate/lib/TestVarInteger.java Mon Nov 7 13:36:30 2011 @@ -1,4 +1,4 @@ -/** +/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -16,148 +16,148 @@ * limitations under the License. */ -package migrate.lib; - -import java.nio.ByteBuffer ; - -import org.junit.Test ; -import org.openjena.atlas.junit.BaseTest ; -import org.openjena.atlas.lib.ByteBufferLib ; - -public class TestVarInteger extends BaseTest -{ - @Test public void varint_01() - { - VarInteger vint = VarInteger.valueOf(0) ; - assertEquals(1, vint.length()) ; - assertEquals((byte)0, vint.bytes()[0]) ; - assertEquals(0L, vint.value()) ; - } - - @Test public void varint_02() - { - VarInteger vint = VarInteger.valueOf(1) ; - assertEquals(1, vint.length()) ; - assertEquals((byte)1, vint.bytes()[0]) ; - assertEquals(1L, vint.value()) ; - } - - @Test public void varint_03() - { - VarInteger vint = VarInteger.valueOf(127) ; - assertEquals(1, vint.length()) ; - assertEquals((byte)0x7F, vint.bytes()[0]) ; - assertEquals(127L, vint.value()) ; - } - - @Test public void varint_04() - { - VarInteger vint = VarInteger.valueOf(128) ; - assertEquals(2, vint.length()) ; - assertEquals((byte)0x80, vint.bytes()[0]) ; - assertEquals((byte)0x01, vint.bytes()[1]) ; - assertEquals(128L, vint.value()) ; - } - - @Test public void varint_05() - { - VarInteger vint = VarInteger.valueOf(129) ; - assertEquals(2, vint.length()) ; - assertEquals((byte)0x81, vint.bytes()[0]) ; - assertEquals((byte)0x01, vint.bytes()[1]) ; - assertEquals(129L, vint.value()) ; - } - - @Test public void varint_10() - { - VarInteger vint = VarInteger.valueOf(1L<<45) ; - //assertEquals(2, vint.length()) ; - assertEquals(1L<<45, vint.value()) ; - } - - // General hammering. - @Test public void varint_N() - { - for ( long x = 0 ; x < (1L<<17) ; x++ ) - { - VarInteger vint = VarInteger.valueOf(x) ; - assertEquals(x, vint.value()) ; - } - } - - @Test public void varint_eq_1() - { - VarInteger x = VarInteger.valueOf(0) ; - VarInteger x0 = VarInteger.valueOf(0) ; - VarInteger x1 = VarInteger.valueOf(1) ; - assertEquals(x.hashCode(), x0.hashCode()) ; - assertNotEquals(x.hashCode(), x1.hashCode()) ; - assertEquals(x, x0) ; - assertNotEquals(x, x1) ; - } - - @Test public void varint_eq_2() - { - VarInteger x = VarInteger.valueOf(1) ; - VarInteger x0 = VarInteger.valueOf(0) ; - VarInteger x1 = VarInteger.valueOf(1) ; - assertEquals(x.hashCode(), x1.hashCode()) ; - assertNotEquals(x.hashCode(), x0.hashCode()) ; - assertEquals(x, x1) ; - assertNotEquals(x, x0) ; - } - - private static void eq(long value) - { - VarInteger x0 = VarInteger.valueOf(value) ; - VarInteger x1 = VarInteger.valueOf(value) ; - assertEquals(x0.hashCode(), x1.hashCode()) ; - assertEquals(x0, x1) ; - } - - @Test public void varint_eq_3() { eq(127) ; } - @Test public void varint_eq_4() { eq(128) ; } - @Test public void varint_eq_5() { eq(129) ; } - - @Test public void varint_bb_1() - { - ByteBuffer bb = ByteBuffer.allocate(8) ; - ByteBufferLib.fill(bb, (byte)0) ; - VarInteger.encode(bb, 1, 2L<<14) ; - assertEquals(0, bb.get(0)) ; - } - - @Test public void varint_extract_1() - { - VarInteger x0 = VarInteger.valueOf(113) ; - VarInteger x1 = VarInteger.make(x0.bytes) ; - assertEquals(x0, x1) ; - } - - @Test public void varint_extract_2() - { - VarInteger x0 = VarInteger.valueOf(113) ; - ByteBuffer bb = ByteBuffer.wrap(x0.bytes()) ; - VarInteger x1 = VarInteger.make(bb,0) ; - assertEquals(x0, x1) ; - } - - @Test public void varint_extract_3() - { - VarInteger x0 = VarInteger.valueOf(11377) ; - ByteBuffer bb = ByteBuffer.wrap(x0.bytes()) ; - VarInteger x1 = VarInteger.make(bb,0) ; - assertEquals(x0, x1) ; - } - - @Test public void varint_length_1() - { - assertEquals(1, VarInteger.lengthOf(0)) ; - assertEquals(1, VarInteger.lengthOf(1)) ; - assertEquals(1, VarInteger.lengthOf(127)) ; - assertEquals(2, VarInteger.lengthOf(128)) ; - assertEquals(2, VarInteger.lengthOf(1L<<14-1)) ; - assertEquals(3, VarInteger.lengthOf(1L<<14)) ; - assertEquals(8, VarInteger.lengthOf(1L<<56-1)) ; - } +package migrate.lib; + +import java.nio.ByteBuffer ; + +import org.junit.Test ; +import org.openjena.atlas.junit.BaseTest ; +import org.openjena.atlas.lib.ByteBufferLib ; + +public class TestVarInteger extends BaseTest +{ + @Test public void varint_01() + { + VarInteger vint = VarInteger.valueOf(0) ; + assertEquals(1, vint.length()) ; + assertEquals((byte)0, vint.bytes()[0]) ; + assertEquals(0L, vint.value()) ; + } + + @Test public void varint_02() + { + VarInteger vint = VarInteger.valueOf(1) ; + assertEquals(1, vint.length()) ; + assertEquals((byte)1, vint.bytes()[0]) ; + assertEquals(1L, vint.value()) ; + } + + @Test public void varint_03() + { + VarInteger vint = VarInteger.valueOf(127) ; + assertEquals(1, vint.length()) ; + assertEquals((byte)0x7F, vint.bytes()[0]) ; + assertEquals(127L, vint.value()) ; + } + + @Test public void varint_04() + { + VarInteger vint = VarInteger.valueOf(128) ; + assertEquals(2, vint.length()) ; + assertEquals((byte)0x80, vint.bytes()[0]) ; + assertEquals((byte)0x01, vint.bytes()[1]) ; + assertEquals(128L, vint.value()) ; + } + + @Test public void varint_05() + { + VarInteger vint = VarInteger.valueOf(129) ; + assertEquals(2, vint.length()) ; + assertEquals((byte)0x81, vint.bytes()[0]) ; + assertEquals((byte)0x01, vint.bytes()[1]) ; + assertEquals(129L, vint.value()) ; + } + + @Test public void varint_10() + { + VarInteger vint = VarInteger.valueOf(1L<<45) ; + //assertEquals(2, vint.length()) ; + assertEquals(1L<<45, vint.value()) ; + } + + // General hammering. + @Test public void varint_N() + { + for ( long x = 0 ; x < (1L<<17) ; x++ ) + { + VarInteger vint = VarInteger.valueOf(x) ; + assertEquals(x, vint.value()) ; + } + } + + @Test public void varint_eq_1() + { + VarInteger x = VarInteger.valueOf(0) ; + VarInteger x0 = VarInteger.valueOf(0) ; + VarInteger x1 = VarInteger.valueOf(1) ; + assertEquals(x.hashCode(), x0.hashCode()) ; + assertNotEquals(x.hashCode(), x1.hashCode()) ; + assertEquals(x, x0) ; + assertNotEquals(x, x1) ; + } + + @Test public void varint_eq_2() + { + VarInteger x = VarInteger.valueOf(1) ; + VarInteger x0 = VarInteger.valueOf(0) ; + VarInteger x1 = VarInteger.valueOf(1) ; + assertEquals(x.hashCode(), x1.hashCode()) ; + assertNotEquals(x.hashCode(), x0.hashCode()) ; + assertEquals(x, x1) ; + assertNotEquals(x, x0) ; + } + + private static void eq(long value) + { + VarInteger x0 = VarInteger.valueOf(value) ; + VarInteger x1 = VarInteger.valueOf(value) ; + assertEquals(x0.hashCode(), x1.hashCode()) ; + assertEquals(x0, x1) ; + } + + @Test public void varint_eq_3() { eq(127) ; } + @Test public void varint_eq_4() { eq(128) ; } + @Test public void varint_eq_5() { eq(129) ; } + + @Test public void varint_bb_1() + { + ByteBuffer bb = ByteBuffer.allocate(8) ; + ByteBufferLib.fill(bb, (byte)0) ; + VarInteger.encode(bb, 1, 2L<<14) ; + assertEquals(0, bb.get(0)) ; + } + + @Test public void varint_extract_1() + { + VarInteger x0 = VarInteger.valueOf(113) ; + VarInteger x1 = VarInteger.make(x0.bytes) ; + assertEquals(x0, x1) ; + } + + @Test public void varint_extract_2() + { + VarInteger x0 = VarInteger.valueOf(113) ; + ByteBuffer bb = ByteBuffer.wrap(x0.bytes()) ; + VarInteger x1 = VarInteger.make(bb,0) ; + assertEquals(x0, x1) ; + } + + @Test public void varint_extract_3() + { + VarInteger x0 = VarInteger.valueOf(11377) ; + ByteBuffer bb = ByteBuffer.wrap(x0.bytes()) ; + VarInteger x1 = VarInteger.make(bb,0) ; + assertEquals(x0, x1) ; + } + + @Test public void varint_length_1() + { + assertEquals(1, VarInteger.lengthOf(0)) ; + assertEquals(1, VarInteger.lengthOf(1)) ; + assertEquals(1, VarInteger.lengthOf(127)) ; + assertEquals(2, VarInteger.lengthOf(128)) ; + assertEquals(2, VarInteger.lengthOf(1L<<14-1)) ; + assertEquals(3, VarInteger.lengthOf(1L<<14)) ; + assertEquals(8, VarInteger.lengthOf(1L<<56-1)) ; + } } Modified: incubator/jena/Scratch/AFS/Dev/trunk/src-lib/test/java/structure/OrderedSetTest.java URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Dev/trunk/src-lib/test/java/structure/OrderedSetTest.java?rev=1198733&r1=1198732&r2=1198733&view=diff ============================================================================== --- incubator/jena/Scratch/AFS/Dev/trunk/src-lib/test/java/structure/OrderedSetTest.java (original) +++ incubator/jena/Scratch/AFS/Dev/trunk/src-lib/test/java/structure/OrderedSetTest.java Mon Nov 7 13:36:30 2011 @@ -1,4 +1,4 @@ -/** +/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -16,30 +16,30 @@ * limitations under the License. */ -package structure; - -import static org.openjena.atlas.lib.RandomLib.random; -import org.openjena.atlas.test.ExecGenerator; - -class OrderedSetTest implements ExecGenerator -{ - int maxNumKeys ; - int maxValue ; - OrderedSetTestFactory factory ; - - OrderedSetTest(OrderedSetTestFactory factory, int maxValue, int maxNumKeys) - { - if ( maxValue <= maxNumKeys ) - throw new IllegalArgumentException("SortedIndexTest: Max value less than number of keys") ; - this.maxValue = maxValue ; - this.maxNumKeys = maxNumKeys ; - this.factory = factory ; - } - - @Override - public void executeOneTest() - { - int numKeys = random.nextInt(maxNumKeys)+1 ; - OrderedSetTestLib.randTest(factory, maxValue, numKeys) ; - } +package structure; + +import static org.openjena.atlas.lib.RandomLib.random; +import org.openjena.atlas.test.ExecGenerator; + +class OrderedSetTest implements ExecGenerator +{ + int maxNumKeys ; + int maxValue ; + OrderedSetTestFactory factory ; + + OrderedSetTest(OrderedSetTestFactory factory, int maxValue, int maxNumKeys) + { + if ( maxValue <= maxNumKeys ) + throw new IllegalArgumentException("SortedIndexTest: Max value less than number of keys") ; + this.maxValue = maxValue ; + this.maxNumKeys = maxNumKeys ; + this.factory = factory ; + } + + @Override + public void executeOneTest() + { + int numKeys = random.nextInt(maxNumKeys)+1 ; + OrderedSetTestLib.randTest(factory, maxValue, numKeys) ; + } }