1 package org.opendaylight.nemo.tool.eclipse.plugin.rest.actions.model;
3 import org.json.JSONArray;
4 import org.json.JSONObject;
9 * Created by hj on 10/29/15.
11 public class Property implements INemoItem {
12 private String propertyName;
13 private List<String> propertyValues;
15 public Property(String propertyName, List<String> propertyValues) {
16 this.propertyName = propertyName;
17 this.propertyValues = propertyValues;
21 public JSONObject toJSONObject() {
22 if (propertyName == null || propertyValues == null) {
23 throw new IllegalStateException("Illegal Property: " + toString());
25 JSONObject jsProperty = new JSONObject();
26 jsProperty.put("property-name", propertyName);
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);
37 JSONObject pJs = new JSONObject();
38 if (propertyName.equals("bandwidth"))
39 pJs.put("int-value", jsonValuesArray);
41 pJs.put("string-value", jsonValuesArray);
42 jsProperty.put("property-values", pJs);
48 public boolean equals(Object o) {
51 if (o == null || getClass() != o.getClass())
54 Property property = (Property) o;
56 if (propertyName != null ? !propertyName.equals(property.propertyName) : property.propertyName != null)
58 if (propertyValues != null ? !propertyValues.equals(property.propertyValues) : property.propertyValues != null)
65 public int hashCode() {
66 int result = propertyName != null ? propertyName.hashCode() : 0;
67 result = 31 * result + (propertyValues != null ? propertyValues.hashCode() : 0);
72 public String toString() {
73 return "Property{" + "propertyName='" + propertyName + '\'' + ", propertyValues=" + propertyValues + '}';