-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBNode.java
More file actions
131 lines (120 loc) · 3.4 KB
/
BNode.java
File metadata and controls
131 lines (120 loc) · 3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/**
* This method instantiates the parameters for the nodes
* used in the 2-3+ tree, along with the Key/Value pairs
* used to identify the values in the nodes.
*
* @author karl88
* @author sfbahr
* @version Oct 18, 2014
*/
public abstract class BNode
{
private KVPair leftKVPair;
private KVPair rightKVPair;
private boolean isUnderflowed;
//This is used to keep all KVPairs up to date after a deletion
private KVPair minPair;
/**
* This is a singleton boolean which determines whether the
* node is a leaf or not.
*
* @return whether or not the node is a leaf
*/
public abstract boolean isLeaf();
/**
* This is a getter method for the left Key/Value pair of a node.
* @return leftKVPair the left Key/Value pair
*/
public KVPair getLeftKVPair()
{
return leftKVPair;
}
/**
* This is a setter method for the left Key/Value pair of a node.
*
* @param newLeftKVPair the new left Key/Value pair
*/
public void setLeftKVPair(KVPair newLeftKVPair)
{
leftKVPair = newLeftKVPair;
}
/**
* This is a getter method for the right Key/Value pair of a node.
* @return rightKVPair the left Key/Value pair
*/
public KVPair getRightKVPair()
{
return rightKVPair;
}
/**
* This method is a setter method for the right
* Key/Value pair of a node.
*
* @param newRightKVPair the new right Key/Value pair
*/
public void setRightKVPair(KVPair newRightKVPair)
{
rightKVPair = newRightKVPair;
}
/**
* This method returns the boolean identifier of whether or not a node
* has been underflowed.
*
* @return isUnderflowed the boolean state of underflow
*/
public boolean isUnderflowed()
{
return isUnderflowed;
}
/**
* This method is a setter for the boolean operation isUnderflowed.
* @param setIsUnderflowed sets the boolean operator
*/
public void setIsUnderflowed(boolean setIsUnderflowed)
{
isUnderflowed = setIsUnderflowed;
}
/**
* This method is a toString method that builds a string
* to better observe the change of the Key/Value pairs.
*
* @return the string representing the Key/Value pairs
*/
@Override
public String toString()
{
StringBuilder builder = new StringBuilder();
if (leftKVPair != null)
{
builder.append(leftKVPair.toString());
}
if (rightKVPair != null)
{
builder.append(" " + rightKVPair.toString());
}
return builder.toString();
}
/**
* This method is a getter for the minimum Key/Value pair, a
* comparison between two sets of pairs, helps determine how
* the nodes change locations within the tree after operations
* have been called on the tree.
*
* @return minPair the minimum pair of two Key/Value pairs
*/
public KVPair minPair()
{
return minPair;
}
/**
* This method is a setter method for the minimum Key/Value pair.
* Helps set the value of minPair to the correct value based on
* the Key/Value pairs of the surrounding nodes.
*
* @param newMinPair the new minPair value
*/
public void setMinPair(KVPair newMinPair)
{
minPair = newMinPair;
}
}