Yes I have...
Here is example code...
import java.util.*;
class PivotTableModel{
private String []columns ={"name","Year","Month","Date","pivotValue","Total s"};;
private Class []columnClass ={String.class,Integer.class,Integer.class,Double. class,Double.class};;
private Object [][]rows = new Object[][]{
new Object[]{"CENTRAL BANK ORDER PROCESS",null,null,null,128.0},
new Object[]{null,2010,null,null,null,null},
new Object[]{null,null,12,null,2.0,null},
new Object[]{null,null,null,27,2.0,null},
new Object[]{null,null,null,28,2.0,null},
new Object[]{null,2011,null,null,null,null},
new Object[]{null,null,3,null,2.0,null},
new Object[]{null,null,4,null,15.0,null},
new Object[]{null,null,5,null,41.0,null},
new Object[]{null,null,null,27,2.0,null},
new Object[]{null,null,6,null,41.0,null},
new Object[]{null,null,8,null,27.0,null},
};
public PivotTableModel(){}
public int getColumnCount() {
return (columns != null) ? columns.length : 0;
}
public String getColumnName(int columnIndex) {
return (columns != null) ? columns[columnIndex] : null;
}
public int getRowCount() {
return (rows != null) ? rows.length : 0;
}
public Object getValueAt(int rowIndex, int columnIndex) {
return (rows != null) ? rows[rowIndex][columnIndex] : null;
}
public Class getColumnClass(int columnIndex) {
return columnClass[columnIndex];
}
public static void main(String []args){
PivotTableModel ptm = new PivotTableModel();
System.out.println(ptm.getValueAt(0,0));
System.out.println(ptm.getColumnCount());
System.out.println(ptm.getRowCount());
System.out.println(ptm.getColumnName(3));
System.out.println(ptm.getColumnClass(3));
// the number of table column that doesnot cocern us for this problem and its index number in the above table.
int rowHeaderLen =1;
int rowHeaderLenIndex =1-1;
// index of first column of interest
int firstColumnHeaderIndex=1;
// the number of columns that are to be included. Total 3 ie top column and 2 children level columns
int columnHeaderLen = 3;
// something to hold our collections
List data = new LinkedList();
List columnTopHeader;
int valueStoredAt=0;
Vector subElement = null;
for(int row = 0; row< ptm.getRowCount();row++){
int put=0;
for(int col = 0; col< ptm.getColumnCount();col++){
if(col>rowHeaderLenIndex&&col<rowHeaderLen+columnH eaderLen)
{
if(ptm.getValueAt(row,col)!=null){
put = col;
}
if(put>rowHeaderLenIndex&&ptm.getValueAt(row,col)! =null){
if(put==firstColumnHeaderIndex){
System.out.println("Add new one at "+put+" for "+ptm.getColumnName(col));
columnTopHeader = new LinkedList();
data.add(columnTopHeader);
//subElement = new Vector();
//if(subElement != null)
//columnTopHeader.add(subElement);
}else if(put>firstColumnHeaderIndex){
if(col>valueStoredAt){
// New vector should be created and put in the vector that is currently in focus
System.out.println("New vector pos at "+put+" for "+ptm.getColumnName(col));
//subElement = new Vector();
//subElement.add(ptm.getValueAt(row,col));
}else if(col==valueStoredAt){
// Add new element in the this level vector
System.out.println("Add New element pos at "+put+" for "+ptm.getColumnName(col));
//subElement.add(ptm.getValueAt(row,col));
}else if(col<valueStoredAt){
// Add new element in the previous level vector
System.out.println("Add New element pos at "+put+" for "+ptm.getColumnName(col));
//subElement.add(ptm.getValueAt(row,col));
}
}
valueStoredAt = col;
System.out.println("last value Added at "+valueStoredAt);
}
System.out.print(ptm.getValueAt(row,col)+"\t");
}
}
System.out.println();
}
}
}
But alas! Only the print statements correctly indicate what behaviour needs to followed; how to achieve that through code? Well, that beats me!
Do I need to have Hashtable/HashMap to hold Super level values and their subsequest child? How to go about it? What I need to code?
Please ignore Vector subElement or other code that may seem not correct. What the code tells is what is needed to be done at specific points in the program.
Thanks in advance