1. TreeOriginalNode.java
package edu.xmu.tree; public class TreeOriginalNode { private String attr1; private String attr2; private String attr3; private int total; public String getAttr1() { return attr1; } public void setAttr1(String attr1) { this.attr1 = attr1; } public String getAttr2() { return attr2; } public void setAttr2(String attr2) { this.attr2 = attr2; } public String getAttr3() { return attr3; } public void setAttr3(String attr3) { this.attr3 = attr3; } public int getTotal() { return total; } public void setTotal(int total) { this.total = total; } @Override public String toString() { return "TreeOriginalNode [attr1=" + attr1 + ", attr2=" + attr2 + ", attr3=" + attr3 + ", total=" + total + "]"; } }
2. TreeNode.java
package edu.xmu.tree; import java.util.ArrayList; import java.util.List; public class TreeNode { private String attr1; private int total; private List<TreeNode> nodeList = new ArrayList<TreeNode>(); public TreeNode() { } public TreeNode(String attr1, int total) { this.attr1 = attr1; this.total = total; } public String getAttr1() { return attr1; } public void setAttr1(String attr1) { this.attr1 = attr1; } public void setTotal(int total) { this.total = total; } public int getTotal() { return this.total; } public List<TreeNode> getNodeList() { return nodeList; } public void setNodeList(List<TreeNode> nodeList) { this.nodeList = nodeList; } @Override public String toString() { return "TreeNode [attr1=" + attr1 + ", total=" + total + ", nodeList=" + nodeList + "]"; } }
3. TreeRoot.java
package edu.xmu.tree; import java.util.ArrayList; import java.util.Iterator; import java.util.List; public class TreeRoot { private List<TreeNode> levelOneList = new ArrayList<TreeNode>(); public void addNode(TreeOriginalNode node) { if (levelOneList.isEmpty()) { levelOneList.add(new TreeNode(node.getAttr1(), node.getTotal())); System.out.println(levelOneList.get(0)); } else { for (Iterator<TreeNode> levelOneIter = levelOneList.iterator(); levelOneIter .hasNext();) { TreeNode levelOneTempNode = levelOneIter.next(); if (levelOneTempNode.getAttr1().equals(node.getAttr1())) { int levelOneTotal = levelOneTempNode.getTotal(); levelOneTotal += node.getTotal(); levelOneTempNode.setTotal(levelOneTotal); List<TreeNode> levelTwoList = levelOneTempNode .getNodeList(); if (levelTwoList.isEmpty()) { System.out.println("Add node" + node + " to levelTwoList"); levelTwoList.add(new TreeNode(node.getAttr2(), node .getTotal())); System.out.println(levelTwoList.get(0)); } else { for (Iterator<TreeNode> levelTwoIter = levelTwoList .iterator(); levelTwoIter.hasNext();) { TreeNode levelTwoTempNode = levelTwoIter.next(); if (levelTwoTempNode.getAttr1().equals( node.getAttr2())) { int levelTwoTotal = levelTwoTempNode.getTotal(); levelTwoTotal += node.getTotal(); levelTwoTempNode.setTotal(levelTwoTotal); List<TreeNode> levelThreeList = levelTwoTempNode .getNodeList(); levelThreeList.add(new TreeNode( node.getAttr3(), node.getTotal())); } else { levelTwoList.add(new TreeNode(node.getAttr2(), node.getTotal())); break; } } } } else { levelOneList.add(new TreeNode(node.getAttr1(), node .getTotal())); break; } } } } public List<TreeNode> getNodeList() { return levelOneList; } public void setNodeList(List<TreeNode> nodeList) { this.levelOneList = nodeList; } @Override public String toString() { StringBuffer sb = new StringBuffer(); for (Iterator<TreeNode> iter = levelOneList.iterator(); iter.hasNext();) { TreeNode node = iter.next(); sb.append(node.toString()); sb.append("\n"); } return sb.toString(); } }
4. TreeRootTest.java
package edu.xmu.tree; import org.junit.Test; public class TreeRootTest { @Test public void test() { TreeRoot root = new TreeRoot(); TreeOriginalNode node1 = new TreeOriginalNode(); node1.setAttr1("aaa"); node1.setAttr2("AAA"); node1.setAttr3("111"); TreeOriginalNode node2 = new TreeOriginalNode(); node2.setAttr1("aaa"); node2.setAttr2("AAA"); node2.setAttr3("222"); TreeOriginalNode node3 = new TreeOriginalNode(); node3.setAttr1("aaa"); node3.setAttr2("BBB"); node3.setAttr3("111"); TreeOriginalNode node4 = new TreeOriginalNode(); node4.setAttr1("bbb"); node4.setAttr2("AAA"); node4.setAttr3("111"); root.addNode(node1); root.addNode(node2); root.addNode(node3); root.addNode(node4); System.out.println(root); } }
相关推荐
Dropout:A Simple Way to Prevent Neural Networks from Overfitting.zip
入门学习Java For Beginners: A Simple Start To Java Programming,JAVA入门学习好书,推荐
经典交通控制与规划文献,引用率极高,欢迎大家下载!
WATCH THE UNOBSERVED_ A SIMPLE APPROACH TO PARALLELIZING
jQuery插件之二:Simple Tree jQuery插件之二:Simple Tree jQuery插件之二:Simple Tree
A simple example of exchanging data across a network using the WinSock control(4KB)
Modern Java Recipes Simple Solutions to Difficult Problems in Java 8 and 9 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除
java源码:Java 命令行解析器 JOpt Simple.zip
A simple Matlab example of sensor fusion using a Kalman filter
perl 模块(spreadsheet、XML::Simple、DBB::mysql等模块) perl 模块(spreadsheet、XML::Simple、DBB::mysql等模块)
You Will Learn Python!
A simple example of JSON parser & composer, in java
Character Recognition Example (III):Training a Simple NN for classification
jQuery-simple-tree jQuery-simple-tree jQuery-simple-tree jQuery-simple-tree
A simple example with how hybrid beamforming is employed at the transmit end of a massive MIMO communications system.zip
automata models of BZ spirals can be created by using a very simple set of equations based on a three substrate model with close connection to reaction-diffusion models, more closely resembling the ...
SQL Server管理工具的簡單示例。 處理數據; 我相信Microsoft SQL Server是管理大量數據/信息的最佳選擇。 任何與數據庫相關的應用程序開發,所有開發人員都非常熟悉Microsoft SQL Server數據庫管理系統以及服務...
A Simple Framework for Contrastive Learning of Visual Representations 作者: Ting Chen, Simon Kornblith, Mohammad Norouzi, Geoffrey Hinton 本文提出一种简洁有效的设计的无监督设计,并且以7%的margin刷新...
1.代码中包括两种异步树加载,Default.aspx中使用json数据格式返回2.Default3使用兼容性很好的Jquery.simpletree树异步加载树,后台返回<ul><li> html标记.可以拖拽树.且插件包很小,只包括jquery.simple.tree.css,...
本书介绍使用java8和java9的一些技巧和方法,是英文版的azw3格式,手机端使用kindle打开,pc端使用calibre软件打开