码迷,mamicode.com
首页 > 其他好文 > 详细

TOPO DN 解析

时间:2014-07-05 23:57:46      阅读:329      评论:0      收藏:0      [点我收藏+]

标签:blog   java   数据   2014   cti   html   

介绍

    有一个算法,是将大量TOPO DN实例解析成结构形式,并根据DN获取相应的数据。本人感觉值得分享,并供大家讨论与优化。


    注意:TOPO DN实例的顺序,是被我的其它算法预处理过的,所以会比较规整。


TOPO DN实例输入片断:

"SubNetwork=HW-345678,ManagedElement=XXXX-1500/CSCF-1505",
"SubNetwork=HW-345678,ManagedElement=XXXX-1500/CSCF-1505,InventoryUnitRack=RACK-1",
"SubNetwork=HW-345678,ManagedElement=XXXX-1500/CSCF-1505,InventoryUnitRack=RACK-1,InventoryUnitShelf=RACK-1/SHELF-3",
"SubNetwork=HW-345678,ManagedElement=XXXX-1500/CSCF-1505,InventoryUnitRack=RACK-1,InventoryUnitShelf=RACK-1/SHELF-3,InventoryUnitPack=RACK-1/SHELF-3/UNIT-5",
"SubNetwork=HW-345678,ManagedElement=XXXX-1011/CSCF-1011",
"SubNetwork=HW-345678,ManagedElement=XXXX-1011/CSCF-1011,IcscfFunction=CSCF-1011",
"SubNetwork=HW-345678,ManagedElement=XXXX-1011/CSCF-1011,IcscfFunction=CSCF-1011,EpRpDynDnsIcscf=DNSPH-1",
"SubNetwork=HW-345678,ManagedElement=XXXX-1011/CSCF-1011,IcscfFunction=CSCF-1011,EpRpDynCxIcscf=DIA-1",
"SubNetwork=HW-345678,ManagedElement=XXXX-1011/CSCF-1011,IcscfFunction=CSCF-1011,EpRpDynDxIcscf=EPRPDX-1006",
"SubNetwork=HW-345678,ManagedElement=XXXX-1011/CSCF-1011,ScscfFunction=CSCF-1011",
"SubNetwork=HW-345678,ManagedElement=XXXX-1011/CSCF-1011,ScscfFunction=CSCF-1011,EpRpDynCxScscf=DIA-1"


TOPO DN实例预期输出片断:

<ManagedElement id="XXXX-1500/CSCF-1505">
	<InventoryUnitRack id="RACK-1">
		<!-- 在完整的代码中,这些地方会根据DN写入数据 -->
		<InventoryUnitShelf id="RACK-1/SHELF-3">
			<InventoryUnitPack id="RACK-1/SHELF-3/UNIT-5">
				<!-- 在完整的代码中,这些地方会根据DN写入数据 -->
			</InventoryUnitPack>
		</InventoryUnitShelf>
	</InventoryUnitRack>
</ManagedElement>
<ManagedElement id="XXXX-1011/CSCF-1011">
	<IcscfFunction id="CSCF-1011">
		<EpRpDynDnsIcscf id="DNSPH-1">
			......
		</EpRpDynDnsIcscf>
		<EpRpDynCxIcscf id="DIA-1">
			......
		</EpRpDynCxIcscf>
		<EpRpDynDxIcscf id="EPRPDX-1006">
			......
		</EpRpDynDxIcscf>
	</IcscfFunction>
	<ScscfFunction id="CSCF-1011">
		<EpRpDynCxScscf id="DIA-1">
			......
		</EpRpDynCxScscf>
	</ScscfFunction>
</ManagedElement>

核心代码片断:

package shuai.study.dnProcess;

import org.apache.commons.lang3.StringUtils;

/**
 * @author shengshu
 * 
 */
public class DnProcess {
	public static void process(String[] dnPathArray) {
		int dnPathLength = dnPathArray.length;

		for (int i = 0; i < dnPathLength; i++) {
			String currentDnPath = dnPathArray[i];
			String[] currentDnPathArray = StringUtils.split(currentDnPath, ",");
			int currentDnPathLength = currentDnPathArray.length;

			System.out.println("<" + StringUtils.substringBefore(currentDnPathArray[currentDnPathLength - 1], "=") + " id=\""
					+ StringUtils.substringAfter(currentDnPathArray[currentDnPathLength - 1], "=") + "\">");

			if (i == dnPathLength - 1) {
				for (int k = currentDnPathLength - 1; k > 0; k--) {
					System.out.println("</" + StringUtils.substringBefore(currentDnPathArray[k], "=") + ">");
				}
			} else {
				String nextDnPath = dnPathArray[i + 1];
				String[] nextDnPathArray = StringUtils.split(nextDnPath, ",");
				int nextDnPathLength = nextDnPathArray.length;

				if (currentDnPathLength == nextDnPathLength) {
					System.out.println("</" + StringUtils.substringBefore(currentDnPathArray[currentDnPathLength - 1], "=") + ">");
				}

				if (currentDnPathLength > nextDnPathLength) {
					for (int j = currentDnPathLength - 1; j >= nextDnPathLength - 1; j--) {
						System.out.println("</" + StringUtils.substringBefore(currentDnPathArray[j], "=") + ">");
					}
				}
			}
		}
	}

	public static void main(String[] args) {
		String[] dnPathArray = new String[] { "SubNetwork=HW-345678,ManagedElement=XXXX-1500/CSCF-1505",
				"SubNetwork=HW-345678,ManagedElement=XXXX-1500/CSCF-1505,InventoryUnitRack=RACK-1",
				"SubNetwork=HW-345678,ManagedElement=XXXX-1500/CSCF-1505,InventoryUnitRack=RACK-1,InventoryUnitShelf=RACK-1/SHELF-3",
				"SubNetwork=HW-345678,ManagedElement=XXXX-1500/CSCF-1505,InventoryUnitRack=RACK-1,InventoryUnitShelf=RACK-1/SHELF-3,InventoryUnitPack=RACK-1/SHELF-3/UNIT-5",
				"SubNetwork=HW-345678,ManagedElement=XXXX-1011/CSCF-1011", "SubNetwork=HW-345678,ManagedElement=XXXX-1011/CSCF-1011,IcscfFunction=CSCF-1011",
				"SubNetwork=HW-345678,ManagedElement=XXXX-1011/CSCF-1011,IcscfFunction=CSCF-1011,EpRpDynDnsIcscf=DNSPH-1",
				"SubNetwork=HW-345678,ManagedElement=XXXX-1011/CSCF-1011,IcscfFunction=CSCF-1011,EpRpDynCxIcscf=DIA-1",
				"SubNetwork=HW-345678,ManagedElement=XXXX-1011/CSCF-1011,IcscfFunction=CSCF-1011,EpRpDynDxIcscf=EPRPDX-1006",
				"SubNetwork=HW-345678,ManagedElement=XXXX-1011/CSCF-1011,ScscfFunction=CSCF-1011",
				"SubNetwork=HW-345678,ManagedElement=XXXX-1011/CSCF-1011,ScscfFunction=CSCF-1011,EpRpDynCxScscf=DIA-1" };

		DnProcess.process(dnPathArray);
	}
}




TOPO DN 解析,布布扣,bubuko.com

TOPO DN 解析

标签:blog   java   数据   2014   cti   html   

原文地址:http://blog.csdn.net/three_man/article/details/36935199

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!