if( isRack() ) { // children are leaves
// range check
if(leaveIndex<0 || leaveIndex>=this.getNumOfChildren()) {
return null;
}
DatanodeDescriptor child =
(DatanodeDescriptor)children.get(leaveIndex);
if(excludedNode == null || excludedNode != child) {
// child is not the excludedNode
return child;
} else { // child is the excludedNode so return the next child
if(leaveIndex+1>=this.getNumOfChildren()) {
return null;
} else {
return (DatanodeDescriptor)children.get(leaveIndex+1);
}
}
} else {
for( int i=0; i<children.size(); i++ ) {
InnerNode child = (InnerNode)children.get(i);
if(excludedNode == null || excludedNode != child) {
// not the excludedNode
int numOfLeaves = child.getNumOfLeaves();
if( excludedNode != null && child.isAncestor(excludedNode) ) {
numOfLeaves -= numOfExcludedLeaves;
}
if( count+numOfLeaves > leaveIndex ) {
// the leaf is in the child subtree
return child.getLeaf(leaveIndex-count, excludedNode);
} else {
// go to the next child
count = count+numOfLeaves;
}
} else { // it is the excluededNode