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.memory; 21 22 23 import java.util.ArrayList; 24 import java.util.List; 25 26 import org.apache.directory.mavibot.btree.Result; 27 28 29 /** 30 * An abstract class to gather common elements of the Result classes 31 * 32 * @param <K> The type for the Key 33 * @param <V> The type for the stored value 34 * 35 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 36 */ 37 /* No qualifier */abstract class AbstractResult<K, V> implements Result<Page<K, V>> 38 { 39 /** The list of copied page reference */ 40 private List<Page<K, V>> copiedPage; 41 42 43 /** 44 * The default constructor for AbstractResult. 45 * 46 */ 47 /* No qualifier */AbstractResult() 48 { 49 copiedPage = new ArrayList<Page<K, V>>(); 50 } 51 52 53 /** 54 * Creates an instance of AbstractResult with an initialized list of copied pages. 55 * 56 * @param copiedPages The list of copied pages to store in this result 57 */ 58 /* No qualifier */AbstractResult( List<Page<K, V>> copiedPages ) 59 { 60 this.copiedPage = copiedPages; 61 } 62 63 64 /** 65 * {@inheritDoc} 66 */ 67 public List<Page<K, V>> getCopiedPages() 68 { 69 return copiedPage; 70 } 71 72 73 /** 74 * {@inheritDoc} 75 */ 76 public void addCopiedPage( Page<K, V> page ) 77 { 78 copiedPage.add( page ); 79 } 80 81 82 public String toString() 83 { 84 StringBuilder sb = new StringBuilder(); 85 86 sb.append( "\n copiedPage = <" ); 87 88 boolean isFirst = true; 89 90 for ( Page<K, V> copiedPage : getCopiedPages() ) 91 { 92 if ( isFirst ) 93 { 94 isFirst = false; 95 } 96 else 97 { 98 sb.append( ", " ); 99 } 100 101 sb.append( copiedPage.getOffset() ); 102 } 103 104 sb.append( ">" ); 105 106 return sb.toString(); 107 } 108 }