Subversion Repositories Code-Repo

Rev

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

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