HashSet

package com.test;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.thoughtworks.xstream.XStream;

public class XmlBean
{
	private List<JobClasss> list;
	public static void main(String[] args)
	{
		
		List<TreeBean> trees = new ArrayList<TreeBean>();
		setData(trees);
		for(TreeBean bean : trees)
		{
			System.out.println(bean.getClassId() + ", " + bean.getClassName()
					+ ", " + bean.getSclassId() + ", " + bean.getSclassName()
					+ ", "+bean.getStepId()+", "+bean.getStepName()
					+"," +bean.getActionId()+", "+bean.getActionName());
		}
		//System.out.println("set "+set.size());
		System.out.println("---------------------华丽分割线---------------------");
		
		
		Set<JobClasss> set = new HashSet<JobClasss>();//工作类型列表
		Set<JobSclass> sclassSet = new HashSet<JobSclass>();//
		Set<Step> stepSet = new HashSet<Step>();//
		//添加工作流类型
		for(TreeBean bean : trees)
		{
			JobClasss jobClass = new JobClasss();
			jobClass.setId(bean.getClassId());
			jobClass.setName(bean.getClassName());
			set.add(jobClass);
			
			JobSclass  jobSclass = new JobSclass();
			jobSclass.setId(bean.getSclassId());
			jobSclass.setName(bean.getSclassName());
			sclassSet.add(jobSclass);
			
			Step step = new Step();
			step.setId(bean.getStepId());
			step.setName(bean.getStepName());
			stepSet.add(step);
		}
		
		
		//添加工作流分类
	
		for (JobClasss jobClass : set) 
		{
			Set<JobSclass> tempSet = new HashSet<JobSclass>();
			for (TreeBean bean : trees)
			{
				if (bean.getClassId() == jobClass.getId()) 
				{
					JobSclass jobsclass = new JobSclass();
					jobsclass.setId(bean.getSclassId());
					jobsclass.setName(bean.getSclassName());
					tempSet.add(jobsclass);
				}
			}
			jobClass.setList(new ArrayList<JobSclass>(tempSet));
			
			for(JobSclass sclazz:tempSet)
			{
				
				Set<Step> stepsSet = new HashSet<Step>();
				for (TreeBean bean : trees)
				{
					if (bean.getSclassId() == sclazz.getId()) 
					{
						Step step = new Step();
						step.setId(bean.getStepId());
						step.setName(bean.getStepName());
						stepsSet.add(step);
						
					}
					sclazz.setList(new ArrayList<Step>(stepsSet));
				}
				
				for(Step step : stepsSet)
				{
					Set<Action> actionsSet = new HashSet<Action>();
					{
						for (TreeBean bean : trees)
						{
							if (bean.getStepId() ==step.getId()) 
							{
								Action action = new Action();
								action.setId(bean.getActionId());
								action.setName(bean.getActionName());
								actionsSet.add(action);
							}
							step.setList(new ArrayList<Action>(actionsSet));
						}
					}
				}
				
			}
		}
		
		
		//stepSet sclassSet
		XStream xstream = new XStream();
		xstream.alias("tree", JobSclass.class);
		String xml =xstream.toXML(set);
		System.out.println(xml);
	}
	
	public static void setData(List<TreeBean> trees)
	{
		
	
		
		
		...
		
		
		
		
		
		
		
		
	}
}
 

你可能感兴趣的:(hashset)