开发者

Most efficient way to manage a master table in a Java based parser

I'm working on a Swing based project that will display large amounts of data using a Table component. I'm trying to decide what are the best alternatives in terms of efficiency and management of the parsed data. The master table can be manipulated (i.e. views of the complete data can be created, or removed),so the complete data needs to be hold in memory

I know these kind of problems can have many different solutions. I thought of creating a class representing one entry on the log, with properties representing each 'property' on it. I can possible use Comparator objects to sort based on these fields, and use these objects to build a table component. This might no开发者_StackOverflow中文版t be a good idea if the total number of entries is in the order of 5000-10000 lines

Any suggestion on good practices to manage this kind of data and perform manipulations to it to render a graphic component are received.

Not many details have been provided, so I'm basically looking for general ideas on how to approach the problem.


I'm presuming that the files are all parsed and an in memory representation of parsed data is available when the table is displayed. You need to have your own tablemodel which gets data from the parsed files.

Something like below can be your table model:

class MyTableModel extends AbstractTableModel {
    private final List<String> columnNames;
    private List<RowData>      rows;

    MyTableModel() {
        columnNames = new ArrayList<String>();
        columnNames.add("Name");
        //...
        rows = new ArrayList<RowData>();
    }

    // populate the table data model with a List
    // that contains parsed data, each list element 
    // could correspond to a record or line (say)
    void setCoreData(final List<RowData> data) {
        this.rows = data;
    }

    public Object getValueAt(final int pRow, final int pCol) {
        if (getColumnName(pCol).equals("Name")) {
            return rows.get(pRow).getName();
        }
        //... .

    }

// corresponds to the rows of table instances of which 
// are created by output of parsing
private class RowData {
    private String name;

    public Object getName() {
        return name;
    }
}

// table instantitaion can be as below (say)
JTable myTable = new JTable(new MyTableModel());

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜