java plugin: Implement a reference counter for the JVMEnv pointers.
[collectd.git] / bindings / java / org / collectd / protocol / ValueList.java
1 /*
2  * jcollectd
3  * Copyright (C) 2009 Hyperic, Inc.
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
19 package org.collectd.protocol;
20
21 import java.util.ArrayList;
22 import java.util.List;
23
24 /**
25  * Java representation of collectd/src/plugin.h:value_list_t structure.
26  */
27 public class ValueList extends PluginData {
28
29     List<Number> _values = new ArrayList<Number>();
30     List<DataSource> _ds = new ArrayList<DataSource>();
31
32     long _interval;
33
34     public ValueList() {
35         
36     }
37
38     public ValueList(PluginData pd) {
39         super(pd);
40     }
41
42     public ValueList(ValueList vl) {
43         this((PluginData)vl);
44         _interval = vl._interval;
45         _values.addAll(vl.getValues());
46         _ds.addAll(vl._ds);
47     }
48
49     public List<Number> getValues() {
50         return _values;
51     }
52
53     public void setValues(List<Number> values) {
54         _values = values;
55     }
56
57     public void addValue(Number value) {
58         _values.add(value);
59     }
60
61     public List<DataSource> getDataSource() {
62         if (_ds.size() > 0) {
63             return _ds;
64         }
65         else {
66             TypesDB db = TypesDB.getInstance();
67             return db.getType(_type);
68         }
69     }
70
71     public void setDataSource(List<DataSource> ds) {
72         _ds = ds;
73     }
74
75     public long getInterval() {
76         return _interval;
77     }
78
79     public void setInterval(long interval) {
80         _interval = interval;
81     }
82
83     public String toString() {
84         StringBuffer sb = new StringBuffer(super.toString());
85         sb.append("=[");
86         List<DataSource> ds = getDataSource();
87         int size = _values.size();
88         for (int i=0; i<size; i++) {
89             Number val = _values.get(i);
90             String name;
91             if (ds == null) {
92                 name = "unknown" + i;
93             }
94             else {
95                 name = ds.get(i).getName();
96             }
97             sb.append(name).append('=').append(val);
98             if (i < size-1) {
99                 sb.append(',');
100             }
101         }
102         sb.append("]");
103         return sb.toString();
104     }
105 }