Modify pom file
[nemo.git] / nemo-tools / eclipse-plugin / nemo-rest / org.opendaylight.nemo.tool.eclipse.plugin.rest / src / org / opendaylight / nemo / tool / eclipse / plugin / rest / actions / model / Flow.java
1 package org.opendaylight.nemo.tool.eclipse.plugin.rest.actions.model;
2
3 import org.json.JSONArray;
4 import org.json.JSONObject;
5
6 import java.util.List;
7
8 /**
9  * Created by hj on 10/29/15.
10  */
11 public class Flow implements INemoItem {
12     private String flow_id;
13     private String flow_name;
14     private List<Match> matches;
15     public Flow(String flow_id, String flow_name, List<Match> matches) {
16         this.flow_id = flow_id;
17         this.flow_name = flow_name;
18         this.matches = matches;
19     }
20
21     @Override
22     public JSONObject toJSONObject() {
23         JSONObject flowJs = new JSONObject();
24         flowJs.put("flow-id", flow_id);
25         flowJs.put("flow-name", flow_name);
26
27         if (matches != null && matches.size() > 0) {
28             //Js array,matches
29             JSONArray jsonMatchArray = new JSONArray();
30             for (int i = 0; i < matches.size(); i++){
31                 Match match = matches.get(i);
32                 jsonMatchArray.put(i,match.toJSONObject());
33             }
34             flowJs.put("match-item",jsonMatchArray);
35         }
36         return flowJs;
37     }
38
39     @Override
40     public boolean equals(Object o) {
41         if (this == o) return true;
42         if (o == null || getClass() != o.getClass()) return false;
43
44         Flow flow = (Flow) o;
45
46         if (flow_id != null ? !flow_id.equals(flow.flow_id) : flow.flow_id != null) return false;
47
48         return true;
49     }
50
51     @Override
52     public int hashCode() {
53         return flow_id != null ? flow_id.hashCode() : 0;
54     }
55
56     @Override
57     public String toString() {
58         return "Flow{" +
59                 "flow_id='" + flow_id + '\'' +
60                 ", flow_name='" + flow_name + '\'' +
61                 ", matches=" + matches +
62                 '}';
63     }
64 }