Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: What data type ie collection or logic to be used for data? An abstraction problem

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Thanked 0 Times in 0 Posts

    Default What data type ie collection or logic to be used for data? An abstraction problem


    I have a pivot and my pivotTableModel holds data in this fashion...
    eg I have a data containing task,Year and month field values

    The struture of my PivotTableModel. Below the data is being show in PivotTableModel rows...
    it has theses fields

    Task Year Month Values
    Issued check 7
    2010 4
    Feb 3
    Mar 1
    2011 3
    Dec 3

    Now I have to show this pivot table

    2011 2010 Total
    Task Feb Mar Dec
    Issued Checks 3 1 3 7


    2011 2010
    Feb Mar Dec
    Task 100 (including other tasks)
    Issued Checks 3 1 3 7
    and so on...

    How to go about it?

    I have a logic which tells me that user has asked for one (or more ) columns on the left and one or more columns on the top

    I am havng success to show and also sort values of the left ie values of the task. but the values on the top. If single set of values I am to show. no problem, it is sorting too. but when I have more than that on the top, the top header values stop sorting and also the values against them in the table are not getting put correctly.

    There can be more than one Feb 2011 occuring against tasks that I have not shown. So I need to merge all occurences and show as one Feb 2011 on the x-axis and show other tasks as occuring against it...

    Thank you

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    On vacation
    Thanked 2,243 Times in 2,215 Posts

    Default Re: What data type ie collection or logic to be used for data? An abstraction problem

    Do you have any specific java programming questions?

  3. #3
    Junior Member
    Join Date
    Feb 2012
    Thanked 0 Times in 0 Posts

    Default Re: What data type ie collection or logic to be used for data? An abstraction problem

    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();


    // 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)
    put = col;
    if(put>rowHeaderLenIndex&&ptm.getValueAt(row,col)! =null){

    System.out.println("Add new one at "+put+" for "+ptm.getColumnName(col));
    columnTopHeader = new LinkedList();
    //subElement = new Vector();
    //if(subElement != null)
    }else if(put>firstColumnHeaderIndex){

    // 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();

    }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));
    }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));

    valueStoredAt = col;
    System.out.println("last value Added at "+valueStoredAt);






    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

Similar Threads

  1. Data collection using mobile
    By Msaki in forum Java ME (Mobile Edition)
    Replies: 0
    Last Post: December 22nd, 2011, 04:18 AM
  2. [SOLVED] what data type should i use in MySql for a java object to be saved
    By chronoz13 in forum JDBC & Databases
    Replies: 4
    Last Post: October 9th, 2011, 07:17 AM
  3. Primitive data type
    By stuart harper in forum What's Wrong With My Code?
    Replies: 4
    Last Post: September 17th, 2011, 12:14 PM
  4. About heap data type
    By PaddyWangTheGG in forum Algorithms & Recursion
    Replies: 2
    Last Post: May 17th, 2010, 03:02 PM
  5. Selection Sorting of Data type (Char)
    By chronoz13 in forum Algorithms & Recursion
    Replies: 1
    Last Post: December 20th, 2009, 07:28 PM