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