⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mbeantree.java

📁 具备多表组合查询组件功能。通过将表字段与表间关系映射到对象关系及属性
💻 JAVA
字号:
package cn.edu.buaa.ieguam.logmanage;

import java.util.ArrayList;
import java.util.List;

import cn.edu.buaa.ieguam.logmanage.ReadTreeMBean;
import cn.edu.buaa.ieguam.logmanage.MBean;


/**
 * 定义以MBean为节点的树状类,并实现对树的遍历算法
 * @author tongxiaodong
 * Creation time:Apr 23, 2007 9:25:48 PM
 */

public class MBeanTree {
	
	
	private MBean root = null;
	private ReadTreeMBean readDef = null;
	
	public MBeanTree()
	{
		
	}
	public MBeanTree(ReadTreeMBean readDef)
	{
		this.readDef = readDef;
	}

	public MBeanTree(MBean root,ReadTreeMBean readDef)
	{
		this.root = root;
		this.readDef = readDef;
	}
			
	/**
	 * Getting and setting methods
	 * @return
	 */
	public MBean getRoot()
	{
		return this.root;
	}
	public void setRoot(MBean root)
	{
		this.root = root;
	}
	public ReadTreeMBean getReadDef()
	{
		return this.readDef;
	}
	public void setReadDef(ReadTreeMBean readDef)
	{
		
		this.readDef = readDef;
		
	}
		
	
	/**
	 * 深度后序遍历该树的所有节点,可用于日志组合查询应用
	 * @throws Exception 
	 */
	public void deepPostOrderTraverse() 
	{
		MBean mBean = this.root;
		MBean father = null;
		MBean leftChild = null;
		MBean rightChild = null;
		String side = null;
		
		
		if(mBean == null)
		{
			return;
		}
		while(true)
		{
			
			if(mBean.hasNextLeft())//遍历左子树
			{
				
				leftChild = (MBean)mBean.getLeftChildList().get(mBean.nextLeft());
				mBean = leftChild;
				side = "left";
				continue;
			}
			
			if(mBean.hasNextRight())//遍历右子树
			{
				rightChild = (MBean)mBean.getRightChildList().get(mBean.nextRight());
				mBean = rightChild;
				side = "right";
				continue;
			}
			
			//读取该节点,并移动节点目标
			father = mBean.getFather();
			if(father == null)
			{
				//System.out.println("root : "+ mBean.getPojoName());			
				this.readDef.readMBean(null,mBean,null);
				break;//遍历结束
			}
			else
			{
				//System.out.println(mBean.getPojoName());
				this.readDef.readMBean(father,mBean,side);
				mBean = father;
			}
		}
	}
	
	/**
	 * 深度中序遍历该树的所有节点,可用于日志导入的应用
	 * @throws Exception 
	 */
	public void deepInOrderTraverse() 
	{
		MBean mBean = this.root;
		MBean father = null;
		MBean leftChild = null;
		MBean rightChild = null;
		String side = null;		
		List readList = new ArrayList();//将已经读取的节点进行记录
		
		if(mBean == null)
		{
			return;
		}
		while(true)
		{
			
			if(mBean.hasNextLeft())//遍历左子树
			{			
				leftChild = (MBean)mBean.getLeftChildList().get(mBean.nextLeft());
				mBean = leftChild;
				side = "left";			
				continue;
			}
			         		
			if(readList.contains(mBean.getPojoName()) == false)//判断此节点是否已阅读
			{
				System.out.println("post: "+mBean.getPojoName());
				this.readDef.readMBean(father,mBean,side);//读取节点
				readList.add(mBean.getPojoName());
			}
						
			if(mBean.hasNextRight())//遍历右子树
			{
				rightChild = (MBean)mBean.getRightChildList().get(mBean.nextRight());
				mBean = rightChild;
				side = "right";
				continue;
			}
			
            //移动节点目标
			father = mBean.getFather();
			if(father == null)
			{
				break;//遍历结束
			}
			else
			{
				mBean = father;
			}
		}
		
	}
	
	/**
	 * 深度先序遍历该树的所有节点
	 * @throws Exception 
	 */
	public void deepPreOrderTraverse() 
	{
		MBean mBean = this.root;
		MBean father = null;
		MBean leftChild = null;
		MBean rightChild = null;
		String side = null;
		
		List readList = new ArrayList();//将已经读取的节点进行记录
		
		if(mBean == null)
		{
			return;
		}
							
		while(true)
		{
			
			if(readList.contains (mBean.getPojoName()) == false)//判断此节点是否已阅读
			{
	            System.out.println(mBean.getPojoName());
				this.readDef.readMBean(father,mBean,side);//读取节点
				readList.add(mBean.getPojoName());
			}
			
			if(mBean.hasNextLeft())//遍历左子树
			{
				
				leftChild = (MBean)mBean.getLeftChildList().get(mBean.nextLeft());
				mBean = leftChild;
				side = "left";
				continue;
			}
			        		
			if(mBean.hasNextRight())//遍历右子树
			{
				rightChild = (MBean)mBean.getRightChildList().get(mBean.nextRight());
				mBean = rightChild;
				side = "right";
				continue;
			}	
			
            //移动节点目标
			father = mBean.getFather();
			if(father == null)
			{
							
				break;//遍历结束
			}
			else
			{
				mBean = father;
			}
		}
		
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -