Optimized database table model

This commit is contained in:
Anthony committed 2018-02-14 22:15:08 -05:00
1 parent 02ee971db2
commit e45ecab762
3 files changed
+18 -45

No files matched your search

@@ -217,6 +217,11 @@ public class MysqlDatabase {
}
/**
* @param rs
* @return a {@link TableModel} with the appropriate column and rows
* @throws SQLException
*/
public TableModel convertToTableModel(ResultSet rs) throws SQLException {
TableModel table = new TableModel();
nbRow = getNbRowFromTable(prepareString);
@@ -1,34 +0,0 @@
package netneutrality.db.models;
/*
* Copyright (c) anthorob
*
* This file is closed-source. It should not be distributed or copied in any way or form
*/
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
public class ColumnModel {
private List<String> columns;
public ColumnModel() {
columns = new LinkedList<>();
}
public void addColumn(String name) {
columns.add(name);
}
public void addAll(Collection<String> columns) {
columns.addAll(columns);
}
@Override
public String toString() {
return Arrays.toString(columns.toArray());
}
}
@@ -8,33 +8,35 @@ package netneutrality.db.models;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
public class TableModel {
private ColumnModel columns;
private List<String> column;
private RowsModel rows;
public TableModel() {
this.columns = new ColumnModel();
this.column = new LinkedList<>();
this.rows = new RowsModel();
}
public TableModel(String... columns) {
this.columns = new ColumnModel();
this.column = new LinkedList<>();
this.rows = new RowsModel();
this.columns.addAll(Arrays.asList(columns));
this.column.addAll(Arrays.asList(columns));
}
public void addColumn(String name) {
columns.addColumn(name);
public TableModel addColumn(String name) {
column.add(name);
return this;
}
public RowsModel addRow(RowModel row) {
public TableModel addRow(RowModel row) {
rows.addRow(row);
return rows;
return this;
}
public RowsModel getRows() {
@@ -45,8 +47,8 @@ public class TableModel {
return rows.getRowModel(index).getRow();
}
public ColumnModel getColumns() {
return columns;
public List<String> getColumns() {
return column;
}
public boolean isEmpty() {
@@ -59,6 +61,6 @@ public class TableModel {
@Override
public String toString() {
return "Columns: [" + columns + "], Rows: [" + rows + "]";
return "Column: [" + column + "], Rows: [" + rows + "]";
}
}