Modify pom file
[nemo.git] / nemo-tools / eclipse-plugin-project / nemo-rest / org.opendaylight.nemo.tool.eclipse.plugin.rest / src / org / opendaylight / nemo / tool / eclipse / plugin / rest / actions / model / Property.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 Property implements INemoItem {
12         private String propertyName;
13         private List<String> propertyValues;
14
15         public Property(String propertyName, List<String> propertyValues) {
16                 this.propertyName = propertyName;
17                 this.propertyValues = propertyValues;
18         }
19
20         @Override
21         public JSONObject toJSONObject() {
22                 if (propertyName == null || propertyValues == null) {
23                         throw new IllegalStateException("Illegal Property: " + toString());
24                 }
25                 JSONObject jsProperty = new JSONObject();
26                 jsProperty.put("property-name", propertyName);
27
28                 // JS array,property values
29                 JSONArray jsonValuesArray = new JSONArray();
30                 for (int i = 0; i < propertyValues.size(); i++) {
31                         String value = propertyValues.get(i);
32                         JSONObject jsonValue = new JSONObject();
33                         jsonValue.put("order", i + "");
34                         jsonValue.put("value", value);
35                         jsonValuesArray.put(i, jsonValue);
36                 }
37                 JSONObject pJs = new JSONObject();
38                 if (propertyName.equals("bandwidth"))
39                         pJs.put("int-value", jsonValuesArray);
40                 else
41                         pJs.put("string-value", jsonValuesArray);
42                 jsProperty.put("property-values", pJs);
43
44                 return jsProperty;
45         }
46
47         @Override
48         public boolean equals(Object o) {
49                 if (this == o)
50                         return true;
51                 if (o == null || getClass() != o.getClass())
52                         return false;
53
54                 Property property = (Property) o;
55
56                 if (propertyName != null ? !propertyName.equals(property.propertyName) : property.propertyName != null)
57                         return false;
58                 if (propertyValues != null ? !propertyValues.equals(property.propertyValues) : property.propertyValues != null)
59                         return false;
60
61                 return true;
62         }
63
64         @Override
65         public int hashCode() {
66                 int result = propertyName != null ? propertyName.hashCode() : 0;
67                 result = 31 * result + (propertyValues != null ? propertyValues.hashCode() : 0);
68                 return result;
69         }
70
71         @Override
72         public String toString() {
73                 return "Property{" + "propertyName='" + propertyName + '\'' + ", propertyValues=" + propertyValues + '}';
74         }
75 }