Rev 96 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
// Internal node for the PRQuadTreepublic class PRQuadTreeNodeInternal implements PRQuadTreeNode {// Node in each quadrantprivate Handle NW;private Handle NE;private Handle SW;private Handle SE;private Handle flyweight;private NodeSerializer serializer;// Constructor to initialize the node with flyweightspublic PRQuadTreeNodeInternal(Handle flyweight, NodeSerializer mem) {serializer = mem;// Initialize all subnodes with the flyweightNW = NE = SW = SE = flyweight;this.flyweight = flyweight;}// Queries if all subnodes are flyweightspublic boolean isEmpty() {return (NW == flyweight)&&(NE == flyweight)&&(SW == flyweight)&&(SE == flyweight);}// Test if node contains other internal nodespublic boolean containsAllLeavesOrFlyweight() {// Queries if all subnodes are either leaves or flyweightsreturn (serializer.handleToNode(NW) instanceof PRQuadTreeNodeLeaf || serializer.handleToNode(NW) instanceof PRQuadTreeNodeFlyweight) &&(serializer.handleToNode(NE) instanceof PRQuadTreeNodeLeaf || serializer.handleToNode(NE) instanceof PRQuadTreeNodeFlyweight) &&(serializer.handleToNode(SW) instanceof PRQuadTreeNodeLeaf || serializer.handleToNode(SW) instanceof PRQuadTreeNodeFlyweight) &&(serializer.handleToNode(SE) instanceof PRQuadTreeNodeLeaf || serializer.handleToNode(SE) instanceof PRQuadTreeNodeFlyweight);}// Returns the number of all records in all subleavespublic int countOfAllLeafNodes() {int ret = 0;if (serializer.handleToNode(NW) instanceof PRQuadTreeNodeLeaf)ret += ((PRQuadTreeNodeLeaf) serializer.handleToNode(NW)).getCount();if (serializer.handleToNode(NE) instanceof PRQuadTreeNodeLeaf)ret += ((PRQuadTreeNodeLeaf) serializer.handleToNode(NE)).getCount();if (serializer.handleToNode(SW) instanceof PRQuadTreeNodeLeaf)ret += ((PRQuadTreeNodeLeaf) serializer.handleToNode(SW)).getCount();if (serializer.handleToNode(SE) instanceof PRQuadTreeNodeLeaf)ret += ((PRQuadTreeNodeLeaf) serializer.handleToNode(SE)).getCount();return ret;}// Returns the number of records in a node if it is a leaf nodepublic int countOfLeafNode(PRQuadTreeNode node) {if (node instanceof PRQuadTreeNodeLeaf)return ((PRQuadTreeNodeLeaf) node).getCount();elsereturn 0;}// Encapsulation functionspublic Handle getNW() {return NW;}public void setNW(Handle nW) {NW = nW;}public Handle getNE() {return NE;}public void setNE(Handle nE) {NE = nE;}public Handle getSW() {return SW;}public void setSW(Handle sW) {SW = sW;}public Handle getSE() {return SE;}public void setSE(Handle sE) {SE = sE;}}