2 * collectd/java - org/collectd/api/OConfigValue.java
3 * Copyright (C) 2009 Florian octo Forster
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.
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.
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
19 * Florian octo Forster <octo at verplant.org>
22 package org.collectd.api;
25 * Java representation of collectd/src/liboconfig/oconfig.h:oconfig_value_t structure.
27 * @author Florian Forster <octo at verplant.org>
29 public class OConfigValue
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;
36 private String _value_string;
37 private Number _value_number;
38 private boolean _value_boolean;
40 public OConfigValue (String s)
42 _type = OCONFIG_TYPE_STRING;
45 _value_boolean = false;
46 } /* OConfigValue (String s) */
48 public OConfigValue (Number n)
50 _type = OCONFIG_TYPE_NUMBER;
53 _value_boolean = false;
54 } /* OConfigValue (String s) */
56 public OConfigValue (boolean b)
58 _type = OCONFIG_TYPE_BOOLEAN;
62 } /* OConfigValue (String s) */
69 public String getString ()
71 return (_value_string);
72 } /* String getString */
74 public Number getNumber ()
76 return (_value_number);
77 } /* String getString */
79 public boolean getBoolean ()
81 return (_value_boolean);
82 } /* String getString */
84 public String toString ()
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));
93 } /* String toString () */
94 } /* class OConfigValue */
96 /* vim: set sw=2 sts=2 et fdm=marker : */