In my Application i wrote a class which inserts data into JTable.
App have two Entities 1: Category 2: Product
For Category I have written this class . When i want to show data in JTable i call any method from this class according to situation.
public class InsertDataToTable {
public void insertCategoriesToTable(JTable tableObject,ArrayList<CategoryEntity> getCategories) {
DefaultTableModel model = (DefaultTableModel) categoryTable.getModel();
model.setRowCount(0);
for (CategoryEntity category : getCategories) {
int id = category.getId();
String categoryName = category.getCategoryName();
model.insertRow(categoryTable.getRowCount(), new Object[]{id, categoryName});
}
}
public void insertSingleCategory(JTable tableObject,CategoryEntity category){
DefaultTableModel model = (DefaultTableModel) categoryTable.getModel();
model.setRowCount(0);
int id=category.getId();
String categoryName=category.getCategoryName();
model.insertRow(categoryTable.getRowCount(), new Object[]{id, categoryName});
}
}
Now I want to make this class General so that I can pass either category object or product object and It Inserts data to table.
Confusion for me is in
public void insertCategoriesToTable(JTable tableObject,ArrayList<CategoryEntity> getCategories)
What should i pass instead of ArrayList so that i can call both methods for both Entities (Category and Product).
I don't want to write same class with little changes for Product Entity.