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.


>> REGISTER NOW TO START POSTING


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
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    Hi,


    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

    ie



    Total
    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
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 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
    Posts
    2
    Thanks
    0
    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();

    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

Similar Threads

  1. Data collection using mobile
    By Msaki in forum Java ME (Mobile Edition)
    Replies: 0
    Last Post: December 22nd, 2011, 05: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, 08:28 PM