Updating Simulator Java API project with the following changes.
[platform/upstream/iotivity.git] / service / simulator / java / eclipse-plugin / ServiceProviderPlugin / src / oic / simulator / serviceprovider / resource / ResourceAttribute.java
1 package oic.simulator.serviceprovider.resource;
2
3 import java.util.ArrayList;
4 import java.util.HashSet;
5 import java.util.Iterator;
6 import java.util.List;
7 import java.util.Set;
8
9 import org.oic.simulator.AutomationType;
10 import org.oic.simulator.SimulatorResourceAttribute;
11
12 public class ResourceAttribute {
13
14     // Native object reference
15     private SimulatorResourceAttribute resourceAttribute;
16
17     private String                     attributeName;
18     private Object                     attributeValue;
19     private AttributeValueType         attributeType;
20     private List<Object>               allowedValues;
21
22     private Object                     minValue;
23     private Object                     maxValue;
24
25     private int                        automationId;
26
27     private boolean                    automationInProgress;
28
29     private int                        automationUpdateInterval;
30
31     private AutomationType             automationType;
32
33     public SimulatorResourceAttribute getResourceAttribute() {
34         return resourceAttribute;
35     }
36
37     public void setResourceAttribute(
38             SimulatorResourceAttribute resourceAttribute) {
39         this.resourceAttribute = resourceAttribute;
40     }
41
42     public String getAttributeName() {
43         return attributeName;
44     }
45
46     public void setAttributeName(String attributeName) {
47         this.attributeName = attributeName;
48     }
49
50     public Object getAttributeValue() {
51         return attributeValue;
52     }
53
54     public void setAttributeValue(Object attributeValue) {
55         this.attributeValue = attributeValue;
56     }
57
58     public AttributeValueType getAttributeType() {
59         return attributeType;
60     }
61
62     public void setAttributeType(AttributeValueType attributeType) {
63         this.attributeType = attributeType;
64     }
65
66     public List<Object> getAllowedValues() {
67         return allowedValues;
68     }
69
70     public void setAllowedValues(List<Object> allowedValues) {
71         this.allowedValues = allowedValues;
72     }
73
74     public void setAllowedValues(String[] allowedValues) {
75         List<Object> allowedValueList = null;
76         if (null != allowedValues && allowedValues.length > 0) {
77             allowedValueList = new ArrayList<Object>();
78             for (String value : allowedValues) {
79                 allowedValueList.add(value);
80             }
81         }
82         this.allowedValues = allowedValueList;
83     }
84
85     public Object getMinValue() {
86         return minValue;
87     }
88
89     public void setMinValue(Object minValue) {
90         this.minValue = minValue;
91     }
92
93     public Object getMaxValue() {
94         return maxValue;
95     }
96
97     public void setMaxValue(Object maxValue) {
98         this.maxValue = maxValue;
99     }
100
101     public boolean isAutomationInProgress() {
102         return automationInProgress;
103     }
104
105     public void setAutomationInProgress(boolean automationInProgress) {
106         this.automationInProgress = automationInProgress;
107     }
108
109     public int getAutomationUpdateInterval() {
110         return automationUpdateInterval;
111     }
112
113     public void setAutomationUpdateInterval(int automationUpdateInterval) {
114         this.automationUpdateInterval = automationUpdateInterval;
115     }
116
117     public AutomationType getAutomationType() {
118         return automationType;
119     }
120
121     public void setAutomationType(AutomationType automationType) {
122         this.automationType = automationType;
123     }
124
125     public int getAutomationId() {
126         return automationId;
127     }
128
129     public void setAutomationId(int automationId) {
130         this.automationId = automationId;
131     }
132
133     public static ResourceAttribute clone(ResourceAttribute attribute) {
134         ResourceAttribute clone = null;
135         if (null != attribute) {
136             clone = new ResourceAttribute();
137             clone.setAttributeName(attribute.getAttributeName());
138             clone.setAttributeValue(attribute.getAttributeValue());
139             clone.setAllowedValues(attribute.getAllowedValues());
140             clone.setAttributeType(attribute.getAttributeType());
141             clone.setMinValue(attribute.getMinValue());
142             clone.setMaxValue(attribute.getMaxValue());
143             clone.setAutomationInProgress(attribute.isAutomationInProgress());
144             clone.setAutomationType(attribute.getAutomationType());
145             clone.setAutomationUpdateInterval(attribute
146                     .getAutomationUpdateInterval());
147             clone.setResourceAttribute(null);
148         }
149         return clone;
150     }
151
152     // This method gives all known possible values of the attribute
153     // It takes allowed values or range of values whichever is available
154     public Set<Object> getValues() {
155         Set<Object> valueList = new HashSet<Object>();
156         if (null != allowedValues) {
157             Iterator<Object> values = allowedValues.iterator();
158             while (values.hasNext()) {
159                 valueList.add(values.next());
160             }
161         } else if (null != minValue && null != maxValue) {
162             if (attributeValue.getClass() == Integer.class) {
163                 int min = (Integer) minValue;
164                 int max = (Integer) maxValue;
165                 for (int value = min; value <= max; value++) {
166                     valueList.add(value);
167                 }
168             } else if (attributeValue.getClass() == Double.class) {
169                 double min = (Double) minValue;
170                 double max = (Double) maxValue;
171                 for (double value = min; value <= max; value++) {
172                     valueList.add(value);
173                 }
174             }
175         }
176         if (valueList.size() < 1) {
177             valueList.add(attributeValue);
178         }
179         return valueList;
180     }
181 }