
src.org.neodatis.btree.tool.BTreeDisplay Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of neodatis-odb Show documentation
Show all versions of neodatis-odb Show documentation
The NeoDatis Object Database
/*
NeoDatis ODB : Native Object Database ([email protected])
Copyright (C) 2007 NeoDatis Inc. http://www.neodatis.org
"This file is part of the NeoDatis ODB open source object database".
NeoDatis ODB is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
NeoDatis ODB is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package org.neodatis.btree.tool;
import org.neodatis.btree.IBTree;
import org.neodatis.btree.IBTreeNode;
import org.neodatis.btree.IKeyAndValue;
/**
* an utility to display a btree
* @author osmadja
*
*/
public class BTreeDisplay {
private StringBuffer[] lines;
private StringBuffer result;
public BTreeDisplay() {
}
public StringBuffer build(IBTree btree, boolean withIds) {
lines = new StringBuffer[btree.getHeight()];
for (int i = 0; i < btree.getHeight(); i++) {
lines[i] = new StringBuffer();
}
buildDisplay(btree.getRoot(), 0,0,"0",withIds);
buildRepresentation();
return result;
}
public StringBuffer build(IBTreeNode node, int height,boolean withIds) {
lines = new StringBuffer[height];
for (int i = 0; i < height; i++) {
lines[i] = new StringBuffer();
}
buildDisplay(node, 0,0,"0",withIds);
buildRepresentation();
return result;
}
private void buildRepresentation() {
int maxLineSize = lines[lines.length-1].length();
result = new StringBuffer();
for(int i=0;ilines.length-1){
return;
}
// get string buffer of this line
StringBuffer line = lines[currentHeight];
if(withIds){
line.append(node.getId()).append(":[");
}else{
line.append("[");
}
for (int i = 0; i < node.getNbKeys(); i++) {
if (i > 0) {
line.append(" , ");
}
IKeyAndValue kav = node.getKeyAndValueAt(i);
line.append(kav.getKey());
}
if(withIds){
line.append("]:").append(node.getParentId()).append("/").append(parentId).append(" ");
}else{
line.append("] ");
}
for(int i=0;i
© 2015 - 2025 Weber Informatics LLC | Privacy Policy