개발중/Java

재귀 도전 하다

Binsoo 2021. 4. 12. 17:21
728x90
반응형

하루종일 했는데 잊어버릴까봐 기록

package com.rsn.def.job;

import java.util.List;
import java.util.Map;
import java.util.ArrayList;
import java.util.HashMap;

public class MenuSession {

	
	
	// ALL DATA
	private static List<menuVo> ALL_LIST = null;

	// 최종 결과 저장
	private static List<menuVo> CODELIST = new ArrayList<>();

	// 임시 변수
	private static Map<Integer, List<menuVo>> MAP;
	private static List<menuVo> LIST;

	
	
	public MenuSession() {

		MenuFile file = new MenuFile();
		ALL_LIST = file.getJsonList();

		
		for ( menuVo vo : ALL_LIST ) {
			if (vo.getCode_type() == null && vo.getUi_type().equals("tree")) {

				System.out.println( "\n\n----------------------------------------------------------------------------------------------------------------------------------------");
				System.out.println( "--------[ 최상위 요소 ]---------------------------------------------------------------------------------------------------------------------");
				vo.toString();
				System.out.println( "-----------------------------------------------------------------------------------------------------------------------------------------");
				System.out.println( "-----------------------------------------------------------------------------------------------------------------------------------------\n\n");

				// 최상위 요소의 하위 요소를 찾아와.
				CODELIST.add(getChild(vo));
				System.out.println( "-----------최상위 END --------------------------------------------------------------------------------------------------------------------\n\n");
			}
		}
	}
	
	

	/*
	 * 하위 요소를 탐색
	 */
	private menuVo getChild(menuVo org_vo) {

		int code_p_seq = org_vo.getCode_seq();

		MAP = new HashMap<>();
		LIST = new ArrayList<>();

		System.out.println("_____자 식 요 소  START");

		for ( menuVo vo : ALL_LIST ) {
			if (vo.getCode_p_seq() == code_p_seq) {

				LIST.add(vo);
				vo.toString();

				if (vo.getUi_type().equals("tree")) {
					System.out.println("\n____" + vo.getCode_seq() + " 의 하위요소 START");
					getChild(vo);
					System.out.println("____하위요소 END\n");
				}
			}
		}
		
		System.out.println("_____자 식 요 소  END");
		MAP.put(code_p_seq, LIST);
		org_vo.setChild(MAP);

		return org_vo;
	}
 
	
	public List<menuVo> getCODELIST() {
		return CODELIST;
	}

}

 

728x90
반응형