Subversion Repositories Code-Repo

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
94 Kevin 1
 
2
// Internal node for the PRQuadTree
3
public class PRQuadTreeNodeInternal implements PRQuadTreeNode {
4
	// Node in each quadrant
5
	private PRQuadTreeNode NW;	
6
	private PRQuadTreeNode NE;
7
	private PRQuadTreeNode SW;
8
	private PRQuadTreeNode SE;
9
	private PRQuadTreeNodeFlyweight flyweight;	// Flyweight
10
 
11
	// Constructor to initialize the node with flyweights
12
	public PRQuadTreeNodeInternal(PRQuadTreeNodeFlyweight flyweight) {
13
		// Initialize all subnodes with the flyweight
14
		NW = NE = SW = SE = flyweight;
15
		this.flyweight = flyweight;
16
	}
17
 
18
	// Queries if all subnodes are flyweights
19
	public boolean isEmpty() {
20
		return (NW == flyweight)&&(NE == flyweight)&&
21
				(SW == flyweight)&&(SE == flyweight);
22
	}
23
 
24
	// Test if node contains other internal nodes
25
	public boolean containsAllLeavesOrFlyweight() {
26
		// Queries if all subnodes are either leaves or flyweights
27
		return (NW instanceof PRQuadTreeNodeLeaf || NW instanceof PRQuadTreeNodeFlyweight)&&
28
				(NE instanceof PRQuadTreeNodeLeaf || NE instanceof PRQuadTreeNodeFlyweight)&&
29
				(SW instanceof PRQuadTreeNodeLeaf || SW instanceof PRQuadTreeNodeFlyweight)&&
30
				(SE instanceof PRQuadTreeNodeLeaf || SE instanceof PRQuadTreeNodeFlyweight);
31
	}
32
 
33
	// Returns the number of all records in all subleaves
34
	public int countOfAllLeafNodes() {
35
		int ret = 0;
36
		if (NW instanceof PRQuadTreeNodeLeaf)
37
			ret += ((PRQuadTreeNodeLeaf) NW).getCount();
38
		if (NE instanceof PRQuadTreeNodeLeaf)
39
			ret += ((PRQuadTreeNodeLeaf) NE).getCount();
40
		if (SW instanceof PRQuadTreeNodeLeaf)
41
			ret += ((PRQuadTreeNodeLeaf) SW).getCount();
42
		if (SE instanceof PRQuadTreeNodeLeaf)
43
			ret += ((PRQuadTreeNodeLeaf) SE).getCount();
44
		return ret;
45
	}
46
 
47
	// Returns the number of records in a node if it is a leaf node
48
	public int countOfLeafNode(PRQuadTreeNode node) {
49
		if (node instanceof PRQuadTreeNodeLeaf)
50
			return ((PRQuadTreeNodeLeaf) node).getCount();
51
		else
52
			return 0;
53
	}
54
 
55
	// Encapsulation functions
56
	public PRQuadTreeNode getNW() {
57
		return NW;
58
	}
59
	public void setNW(PRQuadTreeNode nW) {
60
		NW = nW;
61
	}
62
	public PRQuadTreeNode getNE() {
63
		return NE;
64
	}
65
	public void setNE(PRQuadTreeNode nE) {
66
		NE = nE;
67
	}
68
	public PRQuadTreeNode getSW() {
69
		return SW;
70
	}
71
	public void setSW(PRQuadTreeNode sW) {
72
		SW = sW;
73
	}
74
	public PRQuadTreeNode getSE() {
75
		return SE;
76
	}
77
	public void setSE(PRQuadTreeNode sE) {
78
		SE = sE;
79
	}
80
}