Displaying and editing the complex value types for attributes.
[platform/upstream/iotivity.git] / service / simulator / java / sdk / src / org / oic / simulator / AttributeProperty.java
1 /*
2  * Copyright 2015 Samsung Electronics All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.oic.simulator;
18
19 /**
20  * This class represents the resource attribute's vaule property.
21  */
22 public class AttributeProperty {
23
24     private Type              mType          = Type.UNKNOWN;
25     private double            mMin           = -1;
26     private double            mMax           = -1;
27     private AttributeValue[]  mValueSet      = null;
28     private AttributeProperty mChildProperty = null;
29
30     /**
31      * Enum to represent propety type.
32      */
33     public enum Type {
34         UNKNOWN, RANGE, VALUESET
35     }
36
37     /**
38      * Constructs {@AttributeProperty} of type
39      * {@AttributeProperty.Type.Range} with min
40      * and max values.
41      *
42      * @param min
43      *            Minimun value the attribute can have.
44      * @param max
45      *            Maximum value the attribute can have.
46      */
47     public AttributeProperty(double min, double max) {
48         mType = Type.RANGE;
49         mMin = min;
50         mMax = max;
51     }
52
53     /**
54      * Constructs {@AttributeProperty} of type
55      * {@AttributeProperty.Type.VALUESET} with
56      * array of integer.
57      *
58      * @param values
59      *            Array of int type values.
60      */
61     public AttributeProperty(int[] values) {
62         mType = Type.VALUESET;
63         mValueSet = new AttributeValue[values.length];
64         for (int i = 0; i < values.length; i++)
65             mValueSet[i] = new AttributeValue(values[i]);
66     }
67
68     /**
69      * Constructs {@AttributeProperty} of type
70      * {@AttributeProperty.Type.VALUESET} with
71      * array of double.
72      *
73      * @param values
74      *            Array of double type values.
75      */
76     public AttributeProperty(double[] values) {
77         mType = Type.VALUESET;
78         mValueSet = new AttributeValue[values.length];
79         for (int i = 0; i < values.length; i++)
80             mValueSet[i] = new AttributeValue(values[i]);
81     }
82
83     /**
84      * Constructs {@AttributeProperty} of type
85      * {@AttributeProperty.Type.VALUESET} with
86      * array of boolean.
87      *
88      * @param values
89      *            Array of boolean type values.
90      */
91     public AttributeProperty(boolean[] values) {
92         mType = Type.VALUESET;
93         mValueSet = new AttributeValue[values.length];
94         for (int i = 0; i < values.length; i++)
95             mValueSet[i] = new AttributeValue(values[i]);
96     }
97
98     /**
99      * Constructs {@AttributeProperty} of type
100      * {@AttributeProperty.Type.VALUESET} with
101      * array of Strings.
102      *
103      * @param values
104      *            Array of strings.
105      */
106     public AttributeProperty(String[] values) {
107         mType = Type.VALUESET;
108         mValueSet = new AttributeValue[values.length];
109         for (int i = 0; i < values.length; i++)
110             mValueSet[i] = new AttributeValue(values[i]);
111     }
112
113     /**
114      * API to get type of property.
115      *
116      * @return {@AttributeProperty.Type}.
117      */
118     public Type type() {
119         return mType;
120     }
121
122     /**
123      * API to get minimum value which was set as property.
124      */
125     public double min() {
126         return mMin;
127     }
128
129     /**
130      * API to get maximum value which was set as property.
131      */
132     public double max() {
133         return mMax;
134     }
135
136     /**
137      * API to get array of values which was set as property.
138      *
139      * @return array of {@AttributeValue}.
140      */
141     public AttributeValue[] valueSet() {
142         return mValueSet;
143     }
144
145     /**
146      * API to set child attribute propety.
147      *
148      * @param childProperty
149      *            Child element property this property used if the Attribute
150      *            value is of array type.
151      */
152     public void setChildProperty(AttributeProperty childProperty) {
153         mChildProperty = childProperty;
154     }
155
156     /**
157      * API to get child attribute propety.
158      *
159      * @return Child element property.
160      */
161     public AttributeProperty getChildProperty() {
162         return mChildProperty;
163     }
164
165     private AttributeProperty(AttributeValue[] values) {
166         mType = Type.VALUESET;
167         mValueSet = values;
168     }
169 }