1 /*
2 * collectd/java - org/collectd/api/OConfigItem.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 import java.util.List;
25 import java.util.ArrayList;
27 /**
28 * Java representation of collectd/src/plugin.h:data_set_t structure.
29 *
30 * @author Florian Forster <octo at verplant.org>
31 */
32 public class DataSet
33 {
34 private String _type;
35 private List<DataSource> _ds;
37 private DataSet ()
38 {
39 this._type = null;
40 this._ds = new ArrayList<DataSource> ();
41 }
43 public DataSet (String type)
44 {
45 this._type = type;
46 this._ds = new ArrayList<DataSource> ();
47 }
49 public DataSet (String type, DataSource dsrc)
50 {
51 this._type = type;
52 this._ds = new ArrayList<DataSource> ();
53 this._ds.add (dsrc);
54 }
56 public DataSet (String type, List<DataSource> ds)
57 {
58 this._type = type;
59 this._ds = ds;
60 }
62 public void setType (String type)
63 {
64 this._type = type;
65 }
67 public String getType ()
68 {
69 return (this._type);
70 }
72 public void addDataSource (DataSource dsrc)
73 {
74 this._ds.add (dsrc);
75 }
77 public List<DataSource> getDataSources ()
78 {
79 return (this._ds);
80 }
82 public String toString ()
83 {
84 StringBuffer sb = new StringBuffer ();
85 int i;
87 sb.append (this._type);
88 for (i = 0; i < this._ds.size (); i++)
89 {
90 if (i == 0)
91 sb.append ("\t");
92 else
93 sb.append (", ");
94 sb.append (this._ds.get (i).toString ());
95 }
97 return (sb.toString ());
98 }
100 static public DataSet parseDataSet (String str)
101 {
102 DataSet ds = new DataSet ();
103 String[] fields;
104 int i;
106 str = str.trim();
107 if (str.length() == 0) {
108 return (null);
109 }
110 if (str.charAt(0) == '#') {
111 return (null);
112 }
114 fields = str.split ("\\s+");
115 if (fields.length < 2)
116 return (null);
118 ds._type = fields[0];
120 for (i = 1; i < fields.length; i++) {
121 DataSource dsrc;
123 dsrc = DataSource.parseDataSource (fields[i]);
124 if (dsrc == null)
125 break;
127 ds._ds.add (dsrc);
128 }
130 if (i < fields.length)
131 return (null);
133 return (ds);
134 } /* DataSet parseDataSet */
135 } /* class DataSet */
137 /* vim: set sw=4 sts=4 et : */