1 package org.opendaylight.nemo.tool.eclipse.plugin.rest.actions.model;
3 import org.json.JSONArray;
4 import org.json.JSONObject;
5 import org.opendaylight.nemo.tool.eclipse.plugin.rest.actions.UUIDUtils;
10 * Created by hj on 10/29/15.
12 public class Node implements INemoItem{
13 private String node_id;
14 private String node_name;
15 private String node_type;
16 private List<Property> properties;
17 private List<String> sub_nodes;
19 public Node(String node_id, String node_name, String node_type, List<Property> properties, List<String> sub_nodes) {
20 this.node_id = node_id;
21 this.node_name = node_name;
22 this.node_type = node_type;
23 this.properties = properties;
24 this.sub_nodes = sub_nodes;
28 public JSONObject toJSONObject() {
29 JSONObject jsonNode = new JSONObject();
30 jsonNode.put("node-id",node_id);
31 jsonNode.put("node-name",node_name);
33 jsonNode.put("node-type",node_type);
35 if(properties!=null&&properties.size()>0){
37 JSONArray jsonPropertyArray = new JSONArray();
38 for (int i=0;i<properties.size();i++){
39 JSONObject jsonProperty= properties.get(i).toJSONObject();
40 jsonPropertyArray.put(i,jsonProperty);
42 jsonNode.put("property",jsonPropertyArray);
45 if(sub_nodes!=null&&sub_nodes.size()>0){
47 JSONArray jsonSubNodeArray = new JSONArray();
48 for (int i=0;i<sub_nodes.size();i++){
49 String value = sub_nodes.get(i);
51 JSONObject jsonSubNode = new JSONObject();
52 jsonSubNode.put("order",i+"");
53 jsonSubNode.put("node-id",value);
54 jsonSubNodeArray.put(i,jsonSubNode);
56 jsonNode.put("sub-node",jsonSubNodeArray);
63 public boolean equals(Object o) {
64 if (this == o) return true;
65 if (o == null || getClass() != o.getClass()) return false;
69 if (node_id != null ? !node_id.equals(node.node_id) : node.node_id != null) return false;
75 public int hashCode() {
76 return node_id != null ? node_id.hashCode() : 0;
80 public String toString() {
82 "node_id='" + node_id + '\'' +
83 ", node_name='" + node_name + '\'' +
84 ", node_type='" + node_type + '\'' +
85 ", properties=" + properties +
86 ", sub_nodes=" + sub_nodes +