Click here to Skip to main content
13,046,464 members (71,890 online)
Click here to Skip to main content
Articles » Languages » Java » General » Downloads

Stats

24.3K views
9 bookmarked
Posted 12 Dec 2008

Building Tree Structure Domain Model

, 12 Dec 2008
How to build domain model with tree structure, thinking Object-Oriented
package org.schedulemanager.demo.view;

import java.util.List;

import org.schedulemanager.demo.model.Job;

public class CommandLineView {
	private Job job;

	public Job getJob() {
		return job;
	}

	public void setJob(Job job) {
		this.job = job;
	}
	
	public void printAllJobs() {
		printAllJobs(job, 0);
	}
	
	public void printAllJobs(Job job , int depth) {
		List<Job> jobList = job.getJobList();
		if(jobList!=null && jobList.size()>0){
			for(int i=0;i<jobList.size();i++){
				printDepth(depth);
				Job subJob = jobList.get(i);
				if(subJob.getType().equalsIgnoreCase(Job.BATCHJOB)){
					System.out.print("-");	
					System.out.println(subJob);					
				}else if(subJob.getType().equalsIgnoreCase(Job.JOBGROUP)){
					System.out.print("+");
					System.out.println(subJob);
					printAllJobs(subJob, depth + 1);
				}
				
			}//end for
		}
	}
	
	public void printDepth(int depth) {
		for(int i=0;i<depth;i++){
			System.out.print("\t");
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

RipleyKuo
Software Developer
Taiwan Taiwan
No Biography provided

You may also be interested in...

Pro
Pro
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170713.1 | Last Updated 12 Dec 2008
Article Copyright 2008 by RipleyKuo
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid