[IoTivity Simulator] Handling resource interfaces.
[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 value 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 property type.
32      */
33     public enum Type {
34         UNKNOWN, RANGE, VALUESET
35     }
36
37     /**
38      * Constructs {@link AttributeProperty} of type
39      * {@link AttributeProperty.Type#RANGE} with min and max values.
40      *
41      * @param min
42      *            Minimum value the attribute can have.
43      * @param max
44      *            Maximum value the attribute can have.
45      */
46     public AttributeProperty(double min, double max) {
47         mType = Type.RANGE;
48         mMin = min;
49         mMax = max;
50     }
51
52     /**
53      * Constructs {@link AttributeProperty} of type
54      * {@link AttributeProperty.Type#VALUESET} with array of integer.
55      *
56      * @param values
57      *            Array of int type values.
58      */
59     public AttributeProperty(int[] values) {
60         mType = Type.VALUESET;
61         mValueSet = new AttributeValue[values.length];
62         for (int i = 0; i < values.length; i++)
63             mValueSet[i] = new AttributeValue(values[i]);
64     }
65
66     /**
67      * Constructs {@link AttributeProperty} of type
68      * {@link AttributeProperty.Type#VALUESET} with array of double.
69      *
70      * @param values
71      *            Array of double type values.
72      */
73     public AttributeProperty(double[] values) {
74         mType = Type.VALUESET;
75         mValueSet = new AttributeValue[values.length];
76         for (int i = 0; i < values.length; i++)
77             mValueSet[i] = new AttributeValue(values[i]);
78     }
79
80     /**
81      * Constructs {@link AttributeProperty} of type
82      * {@link AttributeProperty.Type#VALUESET} with array of boolean.
83      *
84      * @param values
85      *            Array of boolean type values.
86      */
87     public AttributeProperty(boolean[] values) {
88         mType = Type.VALUESET;
89         mValueSet = new AttributeValue[values.length];
90         for (int i = 0; i < values.length; i++)
91             mValueSet[i] = new AttributeValue(values[i]);
92     }
93
94     /**
95      * Constructs {@link AttributeProperty} of type
96      * {@link AttributeProperty.Type#VALUESET} with array of Strings.
97      *
98      * @param values
99      *            Array of string type values.
100      */
101     public AttributeProperty(String[] values) {
102         mType = Type.VALUESET;
103         mValueSet = new AttributeValue[values.length];
104         for (int i = 0; i < values.length; i++)
105             mValueSet[i] = new AttributeValue(values[i]);
106     }
107
108     /**
109      * API to get type of property.
110      *
111      * @return {@link AttributeProperty.Type}.
112      */
113     public Type type() {
114         return mType;
115     }
116
117     /**
118      * API to get minimum value which was set as property.
119      *
120      * @return Minimum value.
121      */
122     public double min() {
123         return mMin;
124     }
125
126     /**
127      * API to get maximum value which was set as property.
128      *
129      * @return Maximum value.
130      */
131     public double max() {
132         return mMax;
133     }
134
135     /**
136      * API to get array of values which was set as property.
137      *
138      * @return Array of {@link AttributeValue}.
139      */
140     public AttributeValue[] valueSet() {
141         return mValueSet;
142     }
143
144     /**
145      * API to set child attribute property.
146      *
147      * @param childProperty
148      *            Child element property used if the Attribute value is of array
149      *            type.
150      */
151     public void setChildProperty(AttributeProperty childProperty) {
152         mChildProperty = childProperty;
153     }
154
155     /**
156      * API to get child attribute property.
157      *
158      * @return Child element property.
159      */
160     public AttributeProperty getChildProperty() {
161         return mChildProperty;
162     }
163
164     private AttributeProperty(AttributeValue[] values) {
165         mType = Type.VALUESET;
166         mValueSet = values;
167     }
168 }