package panacea.core.util.bplustree; import java.util.AbstractMap; import java.util.Map; /** * An inner tree node. * * @author Gili Tzabari */ public class InnerNode extends AbstractMap implements Map { private final List keys; private final List> children; private final Comparator comparator; private static class NaturalOrdering implements Comparator { @SuppressWarnings("unchecked") public int compare(K first, K second) { return ((Comparable) first).compareTo(second); } } /** * A subset of an existing map. * * @param K the key type * @param V the value type */ private abstract class SubMap extends AbstractMap implements NavigableMap { private final K fromElement; private final boolean fromInclusive; private final K toElement; private final boolean toInclusive; /** * Creates a new subset of a map. * * @param fromKey low endpoint of the keys in the returned map * @param fromInclusive true if the low endpoint is to be included in the * returned view * @param toKey high endpoint of the keys in the returned map * @param toInclusive true if the high endpoint is to be included in the * returned view */ public SubMap(K fromElement, boolean fromInclusive, K toElement, boolean toInclusive) { this.fromElement = fromElement; this.fromInclusive = fromInclusive; this.toElement = toElement; this.toInclusive = toInclusive; } @Override public Entry lowerEntry(K key) { throw new UnsupportedOperationException("Not supported yet."); } @Override public K lowerKey(K key) { throw new UnsupportedOperationException("Not supported yet."); } @Override public Entry floorEntry(K key) { throw new UnsupportedOperationException("Not supported yet."); } @Override public K floorKey(K key) { throw new UnsupportedOperationException("Not supported yet."); } @Override public Entry ceilingEntry(K key) { throw new UnsupportedOperationException("Not supported yet."); } @Override public K ceilingKey(K key) { throw new UnsupportedOperationException("Not supported yet."); } @Override public Entry higherEntry(K key) { throw new UnsupportedOperationException("Not supported yet."); } @Override public K higherKey(K key) { throw new UnsupportedOperationException("Not supported yet."); } @Override public Entry firstEntry() { throw new UnsupportedOperationException("Not supported yet."); } @Override public Entry lastEntry() { throw new UnsupportedOperationException("Not supported yet."); } @Override public Entry pollFirstEntry() { throw new UnsupportedOperationException("Not supported yet."); } @Override public Entry pollLastEntry() { throw new UnsupportedOperationException("Not supported yet."); } @Override public NavigableMap descendingMap() { throw new UnsupportedOperationException("Not supported yet."); } @Override public NavigableSet navigableKeySet() { throw new UnsupportedOperationException("Not supported yet."); } @Override public NavigableSet descendingKeySet() { throw new UnsupportedOperationException("Not supported yet."); } @Override public NavigableMap subMap(K fromKey, boolean fromInclusive, K toKey, boolean toInclusive) { throw new UnsupportedOperationException("Not supported yet."); } @Override public NavigableMap headMap(K toKey, boolean inclusive) { throw new UnsupportedOperationException("Not supported yet."); } @Override public NavigableMap tailMap(K fromKey, boolean inclusive) { throw new UnsupportedOperationException("Not supported yet."); } @Override public NavigableMap subMap(K fromKey, K toKey) { throw new UnsupportedOperationException("Not supported yet."); } @Override public NavigableMap headMap(K toKey) { throw new UnsupportedOperationException("Not supported yet."); } @Override public NavigableMap tailMap(K fromKey) { throw new UnsupportedOperationException("Not supported yet."); } @Override public Comparator comparator() { throw new UnsupportedOperationException("Not supported yet."); } @Override public K firstKey() { throw new UnsupportedOperationException("Not supported yet."); } @Override public K lastKey() { throw new UnsupportedOperationException("Not supported yet."); } @Override public Set keySet() { throw new UnsupportedOperationException("Not supported yet."); } @Override public Collection values() { throw new UnsupportedOperationException("Not supported yet."); } @Override public Set> entrySet() { throw new UnsupportedOperationException("Not supported yet."); } @Override public int size() { throw new UnsupportedOperationException("Not supported yet."); } @Override public boolean isEmpty() { throw new UnsupportedOperationException("Not supported yet."); } @Override public boolean containsKey(Object key) { throw new UnsupportedOperationException("Not supported yet."); } @Override public boolean containsValue(Object value) { throw new UnsupportedOperationException("Not supported yet."); } @Override public V get(Object key) { throw new UnsupportedOperationException("Not supported yet."); } @Override public V put(K key, V value) { throw new UnsupportedOperationException("Not supported yet."); } @Override public V remove(Object key) { throw new UnsupportedOperationException("Not supported yet."); } @Override public void putAll(Map m) { throw new UnsupportedOperationException("Not supported yet."); } @Override public void clear() { throw new UnsupportedOperationException("Not supported yet."); } } /** * Creates a new inner node. * * @param capacity the maximum number of entries in the node */ public InnerNode(int capacity) { this(capacity, new NaturalOrdering()); } /** * Creates a new inner node. * * @param capacity the maximum number of entries in the node * @param comparator compares keys */ public InnerNode(int capacity, Comparator comparator) { this.keys = new ArrayList(capacity); this.children = new ArrayList>(capacity); this.comparator = comparator; } /** * Creates a view from an existing InnerNode. * * @param keys the node keys * @param children the node children * @param comparator the node comparator */ private InnerNode(List keys, List> children, Comparator comparator) { this.keys = keys; this.children = children; this.comparator = comparator; } /** * Returns the smallest key in the node. * * @return the smallest key in the node */ private K smallestKey() { return keys.get(0); } /** * Returns the largest key in the node. * * @return the largest key in the node */ private K largestKey() { return keys.get(keys.size() - 1); } /** * Returns the child node for which i = smallestKey() and all keys K are such * that K(i) <= K < K(i+1). * * @return */ private NavigableMap smallestChild() { return children.get(0); } /** * Returns the child node for which i = largestKey() and all keys K are such * that K(i) <= K < K(i+1). * * @return */ private NavigableMap largestChild() { return children.get(children.size() - 1); } /** * Returns the child node responsible for a key. * * @param key the key to look up * @return the child node responsible for the key */ private NavigableMap childNode(K key) { // B+ tree layout: // // | child[0] | key[0] | child[1] | key[1] | ... | child[n] | // / | \ // / | \ // | K < key[0] | key[0] <= K < key[1] | ... | key[n-1] <= K | // // 1) child[i] points to a subtree in which all key values K are such that // key[i-1] <= K < key[i] // 2) Find i such that key[i-1] <= K < key[i] and drill down into child[i] int keyIndex = Collections.binarySearch(keys, key, comparator); int childIndex; if (keyIndex == 0) childIndex = 0; else if (keyIndex > 0) { // key[i-1] <= child[i] implies that i = keyIndex + 1 childIndex = keyIndex + 1; } else { // index points to (-i - 1) childIndex = -(keyIndex + 1); } return children.get(childIndex); } @Override public Entry lowerEntry(K key) { return childNode(key).lowerEntry(key); } @Override public K lowerKey(K key) { return childNode(key).lowerKey(key); } @Override public Entry floorEntry(K key) { return childNode(key).floorEntry(key); } @Override public K floorKey(K key) { return childNode(key).floorKey(key); } @Override public Entry ceilingEntry(K key) { return childNode(key).ceilingEntry(key); } @Override public K ceilingKey(K key) { return childNode(key).ceilingKey(key); } @Override public Entry higherEntry(K key) { return childNode(key).higherEntry(key); } @Override public K higherKey(K key) { return childNode(key).ceilingKey(key); } @Override public Entry firstEntry() { return smallestChild().firstEntry(); } @Override public Entry lastEntry() { return largestChild().lastEntry(); } @Override public Entry pollFirstEntry() { return smallestChild().pollFirstEntry(); } @Override public Entry pollLastEntry() { return largestChild().pollLastEntry(); } @Override public NavigableMap descendingMap() { return null; } @Override public NavigableSet navigableKeySet() { return new NavigableSet() { @Override public K lower(K key) { return childNode(key).navigableKeySet().lower(key); } @Override public K floor(K key) { return childNode(key).navigableKeySet().floor(key); } @Override public K ceiling(K key) { return childNode(key).navigableKeySet().ceiling(key); } @Override public K higher(K key) { return childNode(key).navigableKeySet().higher(key); } @Override public K pollFirst() { return smallestKey().navigableKeySet().pollFirst(); } @Override public K pollLast() { return largestKey().navigableKeySet().pollLast(); } @Override public Iterator iterator() { return smallestKey().navigableKeySet().iterator(); } @Override public NavigableSet descendingSet() { throw new UnsupportedOperationException("Not supported yet."); } @Override public Iterator descendingIterator() { throw new UnsupportedOperationException("Not supported yet."); } @Override public NavigableSet subSet(K fromElement, boolean fromInclusive, K toElement, boolean toInclusive) { throw new UnsupportedOperationException("Not supported yet."); } @Override public NavigableSet headSet(K toElement, boolean inclusive) { throw new UnsupportedOperationException("Not supported yet."); } @Override public NavigableSet tailSet(K fromElement, boolean inclusive) { throw new UnsupportedOperationException("Not supported yet."); } @Override public NavigableSet subSet(K fromElement, K toElement) { throw new UnsupportedOperationException("Not supported yet."); } @Override public NavigableSet headSet(K toElement) { throw new UnsupportedOperationException("Not supported yet."); } @Override public NavigableSet tailSet(K fromElement) { throw new UnsupportedOperationException("Not supported yet."); } @Override public Comparator comparator() { throw new UnsupportedOperationException("Not supported yet."); } @Override public K first() { throw new UnsupportedOperationException("Not supported yet."); } @Override public K last() { throw new UnsupportedOperationException("Not supported yet."); } @Override public int size() { throw new UnsupportedOperationException("Not supported yet."); } @Override public boolean isEmpty() { throw new UnsupportedOperationException("Not supported yet."); } @Override public boolean contains(Object o) { throw new UnsupportedOperationException("Not supported yet."); } @Override public Object[] toArray() { throw new UnsupportedOperationException("Not supported yet."); } @Override public T[] toArray(T[] a) { throw new UnsupportedOperationException("Not supported yet."); } @Override public boolean add(K key) { throw new UnsupportedOperationException("Not supported yet."); } @Override public boolean remove(Object o) { throw new UnsupportedOperationException("Not supported yet."); } @Override public boolean containsAll(Collection c) { throw new UnsupportedOperationException("Not supported yet."); } @Override public boolean addAll(Collection c) { throw new UnsupportedOperationException("Not supported yet."); } @Override public boolean retainAll(Collection c) { throw new UnsupportedOperationException("Not supported yet."); } @Override public boolean removeAll(Collection c) { throw new UnsupportedOperationException("Not supported yet."); } @Override public void clear() { throw new UnsupportedOperationException("Not supported yet."); } }; } @Override public NavigableSet descendingKeySet() { return descendingMap().descendingKeySet(); } @Override public NavigableMap subMap(K fromKey, boolean fromInclusive, K toKey, boolean toInclusive) { return childNode(key).subMap(fromKey, fromInclusive, toKey, toInclusive); } @Override public NavigableMap headMap(K toKey, boolean inclusive) { throw new UnsupportedOperationException("Not supported yet."); } @Override public NavigableMap tailMap(K fromKey, boolean inclusive) { throw new UnsupportedOperationException("Not supported yet."); } @Override public NavigableMap subMap(K fromKey, K toKey) { return subMap(fromMap, true, toKey, false); } @Override public NavigableMap headMap(K toKey) { throw new UnsupportedOperationException("Not supported yet."); } @Override public NavigableMap tailMap(K fromKey) { return tailMap(fromKey, true); } @Override public Comparator comparator() { throw new UnsupportedOperationException("Not supported yet."); } @Override public K firstKey() { throw new UnsupportedOperationException("Not supported yet."); } @Override public K lastKey() { throw new UnsupportedOperationException("Not supported yet."); } @Override public Set keySet() { throw new UnsupportedOperationException("Not supported yet."); } @Override public Collection values() { throw new UnsupportedOperationException("Not supported yet."); } @Override public Set> entrySet() { throw new UnsupportedOperationException("Not supported yet."); } @Override public int size() { throw new UnsupportedOperationException("Not supported yet."); } @Override public boolean isEmpty() { throw new UnsupportedOperationException("Not supported yet."); } @Override public boolean containsKey(Object key) { throw new UnsupportedOperationException("Not supported yet."); } @Override public boolean containsValue(Object value) { throw new UnsupportedOperationException("Not supported yet."); } @Override public V get(Object o) { @SuppressWarnings("unchecked") K key = (K) o; if (comparator.compare(key, smallestKey()) < 0) return smallestChild().get(key); else if (comparator.compare(key, largestKey()) < 0) return largestChild().get(key); // 1) P(i) points to a subtree in which all keys values K are such that // K(i) <= K < K(i+1) // 2) Find i such that K(i) <= K < K(i+1) and drill down into P(i) int Ki = Collections.binarySearch(keys, key, comparator); int Pi; if (Ki >= 0) { // Exact match found Pi = Ki - 1; } else { // Ki points to -(index of K(i+1))-1 Pi = -Ki - 2; } return children.get(Pi).get(key); } @Override public V put(K key, V value) { throw new UnsupportedOperationException("Not supported yet."); } @Override public V remove(Object key) { throw new UnsupportedOperationException("Not supported yet."); } @Override public void putAll(Map m) { throw new UnsupportedOperationException("Not supported yet."); } @Override public void clear() { throw new UnsupportedOperationException("Not supported yet."); } } ----- Classpath: --------------------------------------------- bootPath: ClassPath[Entry[jar:file:/C:/Program%20Files%20(x86)/Java/jdk1.6.0_10/jre/lib/resources.jar!/], Entry[jar:file:/C:/Program%20Files%20(x86)/Java/jdk1.6.0_10/jre/lib/rt.jar!/], Entry[jar:file:/C:/Program%20Files%20(x86)/Java/jdk1.6.0_10/jre/lib/sunrsasign.jar!/], Entry[jar:file:/C:/Program%20Files%20(x86)/Java/jdk1.6.0_10/jre/lib/jsse.jar!/], Entry[jar:file:/C:/Program%20Files%20(x86)/Java/jdk1.6.0_10/jre/lib/jce.jar!/], Entry[jar:file:/C:/Program%20Files%20(x86)/Java/jdk1.6.0_10/jre/lib/charsets.jar!/], Entry[file:/C:/Program%20Files%20(x86)/Java/jdk1.6.0_10/jre/classes/], Entry[jar:file:/C:/Program%20Files%20(x86)/Java/jdk1.6.0_10/jre/lib/ext/dnsns.jar!/], Entry[jar:file:/C:/Program%20Files%20(x86)/Java/jdk1.6.0_10/jre/lib/ext/localedata.jar!/], Entry[jar:file:/C:/Program%20Files%20(x86)/Java/jdk1.6.0_10/jre/lib/ext/sunjce_provider.jar!/], Entry[jar:file:/C:/Program%20Files%20(x86)/Java/jdk1.6.0_10/jre/lib/ext/sunmscapi.jar!/], Entry[jar:file:/C:/Program%20Files%20(x86)/Java/jdk1.6.0_10/jre/lib/ext/sunpkcs11.jar!/]] classPath: ClassPath[] sourcePath: ClassPath[Entry[file:/C:/Users/Gili/Documents/blueeye/trunk/panacea/Core/source/], Entry[file:/C:/Users/Gili/Documents/blueeye/trunk/panacea/Core/netbeans6.1/build/generated/wsclient/], Entry[file:/C:/Users/Gili/Documents/blueeye/trunk/panacea/Core/netbeans6.1/build/generated/wsimport/client/]] ----- Original exception --------------------------------------------- java.lang.NullPointerException at com.sun.tools.javac.tree.TreeInfo$1DeclScanner.visitTypeParameter(TreeInfo.java:502) at com.sun.tools.javac.tree.JCTree$JCTypeParameter.accept(JCTree.java:1875) at com.sun.tools.javac.tree.TreeInfo$1DeclScanner.scan(TreeInfo.java:483) at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:58) at com.sun.tools.javac.tree.TreeScanner.visitMethodDef(TreeScanner.java:87) at com.sun.tools.javac.tree.TreeInfo$1DeclScanner.visitMethodDef(TreeInfo.java:495) at com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:658) at com.sun.tools.javac.tree.TreeInfo$1DeclScanner.scan(TreeInfo.java:483) at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:58) at com.sun.tools.javac.tree.TreeScanner.visitClassDef(TreeScanner.java:81) at com.sun.tools.javac.tree.TreeInfo$1DeclScanner.visitClassDef(TreeInfo.java:491) at com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:590) at com.sun.tools.javac.tree.TreeInfo$1DeclScanner.scan(TreeInfo.java:483) at com.sun.tools.javac.tree.TreeScanner.visitNewClass(TreeScanner.java:203) at com.sun.tools.javac.tree.JCTree$JCNewClass.accept(JCTree.java:1351) at com.sun.tools.javac.tree.TreeInfo$1DeclScanner.scan(TreeInfo.java:483) at com.sun.tools.javac.tree.TreeScanner.visitReturn(TreeScanner.java:182) at com.sun.tools.javac.tree.JCTree$JCReturn.accept(JCTree.java:1220) at com.sun.tools.javac.tree.TreeInfo$1DeclScanner.scan(TreeInfo.java:483) at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:58) at com.sun.tools.javac.tree.TreeScanner.visitBlock(TreeScanner.java:103) at com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:770) at com.sun.tools.javac.tree.TreeInfo$1DeclScanner.scan(TreeInfo.java:483) at com.sun.tools.javac.tree.TreeScanner.visitMethodDef(TreeScanner.java:90) at com.sun.tools.javac.tree.TreeInfo$1DeclScanner.visitMethodDef(TreeInfo.java:495) at com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:658) at com.sun.tools.javac.tree.TreeInfo$1DeclScanner.scan(TreeInfo.java:483) at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:58) at com.sun.tools.javac.tree.TreeScanner.visitClassDef(TreeScanner.java:81) at com.sun.tools.javac.tree.TreeInfo$1DeclScanner.visitClassDef(TreeInfo.java:491) at com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:590) at com.sun.tools.javac.tree.TreeInfo.declarationFor(TreeInfo.java:507) at com.sun.tools.javac.tree.TreeInfo.diagnosticPositionFor(TreeInfo.java:472) at com.sun.tools.javac.comp.Check.checkOverride(Check.java:1158) at com.sun.tools.javac.comp.Check.checkImplementations(Check.java:1596) at com.sun.tools.javac.comp.Check.checkImplementations(Check.java:1564) at com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:2763) at com.sun.tools.javac.comp.Attr.attribClass(Attr.java:2693) at com.sun.tools.javac.comp.Attr.attribClass(Attr.java:2627) at com.sun.tools.javac.main.JavaCompiler.attribute(JavaCompiler.java:1061) at com.sun.tools.javac.main.JavaCompiler.attribute(JavaCompiler.java:1037) at com.sun.tools.javac.api.JavacTaskImpl.analyze(JavacTaskImpl.java:437) at com.sun.tools.javac.api.JavacTaskImpl.analyze(JavacTaskImpl.java:417) at org.netbeans.api.java.source.JavaSource.moveToPhase(JavaSource.java:1223) at org.netbeans.api.java.source.JavaSource$CompilationJob.run(JavaSource.java:1539) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) at java.util.concurrent.FutureTask.run(FutureTask.java:138) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:619)