Debian Codegraph @

source/org/jfree/report/modules/misc/tablemodel/TableModelInfo.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: TableModelInfo.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.modules.misc.tablemodel;
33
34 import javax.swing.table.TableModel;
35
36 /**
37 * A utility class that prints out information about a TableModel.
38 *
39 * @author Thomas Morgner
40 */
41 public final class TableModelInfo
42 {
43 /**
44 * DefaultConstructor.
45 */
46 private TableModelInfo ()
47 {
48 }
49
50 /**
51 * Prints a table model to standard output.
52 *
53 * @param mod the model.
54 */
55 public static void printTableModel (final TableModel mod)
56 {
57 System.out.println("Tablemodel contains " + mod.getRowCount() + " rows.");
58 for (int i = 0; i < mod.getColumnCount(); i++)
59 {
60 System.out.println("Column: " + i + " Name = " + mod.getColumnName(i) + "; DataType = "
61 + mod.getColumnClass(i));
62 }
63
64 System.out.println("Checking the data inside");
65 for (int rows = 0; rows < mod.getRowCount(); rows++)
66 {
67 for (int i = 0; i < mod.getColumnCount(); i++)
68 {
69 final Object value = mod.getValueAt(rows, i);
70 final Class c = mod.getColumnClass(i);
71 if (value == null)
72 {
73 System.out.println("ValueAt (" + rows + ", " + i + ") is null");
74 }
75 else
76 {
77 if (c.isAssignableFrom(value.getClass()) == false)
78 {
79 System.out.println
80 ("ValueAt (" + rows + ", " + i + ") is not assignable from " + c);
81 }
82 if (c.equals(Object.class))
83 {
84 System.out.println
85 ("ValueAt (" + rows + ", " + i + ") is in a generic column and is of "
86 + "type " + value.getClass());
87 }
88 }
89 }
90 }
91 }
92
93 /**
94 * Prints a table model to standard output.
95 *
96 * @param mod the model.
97 */
98 public static void printTableModelContents (final TableModel mod)
99 {
100 System.out.println("Tablemodel contains " + mod.getRowCount() + " rows.");
101 for (int i = 0; i < mod.getColumnCount(); i++)
102 {
103 System.out.println("Column: " + i + " Name = " + mod.getColumnName(i) + "; DataType = "
104 + mod.getColumnClass(i));
105 }
106
107 System.out.println("Checking the data inside");
108 for (int rows = 0; rows < mod.getRowCount(); rows++)
109 {
110 for (int i = 0; i < mod.getColumnCount(); i++)
111 {
112 final Object value = mod.getValueAt(rows, i);
113 //final Class c = mod.getColumnClass(i);
114 System.out.println("ValueAt (" + rows + ", " + i + ") is " + value);
115 }
116 }
117 }
118 }