bindings/java: Moved the `PluginData' and `ValueList' classes.
[collectd.git] / bindings / java / org / collectd / api / DataSet.java
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  */
21
22 package org.collectd.api;
23
24 import java.util.List;
25 import java.util.ArrayList;
26
27 public class DataSet
28 {
29     private String _type;
30     private List<DataSource> _ds;
31
32     private DataSet ()
33     {
34         this._type = null;
35         this._ds = new ArrayList<DataSource> ();
36     }
37
38     public DataSet (String type)
39     {
40         this._type = type;
41         this._ds = new ArrayList<DataSource> ();
42     }
43
44     public DataSet (String type, DataSource dsrc)
45     {
46         this._type = type;
47         this._ds = new ArrayList<DataSource> ();
48         this._ds.add (dsrc);
49     }
50
51     public DataSet (String type, List<DataSource> ds)
52     {
53         this._type = type;
54         this._ds = ds;
55     }
56
57     public void setType (String type)
58     {
59         this._type = type;
60     }
61
62     public String getType ()
63     {
64         return (this._type);
65     }
66
67     public void addDataSource (DataSource dsrc)
68     {
69         this._ds.add (dsrc);
70     }
71
72     public List<DataSource> getDataSources ()
73     {
74         return (this._ds);
75     }
76
77     public String toString ()
78     {
79         StringBuffer sb = new StringBuffer ();
80         int i;
81
82         sb.append (this._type);
83         for (i = 0; i < this._ds.size (); i++)
84         {
85             if (i == 0)
86                 sb.append ("\t");
87             else
88                 sb.append (", ");
89             sb.append (this._ds.get (i).toString ());
90         }
91
92         return (sb.toString ());
93     }
94
95     static public DataSet parseDataSet (String str)
96     {
97         DataSet ds = new DataSet ();
98         String[] fields;
99         int i;
100
101         str = str.trim();
102         if (str.length() == 0) {
103             return (null);
104         }
105         if (str.charAt(0) == '#') {
106             return (null);
107         }
108
109         fields = str.split ("\\s+");
110         if (fields.length < 2)
111             return (null);
112
113         ds._type = fields[0];
114
115         for (i = 1; i < fields.length; i++) {
116             DataSource dsrc;
117
118             dsrc = DataSource.parseDataSource (fields[i]);
119             if (dsrc == null)
120                 break;
121
122             ds._ds.add (dsrc);
123         }
124
125         if (i < fields.length)
126             return (null);
127
128         return (ds);
129     } /* DataSet parseDataSet */
130 } /* class DataSet */
131
132 /* vim: set sw=4 sts=4 et : */