1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 * 19 */ 20 package org.apache.directory.mavibot.btree; 21 22 23 import java.util.List; 24 25 26 /** 27 * The result of a delete operation, when the child has not been merged, and when 28 * we have borrowed an element from the left sibling. It contains the 29 * reference to the modified page, and the removed element. 30 * 31 * @param <K> The type for the Key 32 * @param <V> The type for the stored value 33 * 34 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 35 */ 36 /* No qualifier*/abstract class AbstractBorrowedFromSiblingResult<K, V> extends AbstractDeleteResult<K, V> implements 37 BorrowedFromSiblingResult<K, V> 38 { 39 /** The modified sibling reference */ 40 private Page<K, V> modifiedSibling; 41 42 /** Tells if the sibling is the left or right one */ 43 protected SiblingPosition position; 44 45 /** The two possible position for the sibling */ 46 protected enum SiblingPosition 47 { 48 LEFT, 49 RIGHT 50 } 51 52 53 /** 54 * The default constructor for RemoveResult. 55 * 56 * @param modifiedPage The modified page 57 * @param modifiedSibling The modified sibling 58 * @param removedElement The removed element (can be null if the key wasn't present in the tree) 59 */ 60 /* No qualifier*/AbstractBorrowedFromSiblingResult( Page<K, V> modifiedPage, Page<K, V> modifiedSibling, 61 Tuple<K, V> removedElement, SiblingPosition position ) 62 { 63 super( modifiedPage, removedElement ); 64 this.modifiedSibling = modifiedSibling; 65 this.position = position; 66 } 67 68 69 /** 70 * A constructor for RemoveResult with a list of copied pages. 71 * 72 * @param copiedPages the list of copied pages 73 * @param modifiedPage The modified page 74 * @param modifiedSibling The modified sibling 75 * @param removedElement The removed element (can be null if the key wasn't present in the tree) 76 */ 77 /* No qualifier*/AbstractBorrowedFromSiblingResult( List<Page<K, V>> copiedPages, Page<K, V> modifiedPage, 78 Page<K, V> modifiedSibling, 79 Tuple<K, V> removedElement, SiblingPosition position ) 80 { 81 super( copiedPages, modifiedPage, removedElement ); 82 this.modifiedSibling = modifiedSibling; 83 this.position = position; 84 } 85 86 87 /** 88 * {@inheritDoc} 89 */ 90 public Page<K, V> getModifiedSibling() 91 { 92 return modifiedSibling; 93 } 94 95 96 /** 97 * {@inheritDoc} 98 */ 99 public boolean isFromLeft() 100 { 101 return position == SiblingPosition.LEFT; 102 } 103 104 105 /** 106 * {@inheritDoc} 107 */ 108 public boolean isFromRight() 109 { 110 return position == SiblingPosition.RIGHT; 111 } 112 113 114 /** 115 * @see Object#toString() 116 */ 117 public String toString() 118 { 119 StringBuilder sb = new StringBuilder(); 120 121 sb.append( "\n removed element : " ).append( getRemovedElement() ); 122 sb.append( "\n modifiedPage : " ).append( getModifiedPage() ); 123 sb.append( "\n modifiedSibling : " ).append( getModifiedSibling() ); 124 125 return sb.toString(); 126 } 127 }