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.managed; 21 22 23 import java.util.List; 24 25 import org.apache.directory.mavibot.btree.Tuple; 26 27 28 /** 29 * The result of a delete operation, when the child has not been merged, and when 30 * we have borrowed an element from the left sibling. It contains the 31 * reference to the modified page, and the removed element. 32 * 33 * @param <K> The type for the Key 34 * @param <V> The type for the stored value 35 * 36 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 37 */ 38 /* No qualifier */abstract class AbstractBorrowedFromSiblingResult<K, V> extends AbstractDeleteResult<K, V> implements 39 BorrowedFromSiblingResult<K, V> 40 { 41 /** The modified sibling reference */ 42 private Page<K, V> modifiedSibling; 43 44 /** Tells if the sibling is the left or right one */ 45 protected SiblingPosition position; 46 47 /** The two possible position for the sibling */ 48 protected enum SiblingPosition 49 { 50 LEFT, 51 RIGHT 52 } 53 54 55 /** 56 * The default constructor for RemoveResult. 57 * 58 * @param modifiedPage The modified page 59 * @param modifiedSibling The modified sibling 60 * @param removedElement The removed element (can be null if the key wasn't present in the tree) 61 */ 62 /* No qualifier */AbstractBorrowedFromSiblingResult( Page<K, V> modifiedPage, Page<K, V> modifiedSibling, 63 Tuple<K, V> removedElement, SiblingPosition position ) 64 { 65 super( modifiedPage, removedElement ); 66 this.modifiedSibling = modifiedSibling; 67 this.position = position; 68 } 69 70 71 /** 72 * A constructor for RemoveResult with a list of copied pages. 73 * 74 * @param copiedPages the list of copied pages 75 * @param modifiedPage The modified page 76 * @param modifiedSibling The modified sibling 77 * @param removedElement The removed element (can be null if the key wasn't present in the tree) 78 */ 79 /* No qualifier */AbstractBorrowedFromSiblingResult( List<Page<K, V>> copiedPages, Page<K, V> modifiedPage, 80 Page<K, V> modifiedSibling, 81 Tuple<K, V> removedElement, SiblingPosition position ) 82 { 83 super( copiedPages, modifiedPage, removedElement ); 84 this.modifiedSibling = modifiedSibling; 85 this.position = position; 86 } 87 88 89 /** 90 * {@inheritDoc} 91 */ 92 public Page<K, V> getModifiedSibling() 93 { 94 return modifiedSibling; 95 } 96 97 98 /** 99 * {@inheritDoc} 100 */ 101 public boolean isFromLeft() 102 { 103 return position == SiblingPosition.LEFT; 104 } 105 106 107 /** 108 * {@inheritDoc} 109 */ 110 public boolean isFromRight() 111 { 112 return position == SiblingPosition.RIGHT; 113 } 114 115 116 /** 117 * @see Object#toString() 118 */ 119 public String toString() 120 { 121 StringBuilder sb = new StringBuilder(); 122 123 sb.append( "\n removed element : " ).append( getRemovedElement() ); 124 sb.append( "\n modifiedPage : " ).append( getModifiedPage() ); 125 sb.append( "\n modifiedSibling : " ).append( getModifiedSibling() ); 126 127 return sb.toString(); 128 } 129 }