Imported Upstream version 1.0.0
[platform/upstream/iotivity.git] / android / examples / simpleclient / src / main / java / org / iotivity / base / examples / Light.java
1 /*
2  * //******************************************************************
3  * //
4  * // Copyright 2015 Intel Corporation.
5  * //
6  * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7  * //
8  * // Licensed under the Apache License, Version 2.0 (the "License");
9  * // you may not use this file except in compliance with the License.
10  * // You may obtain a copy of the License at
11  * //
12  * //      http://www.apache.org/licenses/LICENSE-2.0
13  * //
14  * // Unless required by applicable law or agreed to in writing, software
15  * // distributed under the License is distributed on an "AS IS" BASIS,
16  * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * // See the License for the specific language governing permissions and
18  * // limitations under the License.
19  * //
20  * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21  */
22 package org.iotivity.base.examples;
23
24 import org.iotivity.base.OcException;
25 import org.iotivity.base.OcRepresentation;
26
27 /**
28  * Light
29  * <p/>
30  * This class is used by SimpleClient to create an object representation of a remote light resource
31  * and update the values depending on the server response
32  */
33 public class Light {
34     public static final String NAME_KEY =  "name";
35     public static final String STATE_KEY = "state";
36     public static final String POWER_KEY = "power";
37
38     private String mName;
39     private boolean mState;
40     private int mPower;
41
42     public Light() {
43         mName = "";
44         mState = false;
45         mPower = 0;
46     }
47
48     public void setOcRepresentation(OcRepresentation rep) throws OcException {
49         mName = rep.getValue(NAME_KEY);
50         mState = rep.getValue(Light.STATE_KEY);
51         mPower = rep.getValue(Light.POWER_KEY);
52     }
53
54     public OcRepresentation getOcRepresentation() throws OcException {
55         OcRepresentation rep = new OcRepresentation();
56         rep.setValue(NAME_KEY, mName);
57         rep.setValue(STATE_KEY, mState);
58         rep.setValue(POWER_KEY, mPower);
59         return rep;
60     }
61
62     public String getName() {
63         return mName;
64     }
65
66     public void setName(String name) {
67         this.mName = mName;
68     }
69
70     public boolean getState() {
71         return mState;
72     }
73
74     public void setState(boolean state) {
75         this.mState = state;
76     }
77
78     public int getPower() {
79         return mPower;
80     }
81
82     public void setPower(int power) {
83         this.mPower = power;
84     }
85
86     @Override
87     public String toString() {
88         return "\t" + NAME_KEY + ": " + mName +
89                 "\n\t" + STATE_KEY + ": " + mState +
90                 "\n\t" + POWER_KEY + ": " + mPower;
91     }
92 }