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 { public TableModel convertToTableModel(ResultSet rs) throws SQLException {
TableModel table = new TableModel(); TableModel table = new TableModel();
nbRow = getNbRowFromTable(prepareString); 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.Arrays;
import java.util.LinkedList;
import java.util.List; import java.util.List;
public class TableModel { public class TableModel {
private ColumnModel columns; private List<String> column;
private RowsModel rows; private RowsModel rows;
public TableModel() { public TableModel() {
this.columns = new ColumnModel(); this.column = new LinkedList<>();
this.rows = new RowsModel(); this.rows = new RowsModel();
} }
public TableModel(String... columns) { public TableModel(String... columns) {
this.columns = new ColumnModel(); this.column = new LinkedList<>();
this.rows = new RowsModel(); this.rows = new RowsModel();
this.columns.addAll(Arrays.asList(columns)); this.column.addAll(Arrays.asList(columns));
} }
public void addColumn(String name) { public TableModel addColumn(String name) {
columns.addColumn(name); column.add(name);
return this;
} }
public RowsModel addRow(RowModel row) { public TableModel addRow(RowModel row) {
rows.addRow(row); rows.addRow(row);
return rows; return this;
} }
public RowsModel getRows() { public RowsModel getRows() {
@@ -45,8 +47,8 @@ public class TableModel {
return rows.getRowModel(index).getRow(); return rows.getRowModel(index).getRow();
} }
public ColumnModel getColumns() { public List<String> getColumns() {
return columns; return column;
} }
public boolean isEmpty() { public boolean isEmpty() {
@@ -59,6 +61,6 @@ public class TableModel {
@Override @Override
public String toString() { public String toString() {
return "Columns: [" + columns + "], Rows: [" + rows + "]"; return "Column: [" + column + "], Rows: [" + rows + "]";
} }
} }