View Javadoc
1   package net.sf.mbus4j.dataframes.datablocks;
2   
3   /*
4    * #%L
5    * mbus4j-core
6    * %%
7    * Copyright (C) 2009 - 2014 MBus4J
8    * %%
9    * mbus4j - Drivers for the M-Bus protocol - http://mbus4j.sourceforge.net/
10   * Copyright (C) 2009-2014, mbus4j.sf.net, and individual contributors as indicated
11   * by the @authors tag. See the copyright.txt in the distribution for a
12   * full listing of individual contributors.
13   * 
14   * This is free software; you can redistribute it and/or modify it
15   * under the terms of the GNU General Public License as
16   * published by the Free Software Foundation; either version 3 of
17   * the License, or (at your option) any later version.
18   * 
19   * This software is distributed in the hope that it will be useful,
20   * but WITHOUT ANY WARRANTY; without even the implied warranty of
21   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22   * Lesser General Public License for more details.
23   * 
24   * You should have received a copy of the GNU Lesser General Public
25   * License along with this software; if not, write to the Free
26   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
27   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
28   * #L%
29   */
30  import net.sf.json.JSONObject;
31  import net.sf.mbus4j.dataframes.datablocks.dif.DataFieldCode;
32  import net.sf.mbus4j.dataframes.datablocks.vif.Vif;
33  import net.sf.mbus4j.dataframes.datablocks.vif.Vife;
34  
35  /**
36   *
37   * @author arnep@users.sourceforge.net
38   * @version $Id: RealDataBlock.java 104 2014-02-21 09:31:17Z arnep $
39   */
40  public class RealDataBlock extends DataBlock {
41  
42      private float value;
43  
44      public RealDataBlock() {
45          super();
46      }
47  
48      @Deprecated
49      public RealDataBlock(DataFieldCode dataFieldCode, Vif vif, Vife... vifes) {
50          super(dataFieldCode, vif, vifes);
51      }
52  
53      /**
54       * @return the value
55       */
56      public float getValue() {
57          return value;
58      }
59  
60      @Override
61      public String getValueAsString() {
62          return Float.toString(value);
63      }
64  
65      /**
66       * @param value the value to set
67       */
68      public void setValue(float value) {
69          this.value = value;
70      }
71  
72      @Override
73      protected void accumulateDatatoJSON(JSONObject json) {
74          json.accumulate("data", getValue());
75      }
76  
77      @Override
78      public void fromJSON(JSONObject json) {
79          super.fromJSON(json);
80          setValue((float) json.getDouble("data"));
81      }
82  
83      @Override
84      public void setValue(String text) {
85          value = Float.parseFloat(text);
86      }
87  }