bd078f813199dae14d68928b13d8992030103dff
[public/netxms.git] / src / client / java / netxms-client / src / main / java / org / netxms / client / datacollection / DciDataRow.java
1 /**
2 * NetXMS - open source network management system
3 * Copyright (C) 2003-2010 Victor Kirhenshtein
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 package org.netxms.client.datacollection;
20
21 import java.util.Date;
22
23 /**
24 * Single row in DCI data
25 * @author Victor
26 *
27 */
28 public class DciDataRow
29 {
30 private Date timestamp;
31 private Object value;
32
33 public DciDataRow(Date timestamp, Object value)
34 {
35 super();
36 this.timestamp = timestamp;
37 this.value = value;
38 }
39
40 /**
41 * @return the timestamp
42 */
43 public Date getTimestamp()
44 {
45 return timestamp;
46 }
47
48 /**
49 * @return the value
50 */
51 public Object getValue()
52 {
53 return value;
54 }
55
56 /**
57 * @return the value
58 */
59 public String getValueAsString()
60 {
61 return value.toString();
62 }
63
64 /**
65 * @return the value
66 */
67 public long getValueAsLong()
68 {
69 if (value instanceof Long)
70 return ((Long)value).longValue();
71
72 if (value instanceof Double)
73 return ((Double)value).longValue();
74
75 return 0;
76 }
77
78 /**
79 * @return the value
80 */
81 public double getValueAsDouble()
82 {
83 if (value instanceof Long)
84 return ((Long)value).doubleValue();
85
86 if (value instanceof Double)
87 return ((Double)value).doubleValue();
88
89 return 0;
90 }
91
92 /**
93 * Invert value
94 */
95 public void invert()
96 {
97 if (value instanceof Long)
98 value = -((Long)value);
99 else if (value instanceof Double)
100 value = -((Double)value);
101 }
102
103 /* (non-Javadoc)
104 * @see java.lang.Object#toString()
105 */
106 @Override
107 public String toString()
108 {
109 return "DciDataRow [timestamp=" + timestamp + ", value=" + value + "]";
110 }
111 }