result = 2;
} else {
final int leftLeafPageInParentIndex = leafPageInParentIndex - 1;
final long leftLeafPagePosition = leafPageParentNonTerminalPage
.getPagePointer(leftLeafPageInParentIndex);
final LeafPage leftLeafPage = (LeafPage) btreePlusElementMgr
.getPage(leftLeafPagePosition,
leafPageParentNonTerminalPage,
leftLeafPageInParentIndex);
result = leftLeafPage.tryBalanceOrMerge(leafPage);
if (result == 0) {
// leaf page merged in left leaf page
btreePlusElementMgr.freePage(leafPage.getPageRecord());
leafPageParentNonTerminalPage.remove(leafPageInParentIndex);
if (leafPageParentNonTerminalPage.setKey(
leftLeafPageInParentIndex, leftLeafPage.getLastKey())) {
if (!leafPageParentNonTerminalPage.wellFilled()) {
tryBalance(leafPageParentNonTerminalPage);
}
} else {
split(leafPageParentNonTerminalPage);
}
} else if (result == 1
&& !leafPageParentNonTerminalPage.setKey(
leftLeafPageInParentIndex,
leftLeafPage.getLastKey())) {
split(leafPageParentNonTerminalPage);
}
}
if (result == 2
&& leafPageInParentIndex != leafPageParentNonTerminalPage
.getNumberOfKeyEntries()) {
final int rightLeafPageinParentIndex = leafPageInParentIndex + 1;
final long rightLeafPagePosition = leafPageParentNonTerminalPage
.getPagePointer(rightLeafPageinParentIndex);
final LeafPage rightLeafPage = (LeafPage) btreePlusElementMgr
.getPage(rightLeafPagePosition,
leafPageParentNonTerminalPage,
rightLeafPageinParentIndex);
result = leafPage.tryBalanceOrMerge(rightLeafPage);
if (result == 0) {
// right leaf page merged in leaf page
btreePlusElementMgr.freePage(rightLeafPage.getPageRecord());
leafPageParentNonTerminalPage
.remove(rightLeafPageinParentIndex);
if (leafPageParentNonTerminalPage.setKey(leafPageInParentIndex,
leafPage.getLastKey())) {
if (!leafPageParentNonTerminalPage.wellFilled()) {