1ebafff7a066d63942fb2db23405edc3d0fc76b7
[collectd.git] / bindings / java / org / collectd / api / OConfigValue.java
1 /*
2  * collectd/java - org/collectd/api/OConfigValue.java
3  * Copyright (C) 2009  Florian octo Forster
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the
7  * Free Software Foundation; only version 2 of the License is applicable.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
17  *
18  * Authors:
19  *   Florian octo Forster <octo at verplant.org>
20  */
21
22 package org.collectd.api;
23
24 /**
25  * Java representation of collectd/src/liboconfig/oconfig.h:oconfig_value_t structure.
26  *
27  * @author Florian Forster &lt;octo at verplant.org&gt;
28  */
29 public class OConfigValue
30 {
31   public static final int OCONFIG_TYPE_STRING  = 0;
32   public static final int OCONFIG_TYPE_NUMBER  = 1;
33   public static final int OCONFIG_TYPE_BOOLEAN = 2;
34
35   private int     _type;
36   private String  _value_string;
37   private Number  _value_number;
38   private boolean _value_boolean;
39
40   public OConfigValue (String s)
41   {
42     _type = OCONFIG_TYPE_STRING;
43     _value_string  = s;
44     _value_number  = null;
45     _value_boolean = false;
46   } /* OConfigValue (String s) */
47
48   public OConfigValue (Number n)
49   {
50     _type = OCONFIG_TYPE_NUMBER;
51     _value_string  = null;
52     _value_number  = n;
53     _value_boolean = false;
54   } /* OConfigValue (String s) */
55
56   public OConfigValue (boolean b)
57   {
58     _type = OCONFIG_TYPE_BOOLEAN;
59     _value_string  = null;
60     _value_number  = null;
61     _value_boolean = b;
62   } /* OConfigValue (String s) */
63
64   public int getType ()
65   {
66     return (_type);
67   } /* int getType */
68
69   public String getString ()
70   {
71     return (_value_string);
72   } /* String getString */
73
74   public Number getNumber ()
75   {
76     return (_value_number);
77   } /* String getString */
78
79   public boolean getBoolean ()
80   {
81     return (_value_boolean);
82   } /* String getString */
83
84   public String toString ()
85   {
86     if (_type == OCONFIG_TYPE_STRING)
87       return (_value_string);
88     else if (_type == OCONFIG_TYPE_NUMBER)
89       return (_value_number.toString ());
90     else if (_type == OCONFIG_TYPE_BOOLEAN)
91       return (Boolean.toString (_value_boolean));
92     return (null);
93   } /* String toString () */
94 } /* class OConfigValue */
95
96 /* vim: set sw=2 sts=2 et fdm=marker : */