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 */
22 package org.collectd.api;
24 public class OConfigValue
25 {
26 public static final int OCONFIG_TYPE_STRING = 0;
27 public static final int OCONFIG_TYPE_NUMBER = 1;
28 public static final int OCONFIG_TYPE_BOOLEAN = 2;
30 private int _type;
31 private String _value_string;
32 private Number _value_number;
33 private boolean _value_boolean;
35 public OConfigValue (String s)
36 {
37 _type = OCONFIG_TYPE_STRING;
38 _value_string = s;
39 _value_number = null;
40 _value_boolean = false;
41 } /* OConfigValue (String s) */
43 public OConfigValue (Number n)
44 {
45 _type = OCONFIG_TYPE_NUMBER;
46 _value_string = null;
47 _value_number = n;
48 _value_boolean = false;
49 } /* OConfigValue (String s) */
51 public OConfigValue (boolean b)
52 {
53 _type = OCONFIG_TYPE_BOOLEAN;
54 _value_string = null;
55 _value_number = null;
56 _value_boolean = b;
57 } /* OConfigValue (String s) */
59 public int getType ()
60 {
61 return (_type);
62 } /* int getType */
64 public String getString ()
65 {
66 return (_value_string);
67 } /* String getString */
69 public Number getNumber ()
70 {
71 return (_value_number);
72 } /* String getString */
74 public boolean getBoolean ()
75 {
76 return (_value_boolean);
77 } /* String getString */
79 public String toString ()
80 {
81 if (_type == OCONFIG_TYPE_STRING)
82 return (_value_string);
83 else if (_type == OCONFIG_TYPE_NUMBER)
84 return (_value_number.toString ());
85 else if (_type == OCONFIG_TYPE_BOOLEAN)
86 return (Boolean.toString (_value_boolean));
87 return (null);
88 } /* String toString () */
89 } /* class OConfigValue */
91 /* vim: set sw=2 sts=2 et fdm=marker : */