Debian Codegraph @

test/org/jfree/report/testcore/SimpleDataSet.java

raw
1 /**
2 * ========================================
3 * JFreeReport : a free Java report library
4 * ========================================
5 *
6 * Project Info: http://reporting.pentaho.org/
7 *
8 * (C) Copyright 2000-2007, by Object Refinery Limited, Pentaho Corporation and Contributors.
9 *
10 * This library is free software; you can redistribute it and/or modify it under the terms
11 * of the GNU Lesser General Public License as published by the Free Software Foundation;
12 * either version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 * See the GNU Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License along with this
19 * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20 * Boston, MA 02111-1307, USA.
21 *
22 * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
23 * in the United States and other countries.]
24 *
25 * ------------
26 * $Id: SimpleDataSet.java 10756 2009-12-02 15:58:24Z tmorgner $
27 * ------------
28 * (C) Copyright 2000-2005, by Object Refinery Limited.
29 * (C) Copyright 2005-2007, by Pentaho Corporation.
30 */
31
32 package org.jfree.report.testcore;
33
34 import java.util.ArrayList;
35
36 import org.jfree.report.DataSet;
37
38 /**
39 * Creation-Date: Jan 18, 2007, 6:09:26 PM
40 *
41 * @author Thomas Morgner
42 */
43 public class SimpleDataSet implements DataSet
44 {
45 private ArrayList names;
46 private ArrayList values;
47
48 public SimpleDataSet ()
49 {
50 names = new ArrayList();
51 values = new ArrayList();
52 }
53
54 /**
55 * Returns the column position of the column, expression or function with the given name
56 * or -1 if the given name does not exist in this DataRow.
57 *
58 * @param name the item name.
59 * @return the item index.
60 */
61 public int findColumn (String name)
62 {
63 return names.indexOf(name);
64 }
65
66 /**
67 * Returns the value of the expression or column in the tablemodel using the given
68 * column number as index. For functions and expressions, the <code>getValue()</code>
69 * method is called and for columns from the tablemodel the tablemodel method
70 * <code>getValueAt(row, column)</code> gets called.
71 *
72 * @param col the item index.
73 * @return the value.
74 *
75 * @throws IllegalStateException if the datarow detected a deadlock.
76 */
77 public Object get (int col)
78 {
79 return values.get(col);
80 }
81
82 /**
83 * Returns the value of the function, expression or column using its specific name. The
84 * given name is translated into a valid column number and the the column is queried.
85 * For functions and expressions, the <code>getValue()</code> method is called and for
86 * columns from the tablemodel the tablemodel method <code>getValueAt(row,
87 * column)</code> gets called.
88 *
89 * @param col the item index.
90 * @return the value.
91 *
92 * @throws IllegalStateException if the datarow detected a deadlock.
93 */
94 public Object get (String col)
95 throws IllegalStateException
96 {
97 // todo implement me
98 int index = names.indexOf(col);
99 if (index == -1)
100 {
101 return null;
102 }
103 return values.get(index);
104 }
105
106 /**
107 * Returns the number of columns, expressions and functions and marked ReportProperties
108 * in the report.
109 *
110 * @return the item count.
111 */
112 public int getColumnCount ()
113 {
114 return values.size();
115 }
116
117 /**
118 * Returns the name of the column, expression or function. For columns from the
119 * tablemodel, the tablemodels <code>getColumnName</code> method is called. For
120 * functions, expressions and report properties the assigned name is returned.
121 *
122 * @param col the item index.
123 * @return the name.
124 */
125 public String getColumnName (int col)
126 {
127 return (String) names.get(col);
128 }
129
130 public void add (String name, Object value)
131 {
132 names.add(name);
133 values.add(value);
134 }
135
136 }