Source Code Cross Referenced for BufferListDetailData.java in  » Profiler » JAMon » com » jamonapi » utils » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Profiler » JAMon » com.jamonapi.utils 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.jamonapi.utils;
002:
003:        /** This class builds the returned array data based on info from header and first row.
004:         * If header has more columns than data then each data is padded with nulls.  
005:         * If first rows data has more columns than header then the header is padded with headers named 'colN' where N is the column number.
006:         * If any rows of data have fewer columns than either the data in the first row or the header
007:         * they are shrunken or grown as neccesary filling any excess columns with nulls, and truncating any excess columns.
008:         * 
009:         * @author steve souza
010:         *
011:         */
012:        public class BufferListDetailData implements  DetailData {
013:
014:            private String[] header;
015:            private Object[][] data;
016:            private Object[] firstRow;
017:            private int colsInHeader;
018:            private int colsInFirstRow;
019:
020:            public BufferListDetailData(BufferList bufferList) {
021:                initalize(bufferList);
022:            }
023:
024:            public String[] getHeader() {
025:                return header;
026:            }
027:
028:            public Object[][] getData() {
029:                return data;
030:            }
031:
032:            public int getRowCount() {
033:                if (isEmpty())
034:                    return 0;
035:                else
036:                    return data.length;
037:
038:            }
039:
040:            public boolean hasData() {
041:                return !isEmpty();
042:            }
043:
044:            public boolean isEmpty() {
045:                return (data == null || data.length == 0);
046:            }
047:
048:            private void initalize(BufferList bufferList) {
049:
050:                /* object is value object.
051:                 * if header is bigger than data of first row then return header up to column width 
052:                 * if header is smaller than data then PAD HEADER with colN
053:                 * if first row is smaller than subsequent rows then use colsize of first row and exclude other cols
054:                 * if first row is bigger than subsequent rows then pad row iwth nulls 
055:                 */
056:
057:                Object[] rows = getAllRows(bufferList);
058:                if (rows != null) {
059:                    firstRow = getRow(rows[0]);
060:                    colsInFirstRow = firstRow.length;
061:                }
062:
063:                colsInHeader = (bufferList.getHeader() == null) ? 0
064:                        : bufferList.getHeader().length;
065:                header = buildHeader(bufferList.getHeader());
066:                data = buildData(rows);
067:            }
068:
069:            private Object[] getAllRows(BufferList bufferList) {
070:                Object[] bufferListArray = null;
071:                synchronized (bufferList) {
072:                    if (bufferList.getRowCount() > 0) {
073:                        bufferListArray = bufferList.getCollection().toArray();
074:                    }
075:                }
076:
077:                return bufferListArray;
078:            }
079:
080:            private String[] buildHeader(String[] h) {
081:                // if header is bigger than data of first row then return header up to column width 
082:                // if header is smaller than data then PAD HEADER with colN
083:
084:                Object[] head = resize(h, getColCount());
085:                if (head == null)
086:                    return null;
087:
088:                String[] headerStr = new String[head.length];
089:                for (int i = 0; i < head.length; i++) {
090:                    if (head[i] == null) {
091:                        headerStr[i] = "col" + i;
092:                    } else
093:                        headerStr[i] = head[i].toString();
094:                }
095:
096:                return headerStr;
097:
098:            }
099:
100:            private Object[][] buildData(Object[] rows) {
101:                if (rows == null)
102:                    return null;
103:
104:                Object[][] localData = new Object[rows.length][];
105:                int numCols = getColCount();
106:                for (int i = 0; i < rows.length; i++) {
107:                    localData[i] = resize(getRow(rows[i]), numCols);
108:                }
109:
110:                return localData;
111:            }
112:
113:            private Object[] resize(Object[] originalData, int size) {
114:                if (originalData == null)
115:                    return null;
116:                else if (size == originalData.length)
117:                    return originalData;
118:
119:                Object[] newData = new Object[size];
120:                // (shouldShrink) ? shrink : grow
121:                int loopSize = (originalData.length > size) ? size
122:                        : originalData.length;
123:
124:                for (int i = 0; i < loopSize; i++) {
125:                    newData[i] = originalData[i];
126:                }
127:
128:                return newData;
129:            }
130:
131:            private Object[] getRow(Object obj) {
132:                if (obj instanceof  Object[])
133:                    return (Object[]) obj;
134:                else if (obj instanceof  ToArray)
135:                    return ((ToArray) obj).toArray();
136:                else
137:                    return new Object[] { obj };
138:            }
139:
140:            private int getColCount() {
141:                return (colsInHeader > colsInFirstRow) ? colsInHeader
142:                        : colsInFirstRow;
143:            }
144:
145:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.